public class NoCloseOutputStream extends java.io.OutputStream implements NoCloseStream
This class is designed to wrap a normal output stream so that it can be passed to methods that write to it and may erroneously close it. This class is a workaround when the method cannot be modified because it is in a library.
Modifier and Type | Field and Description |
---|---|
protected java.io.OutputStream |
out
The output stream that is being protected.
|
Constructor and Description |
---|
NoCloseOutputStream(java.io.OutputStream out)
Protect a new output stream.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Has no effect.
|
void |
flush() |
void |
reallyClose()
Actually closes this stream and releases any system
resources associated with the stream, as opposed to
the close() method, which does nothing.
|
void |
write(byte[] b) |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
protected java.io.OutputStream out
public NoCloseOutputStream(java.io.OutputStream out)
out
- The output stream that is being protected.public void write(int b) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void write(byte[] b) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void write(byte[] b, int off, int len) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
java.io.IOException
reallyClose()
public void reallyClose() throws java.io.IOException
reallyClose
in interface NoCloseStream
java.io.IOException
- if an I/O error occurs.Copyright (c) 2001-2020 by Stephen Ostermiller