Skip to content

Commit

Permalink
#87 more on streams
Browse files Browse the repository at this point in the history
  • Loading branch information
mconway committed Jun 2, 2015
1 parent 0924ace commit 392a69e
Show file tree
Hide file tree
Showing 2 changed files with 225 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
* an optimal buffer size before sending to iRODS
*
* @author Mike Conway - DICE
*
*
*/
public class PackingIrodsOutputStream extends OutputStream {

public final int BUFFER_SIZE = 4 * 1024 * 1024; // FIXME: make this a jargon
// props later
private int byteBufferSizeMax = 32 * 1024;
private int ptr = 0;
private final int byteBufferSizeMax = 32 * 1024;
private final int ptr = 0;
private ByteArrayOutputStream byteArrayOutputStream = null;
private final IRODSFileOutputStream irodsFileOutputStream;

Expand Down Expand Up @@ -65,12 +65,19 @@ public void write(byte[] b, int off, int len) throws IOException {
int lenToHoldOver = projectedLen - byteBufferSizeMax;
int lenToAddToBuff = len - lenToHoldOver;
byteArrayOutputStream.write(b, off, lenToAddToBuff);
irodsFileOutputStream
flushAndResetBufferStream();
}

super.write(b, off, len);
}

private void flushAndResetBufferStream() throws IOException {
irodsFileOutputStream.write(byteArrayOutputStream.toByteArray());
byteArrayOutputStream.reset();
ptr = 0;

}

/*
* (non-Javadoc)
*
Expand Down
Loading

0 comments on commit 392a69e

Please sign in to comment.