DirectByteBufferOutputStream extends OutputStream { @Override public void write(final int b) throws IOException { try { if (currentBuf.remaining() <= 0) { newLastBuffer(); currentBuf = dataList.getLast().getBuffer(); } currentBuf.put((byte) b); } catch (IllegalStateException e) { throw new IllegalStateException("MemoryChunk has been freed"); } catch (MemoryAllocationException e) { throw new IOException("Failed to allocate memory"); } } DirectByteBufferOutputStream(final MemoryPoolAssigner memoryPoolAssigner); @Override void write(final int b); @Override void write(final byte[] b); @Override void write(final byte[] b, final int off, final int len); List<MemoryChunk> getMemoryChunkList(); int size(); @Override void close();  }
@Test public void testWrite() throws IOException { String value = "value"; outputStream.write(value.getBytes()); assertEquals(value, new String(outputStream.toByteArray())); }