ByteBufferOutputStream extends OutputStream { public ByteBuffer getByteBuffer() { ByteBuffer out = buffer.asReadOnlyBuffer(); out.limit(out.position()); out.position(0); return out; } ByteBufferOutputStream(); private  ByteBufferOutputStream(ByteBuffer buffer);  ByteBufferOutputStream(int initialSize); ByteBuffer getByteBuffer(); boolean isElastic(); void setElastic(boolean elastic); @Override void write(byte[] b, int off, int len); @Override void write(int b);  }
@Test public void testEmpty() throws IOException { ByteBufferOutputStream bbos = new ByteBufferOutputStream(); bbos.close(); assertEquals(0, bbos.getByteBuffer().remaining()); }