Skip to content

Commit

Permalink
add takeByteBuffer method to ByteBufferOutputStream2
Browse files Browse the repository at this point in the history
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Nov 11, 2020
1 parent 595d4bf commit d75e6de
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
public class ByteBufferOutputStream2 extends OutputStream
{
private final ByteBufferAccumulator _accumulator;
private final ByteBufferPool _bufferPool;
private int _size = 0;

public ByteBufferOutputStream2()
Expand All @@ -42,8 +41,12 @@ public ByteBufferOutputStream2()

public ByteBufferOutputStream2(ByteBufferPool bufferPool)
{
_bufferPool = (bufferPool == null) ? new NullByteBufferPool() : bufferPool;
_accumulator = new ByteBufferAccumulator(bufferPool);
_accumulator = new ByteBufferAccumulator((bufferPool == null) ? new NullByteBufferPool() : bufferPool);
}

public ByteBuffer takeByteBuffer()
{
return _accumulator.takeByteBuffer();
}

/**
Expand Down Expand Up @@ -108,7 +111,7 @@ public void close()
@Override
public synchronized String toString()
{
return String.format("%s@%x{size=%d, bufferPool=%s, byteAccumulator=%s}", getClass().getSimpleName(),
hashCode(), _size, _bufferPool, _accumulator);
return String.format("%s@%x{size=%d, byteAccumulator=%s}", getClass().getSimpleName(),
hashCode(), _size, _accumulator);
}
}

0 comments on commit d75e6de

Please sign in to comment.