com.gc.iotools.stream.reader
Class CloseOnceReader<T extends Reader>

java.lang.Object
  extended by java.io.Reader
      extended by com.gc.iotools.stream.reader.CloseOnceReader<T>
Type Parameters:
T - Type of the Reader passed in the constructor.
All Implemented Interfaces:
Closeable, Readable

public class CloseOnceReader<T extends Reader>
extends Reader

A CloseOnceReader wraps some other Reader, which it uses as its basic source of data. The class CloseOnceReader pass all requests to the contained input stream, except the close() method that is passed only one time to the underlying stream.

Multiple invocation of the close() method will result in only one invocation of the same method on the underlying stream. This is useful with some buggy Reader that don't allow close() to be called multiple times.

Since:
1.2.7
Version:
$Id: CloseOnceReader.java 463 2011-01-21 23:54:17Z dvd.smnt@gmail.com $
Author:
dvd.smnt

Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
CloseOnceReader(T source)
          Construct a CloseOnceReader that forwards the calls to the source Reader passed in the constructor.
 
Method Summary
 void close()
          
 int getCloseCount()
          Returns the number of time that close was called.
 T getWrappedReader()
           Returns the wrapped (original) Reader passed in the constructor.
 void mark(int readAheadLimit)
          
 boolean markSupported()
          
 int read()
          
 int read(char[] cbuf)
          
 int read(char[] cbuf, int off, int len)
          
 int read(CharBuffer target)
          
 boolean ready()
          
 void reset()
          
 long skip(long n)
          
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CloseOnceReader

public CloseOnceReader(T source)
Construct a CloseOnceReader that forwards the calls to the source Reader passed in the constructor.

Parameters:
source - original Reader
Method Detail

close

public void close()
           throws IOException

Multiple invocation of this method will result in only one invocation of the close() on the underlying stream.

Specified by:
close in interface Closeable
Specified by:
close in class Reader
Throws:
IOException

getCloseCount

public int getCloseCount()
Returns the number of time that close was called.

Returns:
Number of times that close was called

getWrappedReader

public T getWrappedReader()

Returns the wrapped (original) Reader passed in the constructor.

Returns:
The original Reader passed in the constructor

mark

public void mark(int readAheadLimit)
          throws IOException

Overrides:
mark in class Reader
Throws:
IOException

markSupported

public boolean markSupported()

Overrides:
markSupported in class Reader

read

public int read()
         throws IOException

Overrides:
read in class Reader
Throws:
IOException

read

public int read(char[] cbuf)
         throws IOException

Overrides:
read in class Reader
Throws:
IOException

read

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

Specified by:
read in class Reader
Throws:
IOException

read

public int read(CharBuffer target)
         throws IOException

Specified by:
read in interface Readable
Overrides:
read in class Reader
Throws:
IOException

ready

public boolean ready()
              throws IOException

Overrides:
ready in class Reader
Throws:
IOException

reset

public void reset()
           throws IOException

Overrides:
reset in class Reader
Throws:
IOException

skip

public long skip(long n)
          throws IOException

Overrides:
skip in class Reader
Throws:
IOException

toString

public String toString()

Overrides:
toString in class Object


Copyright © 2008-2011. All Rights Reserved.