com.Ostermiller.util Java Utilities


com.Ostermiller.util
Class NoCloseOutputStream

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

public class NoCloseOutputStream
extends 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  OutputStream out
          The output stream that is being protected.
 
Constructor Summary
NoCloseOutputStream(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 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(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 IOException

Specified by:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] b)
           throws IOException

Overrides:
write in class OutputStream
Throws:
IOException

write

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

Overrides:
write in class OutputStream
Throws:
IOException

flush

public void flush()
           throws IOException

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

close

public void close()
           throws IOException
Has no effect.

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

reallyClose

public void reallyClose()
                 throws 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:
IOException - if an I/O error occurs.

com.Ostermiller.util Java Utilities


Copyright (c) 2001-2007 by Stephen Ostermiller