UnownedOutputStream extends FilterOutputStream { @Override public void close() throws IOException { throw new UnsupportedOperationException( "Caller does not own the underlying output stream " + " and should not call close()."); } 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 testClosingThrows() throws Exception { expectedException.expect(UnsupportedOperationException.class); expectedException.expectMessage("Caller does not own the underlying"); os.close(); }