net.sf.japaki.io
Class SlicedReader

java.lang.Object
  extended by java.io.Reader
      extended by net.sf.japaki.io.SlicedReader
All Implemented Interfaces:
Closeable, Readable

public class SlicedReader
extends Reader

A sliced reader is a reader that can be "sliced". A slice is a kind of clone that is based on the same reader as the original but stores its own position in the character stream. The ability to keep the position depends on the size of the underlying buffer.


Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
protected SlicedReader(ReaderBuffer buffer)
          Constructs a new sliced reader based on the given reader.
 
Method Summary
 void close()
           
protected  int getPosition()
          Returns the current position.
static SlicedReader newReader(Reader in)
          Constructs a new sliced reader based on the given reader.
static SlicedReader newReader(Reader in, int sz)
          Constructs a new sliced reader based on the given reader.
 int read(char[] cbuf, int off, int len)
           
 SlicedReader slice()
          Creates a slice of this reader.
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SlicedReader

protected SlicedReader(ReaderBuffer buffer)
Constructs a new sliced reader based on the given reader.

Parameters:
buffer - base buffer
Throws:
NullPointerException - if buffer is null
Method Detail

newReader

public static SlicedReader newReader(Reader in,
                                     int sz)
Constructs a new sliced reader based on the given reader.

Parameters:
in - base reader
sz - size to allocate for the buffer
Throws:
NullPointerException - if in is null
IllegalArgumentException - if the size is a negative integer

newReader

public static SlicedReader newReader(Reader in)
Constructs a new sliced reader based on the given reader.

Parameters:
in - base reader
Throws:
NullPointerException - if in is null

getPosition

protected int getPosition()
Returns the current position.

Returns:
the current position

slice

public SlicedReader slice()
Creates a slice of this reader.

Returns:
a new slice of this reader

read

public int read(char[] cbuf,
                int off,
                int len)
         throws IOException
Specified by:
read in class Reader
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in class Reader
Throws:
IOException