Reset Recorder state when uri processing is finished (had been seeing cases where a url's entry in crawl.log would sometimes have nonzero size value if the url was erroring out and RecordingOutputStream.open() was never called)

This commit is contained in:
Noah Levitt
2013-08-12 19:28:28 -07:00
parent 68adaa70fd
commit a6958951df
3 changed files with 33 additions and 12 deletions
@@ -348,4 +348,8 @@ public class RecordingInputStream
public int getRecordedBufferLength() {
return recordingOutputStream.getBufferLength();
}
public void clearForReuse() throws IOException {
recordingOutputStream.clearForReuse();
}
}
@@ -181,19 +181,8 @@ public class RecordingOutputStream extends OutputStream {
throw new IOException("ROS already open for "
+Thread.currentThread().getName());
}
clearForReuse();
this.out = wrappedStream;
this.position = 0;
this.markPosition = 0;
this.maxPosition = 0;
this.size = 0;
this.messageBodyBeginMark = -1;
// ensure recording turned on
this.recording = true;
// Always begins false; must use startDigest() to begin
this.shouldDigest = false;
if (this.diskStream != null) {
closeDiskStream();
}
if (this.diskStream == null) {
// TODO: Fix so we only make file when its actually needed.
FileOutputStream fis = new FileOutputStream(this.backingFilename);
@@ -567,5 +556,21 @@ public class RecordingOutputStream extends OutputStream {
public long getRemainingLength() {
return maxLength - position;
}
public void clearForReuse() throws IOException {
this.out = null;
this.position = 0;
this.markPosition = 0;
this.maxPosition = 0;
this.size = 0;
this.messageBodyBeginMark = -1;
// ensure recording turned on
this.recording = true;
// Always begins false; must use startDigest() to begin
this.shouldDigest = false;
if (this.diskStream != null) {
closeDiskStream();
}
}
}
@@ -577,5 +577,17 @@ public class Recorder {
public void endReplays() {
ArchiveUtils.closeQuietly(replayCharSequence);
replayCharSequence = null;
// like closeQuietly
try {
ris.clearForReuse();
} catch (IOException ioe) {
}
// like closeQuietly
try {
ros.clearForReuse();
} catch (IOException e) {
}
}
}