UnownedInputStream extends FilterInputStream { @Override public void close() throws IOException { throw new UnsupportedOperationException( "Caller does not own the underlying input stream " + " and should not call close()."); } UnownedInputStream(InputStream delegate); @Override void close(); @Override boolean equals(@Nullable Object obj); @Override int hashCode(); @SuppressWarnings("UnsynchronizedOverridesSynchronized") @Override void mark(int readlimit); @Override boolean markSupported(); @SuppressWarnings("UnsynchronizedOverridesSynchronized") @Override void reset(); @Override String toString();  }
@Test public void testClosingThrows() throws Exception { expectedException.expect(UnsupportedOperationException.class); expectedException.expectMessage("Caller does not own the underlying"); expectedException.expectMessage("close()"); os.close(); }