com.Ostermiller.util
Class NoCloseReader

java.lang.Object
  extended by java.io.Reader
      extended by com.Ostermiller.util.NoCloseReader
All Implemented Interfaces:
NoCloseStream, java.io.Closeable, java.lang.Readable

public class NoCloseReader
extends java.io.Reader
implements NoCloseStream

A reader which a close method with no effect. More information about this class is available from ostermiller.org.

This class is designed to wrap a normal reader 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.Reader in
          The reader that is being protected.
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
NoCloseReader(java.io.Reader in)
          Protect a new reader.
 
Method Summary
 void close()
          Has no effect.
 void mark(int readlimit)
          
 boolean markSupported()
          
 int read()
          
 int read(char[] cbuf)
          
 int read(char[] cbuf, int off, int len)
          
 boolean ready()
          
 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.io.Reader
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

protected java.io.Reader in
The reader 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

NoCloseReader

public NoCloseReader(java.io.Reader in)
Protect a new reader.

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

read

public int read()
         throws java.io.IOException

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

read

public int read(char[] cbuf)
         throws java.io.IOException

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

read

public int read(char[] cbuf,
                int off,
                int len)
         throws java.io.IOException

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

skip

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

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

ready

public boolean ready()
              throws java.io.IOException

Overrides:
ready in class java.io.Reader
Throws:
java.io.IOException

close

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

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

mark

public void mark(int readlimit)
          throws java.io.IOException

Overrides:
mark in class java.io.Reader
Throws:
java.io.IOException

reset

public void reset()
           throws java.io.IOException

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

markSupported

public boolean markSupported()

Overrides:
markSupported in class java.io.Reader

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.