com.Ostermiller.util
Class NoCloseInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.Ostermiller.util.NoCloseInputStream
All Implemented Interfaces:
NoCloseStream, java.io.Closeable

public class NoCloseInputStream
extends java.io.InputStream
implements NoCloseStream

An input 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 input stream so that it can be passed to methods that read from 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.InputStream in
          The input stream that is being protected.
 
Constructor Summary
NoCloseInputStream(java.io.InputStream in)
          Protect a new input stream.
 
Method Summary
 int available()
          
 void close()
          Has no effect.
 void mark(int readlimit)
          
 boolean markSupported()
          
 int read()
          
 int read(byte[] b)
          
 int read(byte[] b, int off, int len)
          
 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 reset()
          
 long skip(long n)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

protected java.io.InputStream in
The input 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

NoCloseInputStream

public NoCloseInputStream(java.io.InputStream in)
Protect a new input stream.

Parameters:
in - The input stream that is being protected.
Since:
ostermillerutils 1.01.00
Method Detail

read

public int read()
         throws java.io.IOException

Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(byte[] b)
         throws java.io.IOException

Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

read

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

Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

skip

public long skip(long n)
          throws java.io.IOException

Overrides:
skip in class java.io.InputStream
Throws:
java.io.IOException

available

public int available()
              throws java.io.IOException

Overrides:
available in class java.io.InputStream
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.InputStream
Throws:
java.io.IOException
Since:
ostermillerutils 1.01.00
See Also:
reallyClose()

mark

public void mark(int readlimit)

Overrides:
mark in class java.io.InputStream

reset

public void reset()
           throws java.io.IOException

Overrides:
reset in class java.io.InputStream
Throws:
java.io.IOException

markSupported

public boolean markSupported()

Overrides:
markSupported in class java.io.InputStream

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.