ReusableBufferedOutputStream extends BufferedOutputStream { public void reset(OutputStream out) { Assertions.checkState(closed); this.out = out; count = 0; closed = false; } ReusableBufferedOutputStream(OutputStream out);  ReusableBufferedOutputStream(OutputStream out, int size); @Override void close(); void reset(OutputStream out);  }
@Test public void testReset() throws Exception { ByteArrayOutputStream byteArrayOutputStream1 = new ByteArrayOutputStream(1000); ReusableBufferedOutputStream outputStream = new ReusableBufferedOutputStream( byteArrayOutputStream1, 1000); outputStream.write(TEST_DATA_1); outputStream.close(); ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream(1000); outputStream.reset(byteArrayOutputStream2); outputStream.write(TEST_DATA_2); outputStream.close(); assertThat(byteArrayOutputStream1.toByteArray()).isEqualTo(TEST_DATA_1); assertThat(byteArrayOutputStream2.toByteArray()).isEqualTo(TEST_DATA_2); }