### Question:
BufferAwareByteArrayOutputStream extends ByteArrayOutputStream { int getBufferSize() { return buf.length; } BufferAwareByteArrayOutputStream(int size);   }### Answer:
@Test public void testBufferSize() throws Exception { 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()); }