com.cra.bnet.io
Class BufferedRegExpReader

java.lang.Object
  |
  +--java.io.Reader
        |
        +--java.io.FilterReader
              |
              +--com.cra.bnet.io.BufferedRegExpReader
All Implemented Interfaces:
org.apache.regexp.CharacterIterator

public class BufferedRegExpReader
extends FilterReader
implements org.apache.regexp.CharacterIterator

Reader implementation that buffers characters read from a regular expression matcher. This class is used to wrap another Reader and provide its characters to the Jakarta regular expression matcher class RE. All characters read by the regular expression matcher are stored in a buffer so that they can be read again later. The reset method is used to reset the reader, so that the buffer characters will be returned first before reading from the underlying Reader.


Field Summary
 
Fields inherited from class java.io.FilterReader
in
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
BufferedRegExpReader(Reader reader)
          Creates a new BufferedRegExpReader that wraps the specified reader.
 
Method Summary
 char charAt(int index)
          Returns the character at the specified index.
 void close()
          Closes this reader.
 StringBuffer getBuffer()
          Returns the buffer used to store characters read from the underlying reader.
 boolean isEnd(int pos)
          Returns true if the specified index is greater than the last valid index and false if it is a valid index.
 int length()
          Returns the length of this character sequence.
 void mark(int readAheadLimit)
          Throws an UnsupportedOperationException since the mark method is not supported by this class.
 boolean markSupported()
          Returns false sine the mark method is not supported by this class.
 int read()
          Reads a single character and returns it.
 int read(char[] cbuf, int index, int length)
          Reads the specified number of characters into the specified character array, starting at the specified index and returns the number of characters actually read.
 boolean ready()
          Returns true if this reader is ready to supply characters and false if it is not.
 void reset()
          Resets this reader so it will start returning the buffered characters before reading more characters from the underlying reader.
 long skip(long n)
          Throws an UnsupportedOperationException since this class doesn't support the skip method.
 String substring(int start)
          Throws an UnsupportedOperationException since this class doesn't support the substring(int) method.
 String substring(int start, int end)
          Returns the substring between the two specified indices.
 
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

BufferedRegExpReader

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

Parameters:
reader - input stream that will wrapped and buffered.
Method Detail

charAt

public char charAt(int index)
Returns the character at the specified index.

Specified by:
charAt in interface org.apache.regexp.CharacterIterator
Parameters:
index - index of the requested character.
Returns:
the character at the specified index.

close

public void close()
           throws IOException
Closes this reader.

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

getBuffer

public StringBuffer getBuffer()
Returns the buffer used to store characters read from the underlying reader.

Returns:
the buffer used to store characters read from the underlying reader.

isEnd

public boolean isEnd(int pos)
Returns true if the specified index is greater than the last valid index and false if it is a valid index.

Specified by:
isEnd in interface org.apache.regexp.CharacterIterator
Parameters:
pos - index to test.
Returns:
true if the specified index is greater than the last valid index.

length

public int length()
Returns the length of this character sequence. Because there is no way of knowing how many characters the underlying reader will provide, this method returns Integer.MAX_VALUE.

Returns:
the length of this character sequence.

mark

public void mark(int readAheadLimit)
Throws an UnsupportedOperationException since the mark method is not supported by this class.

Overrides:
mark in class FilterReader
Parameters:
readAheadLimit -

markSupported

public boolean markSupported()
Returns false sine the mark method is not supported by this class.

Overrides:
markSupported in class FilterReader
Returns:
false.

read

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

Overrides:
read in class FilterReader
Returns:
the character that was read.
Throws:
IOException - if some I/O error occurs.

read

public int read(char[] cbuf,
                int index,
                int length)
         throws IOException
Reads the specified number of characters into the specified character array, starting at the specified index and returns the number of characters actually read.

Overrides:
read in class FilterReader
Parameters:
cbuf - character array that the characters are copied into.
index - index in the array to start putting the characters at.
length - number of characters to read.
Returns:
number of characters actually read.
Throws:
IOException - if some I/O error occurs.

ready

public boolean ready()
              throws IOException
Returns true if this reader is ready to supply characters and false if it is not.

Overrides:
ready in class FilterReader
Returns:
true if this reader is ready to supply characters and false if it is not.
Throws:
IOException - if some I/O error occurs.

reset

public void reset()
Resets this reader so it will start returning the buffered characters before reading more characters from the underlying reader.

Overrides:
reset in class FilterReader

skip

public long skip(long n)
Throws an UnsupportedOperationException since this class doesn't support the skip method.

Overrides:
skip in class FilterReader

substring

public String substring(int start)
Throws an UnsupportedOperationException since this class doesn't support the substring(int) method.

Specified by:
substring in interface org.apache.regexp.CharacterIterator

substring

public String substring(int start,
                        int end)
Returns the substring between the two specified indices. The first character in the string is the one at the specified start index, and the last character is the one just before the specified end index.

Specified by:
substring in interface org.apache.regexp.CharacterIterator
Parameters:
start - beginning index of the substring.
end - ending index of the substring.
Returns:
the substring between the two specified indices.