FixedSizeByteArrayOutputStream extends ByteArrayOutputStream { @Override public synchronized void reset() { super.reset(); remaining = super.buf.length; } FixedSizeByteArrayOutputStream(final int maxSize); @Override void write(int b); @Override void write(byte[] b, int off, int len); @Override synchronized void reset();  }
@Test public void testReset() throws Exception { FixedSizeByteArrayOutputStream fixedSizeByteArrayOutputStream = new FixedSizeByteArrayOutputStream(10); Assert.assertEquals(0, fixedSizeByteArrayOutputStream.size()); fixedSizeByteArrayOutputStream.write(new byte[]{0x01, 0x02, 0x03, 0x04}); Assert.assertEquals(4, fixedSizeByteArrayOutputStream.size()); fixedSizeByteArrayOutputStream.reset(); Assert.assertEquals(0, fixedSizeByteArrayOutputStream.size()); fixedSizeByteArrayOutputStream.write(new byte[]{0x01, 0x02, 0x03, 0x04, 0x05, 0x6, 0x7}); Assert.assertEquals(7, fixedSizeByteArrayOutputStream.size()); }