org.inria.ns.reflex.util.io
Class ExtensibleBufferedReader

java.lang.Object
  extended by java.io.Reader
      extended by java.io.FilterReader
          extended by org.inria.ns.reflex.util.io.ExtensibleBufferedReader
All Implemented Interfaces:
Closeable, Readable, Unwrappable

public class ExtensibleBufferedReader
extends FilterReader
implements Unwrappable

A buffer that always grows once marked until reset.

Author:
Philippe Poulard

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.inria.ns.reflex.structures.Unwrappable
Unwrappable.Unwrapper
 
Field Summary
 
Fields inherited from interface org.inria.ns.reflex.structures.Unwrappable
UNWRAPPER
 
Constructor Summary
ExtensibleBufferedReader(Reader in)
          Creates an ExtensibleBufferedReader based on a given reader.
ExtensibleBufferedReader(Reader in, int size)
          Creates an ExtensibleBufferedReader with the specified buffer size, and based on a given reader.
 
Method Summary
 void close()
          Closes this Reader and releases any system resources associated with the stream.
 void mark(int readlimit)
          See the general contract of the mark method of Reader.
 boolean markSupported()
          Tests if this reader supports the mark and reset methods.
 int read()
          See the general contract of the read method of Reader.
 int read(char[] b, int off, int len)
          Reads chars from this reader into the specified char array, starting at the given offset.
 boolean ready()
          Tell whether this stream is ready to be read.
 void reset()
          See the general contract of the reset method of Reader.
 long skip(long n)
          See the general contract of the skip method of InputStream.
 Object unwrap()
          Unwrap the underlying Reader.
 
Methods inherited from class java.io.Reader
read, read
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtensibleBufferedReader

public ExtensibleBufferedReader(Reader in)
Creates an ExtensibleBufferedReader based on a given reader. This new buffer doesn't bufferize the data once created : mark(int) must be invoked explicitely. The default buffer size is set to 2048.

Parameters:
in - The underlying reader.

ExtensibleBufferedReader

public ExtensibleBufferedReader(Reader in,
                                int size)
Creates an ExtensibleBufferedReader with the specified buffer size, and based on a given reader. This new buffer doesn't bufferize the data once created : mark(int) must be invoked explicitely.

Parameters:
in - The underlying reader.
size - The buffer size.
Throws:
IllegalArgumentException - if size <= 0.
Method Detail

read

public int read()
         throws IOException
See the general contract of the read method of Reader.

Overrides:
read in class FilterReader
Returns:
The next char of data, or -1 if the end of the stream is reached.
Throws:
IOException - if an I/O error occurs.
See Also:
FilterReader.in

read

public int read(char[] b,
                int off,
                int len)
         throws IOException
Reads chars from this reader into the specified char array, starting at the given offset.

This method implements the general contract of the corresponding read method of the Reader class.

Overrides:
read in class FilterReader
Parameters:
b - destination buffer.
off - offset at which to start storing characters.
len - maximum number of characters to read.
Returns:
the number of characters read, or -1 if the end of the stream has been reached.
Throws:
IOException - if an I/O error occurs.

skip

public long skip(long n)
          throws IOException
See the general contract of the skip method of InputStream.

Overrides:
skip in class FilterReader
Parameters:
n - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
Throws:
IOException - if an I/O error occurs.

ready

public boolean ready()
              throws IOException
Tell whether this stream is ready to be read.

Overrides:
ready in class FilterReader
Returns:
true if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.
Throws:
IOException - if an I/O error occurs.
See Also:
FilterInputStream.in

mark

public void mark(int readlimit)
          throws IOException
See the general contract of the mark method of Reader. Once marked, everything read in the underlying reader is buffered. Setting the read limit to 0 consist on canceling the mark.

Overrides:
mark in class FilterReader
Parameters:
readlimit - Data is buffered until reset() is invoked, or until the read limit is set to 0 (in this case, everything that had been buffered is lost).
Throws:
IOException
See Also:
BufferedReader.reset()

reset

public void reset()
           throws IOException
See the general contract of the reset method of Reader.

The mark is always valid ; this method never fails.

Overrides:
reset in class FilterReader
Throws:
IOException - For compatibility.
See Also:
BufferedReader.mark(int)

markSupported

public boolean markSupported()
Tests if this reader supports the mark and reset methods. The markSupported method of ExtensibleBufferedReader returns true.

Overrides:
markSupported in class FilterReader
Returns:
true.
See Also:
InputStream.mark(int), InputStream.reset()

close

public void close()
           throws IOException
Closes this Reader and releases any system resources associated with the stream.

Specified by:
close in interface Closeable
Overrides:
close in class FilterReader
Throws:
IOException - if an I/O error occurs.

unwrap

public Object unwrap()
Unwrap the underlying Reader.

Specified by:
unwrap in interface Unwrappable
See Also:
Unwrappable.unwrap()