ResponseOutPutStream extends OutputStream { @Override public void write(int b) { buf.put((byte) b); } ResponseOutPutStream(ByteBuffer buf); @Override void write(int b);  }
@Test public void testRequestOutputStreamReadContent() throws IOException { ByteBuffer buf = ByteBuffer.allocate(2048); OutputStream outputStream = new ResponseOutPutStream(buf); outputStream.write("test".getBytes()); outputStream.write("test".getBytes()); outputStream.write("test".getBytes()); buf.flip(); List<Byte> bytes = new ArrayList<>(); while (buf.hasRemaining()) { bytes.add(buf.get()); } assertEquals("testtesttest", new String(Bytes.toArray(bytes))); }