com.Ostermiller.util
Class NoCloseOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.Ostermiller.util.NoCloseOutputStream
All Implemented Interfaces:
NoCloseStream, java.io.Closeable, java.io.Flushable

public class NoCloseOutputStream
extends java.io.OutputStream
implements NoCloseStream

An output stream with a close method with no effect. More information about this class is available from ostermiller.org.

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.

Since:
ostermillerutils 1.01.00

Field Summary
protected  java.io.OutputStream out
          The output stream that is being protected.
 
Constructor Summary
NoCloseOutputStream(java.io.OutputStream out)
          Protect a new output stream.
 
Method Summary
 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)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected java.io.OutputStream out
The output stream that is being protected. All methods should be forwarded to it, except for the close method, which should do nothing. The reallyClose method should actually close this stream.

Since:
ostermillerutils 1.01.00
Constructor Detail

NoCloseOutputStream

public NoCloseOutputStream(java.io.OutputStream out)
Protect a new output stream.

Parameters:
out - The output stream that is being protected.
Since:
ostermillerutils 1.01.00
Method Detail

write

public void write(int b)
           throws java.io.IOException

Specified by:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException

Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException

Overrides:
write in class java.io.OutputStream
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Has no effect.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException
Since:
ostermillerutils 1.01.00
See Also:
reallyClose()

reallyClose

public void reallyClose()
                 throws java.io.IOException
Actually closes this stream and releases any system resources associated with the stream, as opposed to the close() method, which does nothing.

Specified by:
reallyClose in interface NoCloseStream
Throws:
java.io.IOException - if an I/O error occurs.