BufferedElementCountingOutputStream extends OutputStream { @Override public void close() throws IOException { finish(); os.close(); } BufferedElementCountingOutputStream(OutputStream os);  BufferedElementCountingOutputStream(OutputStream os, long terminatorValue);   BufferedElementCountingOutputStream(OutputStream os, int bufferSize, long terminatorValue); void finish(); void markElementStart(); @Override void write(int b); @Override void write(byte[] b, int off, int len); @Override void flush(); @Override void close(); static final int DEFAULT_BUFFER_SIZE; }
@Test public void testClosingFinishesTheStream() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedElementCountingOutputStream os = createAndWriteValues(toBytes("abcdefghij"), baos); os.close(); verifyValues(toBytes("abcdefghij"), new ByteArrayInputStream(baos.toByteArray())); }