com.ibm.commons.util.io
Class LookAheadReader

java.lang.Object
  extended by java.io.Reader
      extended by com.ibm.commons.util.io.LookAheadReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable

public class LookAheadReader
extends java.io.Reader

The lexical reader is a specific reader that cache some data of another reader and that permits a lookup of characters.


Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
LookAheadReader(java.io.Reader reader, int bufferLength)
          Constructor.
 
Method Summary
 void close()
           
 void copy(java.io.Writer w)
          Copy to a writer
 int getBufferLength()
           
 int getChar()
          Read one character ahead.
 int getCharAt(int pos)
          Read a character ahead.
 int getCurrentIndex()
           
 java.lang.String getStringAhead(int maxChars)
          Get a string of # characters.
 boolean hasChar()
          Check if the end of the strealm has been reached
 boolean match(char c)
           
 boolean match(java.lang.String s)
           
 boolean matchIgnoreCase(char c)
           
 boolean matchIgnoreCase(java.lang.String s)
           
 int read()
           
 int read(char[] cbuf, int off, int len)
           
protected  int readBuffer(char[] buffer, int position, int count)
          Internal function that read data into the buffer.
 int readCDATABase64()
           
 int readCDATABase64Bytes(byte[] b)
           
 int readCDATABase64Bytes(byte[] b, int off, int len)
           
 long skip(long len)
           
 boolean skipBlanks()
           
 boolean skipBlanks(FastStringBuffer b)
          Skip a list of blanks characters (space, new line, tab...).
 void skipUpto(char c)
           
 void skipUpto(java.lang.String s)
           
 void skipUptoEOL()
           
 boolean startsWith(char c)
           
 boolean startsWith(java.lang.String s)
           
 boolean startsWithIgnoreCase(char c)
           
 boolean startsWithIgnoreCase(java.lang.String s)
           
 java.lang.String upto(char c)
           
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, ready, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LookAheadReader

public LookAheadReader(java.io.Reader reader,
                       int bufferLength)
Constructor.

Method Detail

getBufferLength

public int getBufferLength()

read

public final int read()
               throws java.io.IOException
Overrides:
read in class java.io.Reader
Throws:
java.io.IOException

readCDATABase64

public final int readCDATABase64()
                          throws java.io.IOException
Throws:
java.io.IOException

readCDATABase64Bytes

public final int readCDATABase64Bytes(byte[] b)
                               throws java.io.IOException
Throws:
java.io.IOException

readCDATABase64Bytes

public final int readCDATABase64Bytes(byte[] b,
                                      int off,
                                      int len)
                               throws java.io.IOException
Throws:
java.io.IOException

read

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

skip

public long skip(long len)
          throws java.io.IOException
Overrides:
skip in class java.io.Reader
Throws:
java.io.IOException

close

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

getCurrentIndex

public int getCurrentIndex()

readBuffer

protected int readBuffer(char[] buffer,
                         int position,
                         int count)
                  throws java.io.IOException
Internal function that read data into the buffer. It can be overriden in order to set some kind of filters (skipping blanks, comments...).

Throws:
java.io.IOException

hasChar

public boolean hasChar()
                throws java.io.IOException
Check if the end of the strealm has been reached

Throws:
java.io.IOException

getCharAt

public final int getCharAt(int pos)
                    throws java.io.IOException
Read a character ahead. The position cannot be greater than the buffer length.

Parameters:
pos - the character position
Returns:
the character, -1 if not available (not enough character in the reader)
Throws:
java.io.IOException

getChar

public final int getChar()
                  throws java.io.IOException
Read one character ahead.

Returns:
the character, -1 if not available (not enough character in the reader)
Throws:
java.io.IOException

getStringAhead

public java.lang.String getStringAhead(int maxChars)
                                throws java.io.IOException
Get a string of # characters. Mainly for debugging!

Throws:
java.io.IOException

startsWith

public boolean startsWith(char c)
                   throws java.io.IOException
Throws:
java.io.IOException

startsWithIgnoreCase

public boolean startsWithIgnoreCase(char c)
                             throws java.io.IOException
Throws:
java.io.IOException

startsWith

public boolean startsWith(java.lang.String s)
                   throws java.io.IOException
Throws:
java.io.IOException

startsWithIgnoreCase

public boolean startsWithIgnoreCase(java.lang.String s)
                             throws java.io.IOException
Throws:
java.io.IOException

match

public boolean match(char c)
              throws java.io.IOException
Throws:
java.io.IOException

matchIgnoreCase

public boolean matchIgnoreCase(char c)
                        throws java.io.IOException
Throws:
java.io.IOException

match

public boolean match(java.lang.String s)
              throws java.io.IOException
Throws:
java.io.IOException

matchIgnoreCase

public boolean matchIgnoreCase(java.lang.String s)
                        throws java.io.IOException
Throws:
java.io.IOException

skipBlanks

public boolean skipBlanks(FastStringBuffer b)
                   throws java.io.IOException
Skip a list of blanks characters (space, new line, tab...).

Throws:
java.io.IOException

skipBlanks

public boolean skipBlanks()
                   throws java.io.IOException
Throws:
java.io.IOException

skipUpto

public void skipUpto(char c)
              throws java.io.IOException
Throws:
java.io.IOException

skipUpto

public void skipUpto(java.lang.String s)
              throws java.io.IOException
Throws:
java.io.IOException

skipUptoEOL

public void skipUptoEOL()
                 throws java.io.IOException
Throws:
java.io.IOException

upto

public java.lang.String upto(char c)
                      throws java.io.IOException
Throws:
java.io.IOException

copy

public void copy(java.io.Writer w)
          throws java.io.IOException
Copy to a writer

Throws:
java.io.IOException