IdentityOutputStream extends OutputStream { @Override public void close() throws IOException { if (!this.closed) { this.closed = true; this.buffer.flush(this.outputStream); } } IdentityOutputStream(final SessionOutputBuffer buffer, final OutputStream outputStream); @Override void close(); @Override void flush(); @Override void write(final byte[] b, final int off, final int len); @Override void write(final byte[] b); @Override void write(final int b);  }
@Test public void testClose() throws Exception { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final SessionOutputBuffer outbuffer = new SessionOutputBufferImpl(16); final OutputStream out = new IdentityOutputStream(outbuffer, outputStream); out.close(); out.close(); final byte[] tmp = new byte[10]; try { out.write(tmp); Assert.fail("IOException should have been thrown"); } catch (final IOException ex) { } try { out.write(1); Assert.fail("IOException should have been thrown"); } catch (final IOException ex) { } }