SharedOutputBuffer extends AbstractSharedBuffer implements ContentOutputBuffer { public void flush(final DataStreamChannel channel) throws IOException { lock.lock(); try { dataStreamChannel = channel; hasCapacity = true; setOutputMode(); if (buffer().hasRemaining()) { dataStreamChannel.write(buffer()); } if (!buffer().hasRemaining() && endStream) { propagateEndStream(); } condition.signalAll(); } finally { lock.unlock(); } } SharedOutputBuffer(final ReentrantLock lock, final int initialBufferSize);  SharedOutputBuffer(final int bufferSize); void flush(final DataStreamChannel channel); @Override void write(final byte[] b, final int off, final int len); @Override void write(final int b); @Override void writeCompleted();  }
@Test public void testFlush() throws Exception { final Charset charset = StandardCharsets.US_ASCII; final SharedOutputBuffer outputBuffer = new SharedOutputBuffer(30); final WritableByteChannelMock channel = new WritableByteChannelMock(1024); final DataStreamChannel dataStreamChannel = new DataStreamChannelMock(channel); outputBuffer.flush(dataStreamChannel); Assert.assertEquals(0, outputBuffer.length()); Assert.assertEquals(30, outputBuffer.capacity()); final byte[] tmp = "1234567890".getBytes(charset); outputBuffer.write(tmp, 0, tmp.length); outputBuffer.write(tmp, 0, tmp.length); outputBuffer.write('1'); outputBuffer.write('2'); outputBuffer.flush(dataStreamChannel); Assert.assertEquals(0, outputBuffer.length()); Assert.assertEquals(30, outputBuffer.capacity()); }