On Fri, 26 Oct 2007 04:31:15 -0400, Esmond Pitt
<esmond.pitt@nospam.bigpond.com> wrote:
Arne VajhHj wrote:
Something similar can be made to work.
public class NonClosingStream extends OutputStream {
It's *much* simpler than that:
public class NonClosingStream extends FilterOutputStream {
public NonClosingStream(OutputStream out) { super(out); }
public void close() {}
}
While that will actually work, pushing data through that stream is
extremely inefficient.
While FilterInputStream.read(byte[], int, int) passes through the
buffered read to the underlying stream, FilterOutputStream.write(byte[],
int, int) breaks the write into unbuffered byte-by-byte writes.
So, you *really* want
public class NonClosingStream extends FilterOutputStream {
public NonClosingStream(OutputStream out) { super(out); }
public void write(byte[] buf, int off, int len) throws IOException {
out.write(buf, off, len);
}
public void close() {}
}
Just another fun qwerk from classes designed back in the Java 1.0 days.
As an alternative, check out
org.apache.commons.io.input.ProxyInputStream. The Apache Commons IO
library seems to have tried to learn from these little problems.
of the class you are extending.