InputStreamProxy extends InputStream implements Serializable { @Override public void close() throws IOException { streamProvider.close(streamID); } InputStreamProxy(int streamID, String address); @Override int read(); @Override int read(byte[] b, int off, int len); int readInternal(); int readInternal(byte[] b, int off, int len); @Override int available(); @Override void close();  }
@Test public void testClose() throws IOException { OwnInputStream in = fillStream('c', 10); int id = streamProvider.registerStream(in); InputStreamProxy fixture = new InputStreamProxy(id, ""); fixture.setStreamProvider(streamProvider); assertEquals('c', fixture.read()); fixture.close(); assertTrue(in.isClosed); try{ streamProvider.read(id); fail("must have been closed already"); } catch(IOException e) {} }