com.cra.bnet.io
Class CraPushbackReader

java.lang.Object
  |
  +--java.io.Reader
        |
        +--java.io.FilterReader
              |
              +--com.cra.bnet.io.CraPushbackReader

public class CraPushbackReader
extends FilterReader

A reader that allows characters to be pushed back into the stream. The pushed back characters can then be read again later.

This reader uses a growable pushback buffer. That is, clients do not need to worry about pushing back too many characters.


Field Summary
 
Fields inherited from class java.io.FilterReader
in
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
CraPushbackReader(Reader reader)
          Creates a new CraPushbackReader that wraps the specified reader.
 
Method Summary
 void close()
          Closes the stream.
 void mark(int readAheadLimit)
          This method always throws an UnsupportedOperationException.
 boolean markSupported()
          This method always returns false since the mark method is not supported.
 int read()
          Reads a single character and returns it.
 int read(char[] cbuf, int off, int len)
          Reads the specified number of characters into the specified array, starting at the specified index.
 boolean ready()
          Returns true if this reader is ready to be read from and false if it is not.
 void reset()
          This method always throws an UnsupportedOperationException.
 void unread(char[] cbuf)
          Pushes back an array of characters.
 void unread(char[] cbuf, int off, int len)
          Push back a portion of an array of characters.
 void unread(int c)
          Pushes back a single character into the pushback buffer.
 
Methods inherited from class java.io.FilterReader
skip
 
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
 

Constructor Detail

CraPushbackReader

public CraPushbackReader(Reader reader)
Creates a new CraPushbackReader that wraps the specified reader.

Parameters:
reader - reader that this pushback reader wraps.
Method Detail

close

public void close()
           throws IOException
Closes the stream.

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

mark

public void mark(int readAheadLimit)
          throws IOException
This method always throws an UnsupportedOperationException.

Overrides:
mark in class FilterReader
IOException

markSupported

public boolean markSupported()
This method always returns false since the mark method is not supported.

Overrides:
markSupported in class FilterReader

read

public int read()
         throws IOException
Reads a single character and returns it.

Overrides:
read in class FilterReader
Returns:
the character read, or -1 if the end of the stream has been reached.
Throws:
IOException - if an I/O error occurs.

read

public int read(char[] cbuf,
                int off,
                int len)
         throws IOException
Reads the specified number of characters into the specified array, starting at the specified index.

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

ready

public boolean ready()
              throws IOException
Returns true if this reader is ready to be read from and false if it is not.

Overrides:
ready in class FilterReader
Returns:
true if this reader is ready to be read from and false if it is not.
Throws:
IOException - if an I/O error occurs.

reset

public void reset()
           throws IOException
This method always throws an UnsupportedOperationException.

Overrides:
reset in class FilterReader
IOException

unread

public void unread(int c)
            throws IOException
Pushes back a single character into the pushback buffer.

Parameters:
c - character to push back.
Throws:
IOException - if an I/O error occurs.

unread

public void unread(char[] cbuf)
            throws IOException
Pushes back an array of characters. After this method returns, the next character to be read will have the value cbuf[0], the character after that will have the value cbuf[1], and so forth.

Parameters:
cbuf - character array to push back.
Throws:
IOException - if an I/O error occurs.

unread

public void unread(char[] cbuf,
                   int off,
                   int len)
            throws IOException
Push back a portion of an array of characters. After this method returns, the next character to be read will have the value cbuf[off], the character after that will have the value cbuf[off+1], and so forth.

Parameters:
cbuf - character array.
off - offset of first character to push back.
len - number of characters to push back.
Throws:
IOException - if an I/O error occurs.