Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions src/main/java/org/archive/io/RecordingOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import it.unimi.dsi.fastutil.io.FastBufferedOutputStream;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
Expand Down Expand Up @@ -89,12 +90,6 @@ public class RecordingOutputStream extends OutputStream {
/** flag to disable recording */
private boolean recording;

/**
* Reusable buffer for FastBufferedOutputStream
*/
protected byte[] bufStreamBuf =
new byte [ FastBufferedOutputStream.DEFAULT_BUFFER_SIZE ];

/**
* True if we're to digest content.
*/
Expand Down Expand Up @@ -206,15 +201,18 @@ public void open(OutputStream wrappedStream) throws IOException {
}
clearForReuse();
this.out = wrappedStream;
startTime = System.currentTimeMillis();
}

protected OutputStream ensureDiskStream() throws FileNotFoundException {
if (this.diskStream == null) {
// TODO: Fix so we only make file when its actually needed.
FileOutputStream fis = new FileOutputStream(this.backingFilename);

this.diskStream = new RecyclingFastBufferedOutputStream(fis, bufStreamBuf);
this.diskStream = new FastBufferedOutputStream(fis);
}
startTime = System.currentTimeMillis();
return this.diskStream;
}


public void write(int b) throws IOException {
if(position<maxPosition) {
// revisiting previous content; do nothing but advance position
Expand Down Expand Up @@ -319,10 +317,7 @@ private void record(int b) throws IOException {
this.digest.update((byte)b);
}
if (this.position >= this.buffer.length) {
// TODO: Its possible to call write w/o having first opened a
// stream. Protect ourselves against this.
assert this.diskStream != null: "Diskstream is null";
this.diskStream.write(b);
this.ensureDiskStream().write(b);
} else {
this.buffer[(int) this.position] = (byte) b;
}
Expand Down Expand Up @@ -357,12 +352,7 @@ private void record(byte[] b, int off, int len) throws IOException {
*/
private void tailRecord(byte[] b, int off, int len) throws IOException {
if(this.position >= this.buffer.length){
// TODO: Its possible to call write w/o having first opened a
// stream. Lets protect ourselves against this.
if (this.diskStream == null) {
throw new IOException("diskstream is null");
}
this.diskStream.write(b, off, len);
this.ensureDiskStream().write(b, off, len);
this.position += len;
} else {
assert this.buffer != null: "Buffer is null";
Expand Down

This file was deleted.

10 changes: 3 additions & 7 deletions src/main/java/org/archive/io/WriterPoolMember.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.archive.io;

import it.unimi.dsi.fastutil.io.FastBufferedOutputStream;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -80,9 +82,6 @@ public abstract class WriterPoolMember implements ArchiveFileConstants {
/** Counting stream for metering */
protected MiserOutputStream countOut = null;

/** reusable buffer for recycling scenarios */
protected byte[] rebuf;

protected WriterPoolSettings settings;
private final String extension;

Expand Down Expand Up @@ -209,10 +208,7 @@ protected String createFile(final File file) throws IOException {
close();
this.f = file;
FileOutputStream fos = new FileOutputStream(this.f);
if(rebuf==null) {
rebuf = new byte[settings.getWriteBufferSize()];
}
this.countOut = new MiserOutputStream(new RecyclingFastBufferedOutputStream(fos,rebuf),settings.getFrequentFlushes());
this.countOut = new MiserOutputStream(new FastBufferedOutputStream(fos),settings.getFrequentFlushes());
this.out = this.countOut;
logger.fine("Opened " + this.f.getAbsolutePath());
return this.f.getName();
Expand Down