MatchingOutputStream extends OutputStream { public void expectEof() throws IOException { if (expectedBytesStream.read() != -1) { throw new MismatchException("EOF not reached in expectedBytesStream"); } } MatchingOutputStream(InputStream expectedBytesStream, int matchBufferSize); @Override void write(int b); @Override void write(byte[] b); @Override void write(byte[] dataToWrite, int offset, int length); @Override void close(); void expectEof();  }
@Test public void testExpectEof() throws IOException { outputStream.write(data); outputStream.expectEof(); }