龙将斩千 v5.5.5.39856版本的 MD5 值为:5c05b1d6f8d872ca3fe0343d6ff07caf
以下内容为反编译后的 SizeAndTimeBasedFNATP.java 源代码,内容仅作参考
package ch.qos.logback.core.rolling;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.joran.spi.NoAutoStart;
import ch.qos.logback.core.rolling.helper.ArchiveRemover;
import ch.qos.logback.core.rolling.helper.CompressionMode;
import ch.qos.logback.core.rolling.helper.DefaultFileProvider;
import ch.qos.logback.core.rolling.helper.FileFilterUtil;
import ch.qos.logback.core.rolling.helper.SizeAndTimeBasedArchiveRemover;
import ch.qos.logback.core.util.DefaultInvocationGate;
import ch.qos.logback.core.util.FileSize;
import ch.qos.logback.core.util.InvocationGate;
import java.io.File;
@NoAutoStart
public class SizeAndTimeBasedFNATP<E> extends TimeBasedFileNamingAndTriggeringPolicyBase<E> {
int currentPeriodsCounter;
InvocationGate invocationGate;
FileSize maxFileSize;
private final Usage usage;
static String MISSING_INT_TOKEN = "Missing integer token, that is %i, in FileNamePattern [";
static String MISSING_DATE_TOKEN = "Missing date token, that is %d, in FileNamePattern [";
enum Usage {
EMBEDDED,
DIRECT
}
public SizeAndTimeBasedFNATP() {
this(Usage.DIRECT);
}
public SizeAndTimeBasedFNATP(Usage usage) {
this.currentPeriodsCounter = 0;
this.invocationGate = new DefaultInvocationGate();
this.usage = usage;
}
private boolean validDateAndIntegerTokens() {
boolean z;
if (this.tbrp.fileNamePattern.getIntegerTokenConverter() == null) {
addError(MISSING_INT_TOKEN + this.tbrp.fileNamePatternStr + "]");
addError(CoreConstants.SEE_MISSING_INTEGER_TOKEN);
z = true;
} else {
z = false;
}
if (this.tbrp.fileNamePattern.getPrimaryDateTokenConverter() == null) {
addError(MISSING_DATE_TOKEN + this.tbrp.fileNamePatternStr + "]");
z = true;
}
return !z;
}
void computeCurrentPeriodsHighestCounterValue(String str) {
File[] filesInFolderMatchingStemRegex = FileFilterUtil.filesInFolderMatchingStemRegex(new File(getCurrentPeriodsFileNameWithoutCompressionSuffix()).getParentFile(), str);
if (filesInFolderMatchingStemRegex == null || filesInFolderMatchingStemRegex.length == 0) {
this.currentPeriodsCounter = 0;
return;
}
this.currentPeriodsCounter = FileFilterUtil.findHighestCounter(filesInFolderMatchingStemRegex, str);
if (this.tbrp.getParentsRawFileProperty() == null && this.tbrp.compressionMode == CompressionMode.NONE) {
return;
}
this.currentPeriodsCounter++;
}
protected ArchiveRemover createArchiveRemover() {
return new SizeAndTimeBasedArchiveRemover(this.tbrp.fileNamePattern, this.rc, new DefaultFileProvider());
}
@Override
public String getCurrentPeriodsFileNameWithoutCompressionSuffix() {
return this.tbrp.fileNamePatternWithoutCompSuffix.convertMultipleArguments(this.dateInCurrentPeriod, Integer.valueOf(this.currentPeriodsCounter));
}
@Override
public boolean isTriggeringEvent(File file, E e) {
String str;
long currentTime = getCurrentTime();
if (currentTime >= this.nextCheck) {
this.elapsedPeriodsFileName = this.tbrp.fileNamePatternWithoutCompSuffix.convertMultipleArguments(this.dateInCurrentPeriod, Integer.valueOf(this.currentPeriodsCounter));
this.currentPeriodsCounter = 0;
setDateInCurrentPeriod(currentTime);
computeNextCheck();
return true;
}
if (this.invocationGate.isTooSoon(currentTime)) {
return false;
}
if (file == null) {
str = "activeFile == null";
} else {
if (this.maxFileSize != null) {
if (file.length() < this.maxFileSize.getSize()) {
return false;
}
this.elapsedPeriodsFileName = this.tbrp.fileNamePatternWithoutCompSuffix.convertMultipleArguments(this.dateInCurrentPeriod, Integer.valueOf(this.currentPeriodsCounter));
this.currentPeriodsCounter++;
return true;
}
str = "maxFileSize = null";
}
addWarn(str);
return false;
}
public void setMaxFileSize(FileSize fileSize) {
this.maxFileSize = fileSize;
}
@Override
public void start() {
super.start();
if (this.usage == Usage.DIRECT) {
addWarn(CoreConstants.SIZE_AND_TIME_BASED_FNATP_IS_DEPRECATED);
addWarn("For more information see http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedRollingPolicy");
}
if (super.isErrorFree()) {
if (this.maxFileSize == null) {
addError("maxFileSize property is mandatory.");
withErrors();
}
if (!validDateAndIntegerTokens()) {
withErrors();
return;
}
this.archiveRemover = createArchiveRemover();
this.archiveRemover.setContext(this.context);
computeCurrentPeriodsHighestCounterValue(FileFilterUtil.afterLastSlash(this.tbrp.fileNamePattern.toRegexForFixedDate(this.dateInCurrentPeriod)));
if (isErrorFree()) {
this.started = true;
}
}
}
}