BufferAwareByteArrayOutputStream extends ByteArrayOutputStream { int getBufferSize() { return buf.length; } BufferAwareByteArrayOutputStream(final int size);   }
@Test public void testBufferSize() throws Exception { final BufferAwareByteArrayOutputStream outputStream = new BufferAwareByteArrayOutputStream(8); assertEquals(8, outputStream.getBufferSize()); outputStream.write(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}); assertEquals(8, outputStream.getBufferSize()); outputStream.write(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}); assertEquals(16, outputStream.getBufferSize()); outputStream.reset(); assertEquals(16, outputStream.getBufferSize()); }