UnownedOutputStream extends FilterOutputStream { @Override public void write(byte[] b, int off, int len) throws IOException { out.write(b, off, len); } UnownedOutputStream(OutputStream delegate); @Override void close(); @Override boolean equals(@Nullable Object obj); @Override int hashCode(); @Override String toString(); @Override void write(byte[] b, int off, int len);  }
@Test public void testWrite() throws IOException { CallCountOutputStream fsCount = new CallCountOutputStream(); FilterOutputStream fs = new FilterOutputStream(fsCount); CallCountOutputStream osCount = new CallCountOutputStream(); UnownedOutputStream os = new UnownedOutputStream(osCount); byte[] data = "Hello World!".getBytes(StandardCharsets.UTF_8); fs.write(data, 0, data.length); os.write(data, 0, data.length); fs.write('\n'); os.write('\n'); assertEquals(13, fsCount.callCnt); assertEquals(2, osCount.callCnt); assertArrayEquals(fsCount.toByteArray(), osCount.toByteArray()); }