avoid constructor ex

This commit is contained in:
Mengyi Zhou 2015-12-07 16:53:49 +08:00
parent edf7650359
commit 65c47c04bf
2 changed files with 17 additions and 18 deletions

View file

@ -26,7 +26,7 @@ public class AccessLogStatsAnalyzer implements LogStatsAnalyzer {
private final LogTracker logTracker;
private final LogParser logParser;
public AccessLogStatsAnalyzer() throws IOException {
public AccessLogStatsAnalyzer() {
this(new LogStatsAnalyzerConfigBuilder()
.setLogFormat(new AccessLogLineFormat(AccessLogFormat).generate())
.setLogFilename("/opt/logs/nginx/access.log")
@ -84,7 +84,7 @@ public class AccessLogStatsAnalyzer implements LogStatsAnalyzer {
private boolean allowTracking;
private int trackerReadSize;
public LogStatsAnalyzerConfigBuilder setLogFilename(String logFilename) throws IOException {
public LogStatsAnalyzerConfigBuilder setLogFilename(String logFilename) {
this.logFilename = logFilename;
return this;
}
@ -105,9 +105,8 @@ public class AccessLogStatsAnalyzer implements LogStatsAnalyzer {
return this;
}
public LogStatsAnalyzerConfig build() throws IOException {
public LogStatsAnalyzerConfig build() {
File f = new File(logFilename);
if (f.exists() && f.isFile()) {
String rootDir = f.getAbsoluteFile().getParentFile().getAbsolutePath();
LogTrackerStrategy strategy = new LogTrackerStrategy()
.setAllowLogRotate(true)
@ -119,9 +118,6 @@ public class AccessLogStatsAnalyzer implements LogStatsAnalyzer {
return new LogStatsAnalyzerConfig()
.addFormat(logFormat)
.setLogTracker(new AccessLogTracker(strategy));
} else {
throw new IOException(logFilename + " is not a file or does not exist.");
}
}
}
}

View file

@ -69,6 +69,9 @@ public class AccessLogTracker implements LogTracker {
@Override
public void start() throws IOException {
if (!new File(getLogFilename()).exists()) {
throw new IOException(logFilename + " is not a file or does not exist.");
}
raf = new RandomAccessFile(getLogFilename(), "r");
fileChannel = raf.getChannel();
if (allowTracking) {