Skip to content

Commit

Permalink
Fixed bugs found by the compression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DavyLandman committed Feb 28, 2024
1 parent 0bdf10c commit c274f1d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,20 @@ public void flush() throws IOException {
if (closed) {
throw new IOException("Stream closed");
}

target.flip();
if (target.hasRemaining()) {
target = flush(target);
if (!target.hasRemaining()) {
throw new IOException("flush implementation didn't correctly provide a new buffer to write to: " + target);
}
}
else {
// the buffer was empty, so flush was called on an already flushed stream
// so we'll reset the buffer to make sure we don't continue with empty buffer
target.clear();
}
assert target.hasRemaining(): "after a flush, we should have a buffer with some room. (it was: " + target + ")";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public BinaryWireOutputStream(OutputStream stream, int stringSharingWindowSize)
this(stream, stringSharingWindowSize, 8*1024);
}
public BinaryWireOutputStream(OutputStream stream, int stringSharingWindowSize, int bufferSize) throws IOException {
assert stringSharingWindowSize > 0;
if (stream instanceof BufferedOutputStream || stream instanceof ByteBufferOutputStream) {
__stream = stream;
}
Expand Down

0 comments on commit c274f1d

Please sign in to comment.