PooledByteBufferOutputStream extends OutputStream implements AutoCloseable { public void release() { if (pooledByteBuffer != null) { LOGGER.trace("Releasing pooledBuffer {}", pooledByteBuffer); pooledByteBuffer.release(); pooledByteBuffer = null; } } @Inject  PooledByteBufferOutputStream(final ByteBufferPool byteBufferPool,
                                        @Assisted final int initialCapacity); PooledByteBuffer getPooledByteBuffer(); @Override void write(int b); @Override void write(byte[] b); void release(); void clear(); @Override void close(); @Override String toString();  }
@Test void testRelease() throws IOException { ByteBufferPool byteBufferPool = getByteBufferPool(); assertThat(byteBufferPool.getCurrentPoolSize()).isEqualTo(0); PooledByteBufferOutputStream pooledByteBufferOutputStream = new PooledByteBufferOutputStream( byteBufferPool, 2); pooledByteBufferOutputStream.write(new byte[]{0, 0}); pooledByteBufferOutputStream.getPooledByteBuffer().release(); assertThat(byteBufferPool.getCurrentPoolSize()).isEqualTo(1); pooledByteBufferOutputStream.release(); assertThat(byteBufferPool.getCurrentPoolSize()).isEqualTo(1); }