com.ibm.commons.util.io
Class LookAheadInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.ibm.commons.util.io.LookAheadInputStream
All Implemented Interfaces:
java.io.Closeable

public class LookAheadInputStream
extends java.io.InputStream

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


Constructor Summary
LookAheadInputStream(java.io.InputStream is, int bufferLength)
          Constructor.
 
Method Summary
 void close()
           
 int getBufferLength()
           
 int getByte()
          Read one byte ahead.
 byte[] getByteAhead(int maxChars)
          Get a string of # characters.
 int getByteAt(int pos)
          Read a byte ahead.
 char getChar()
           
 char getCharAt(int index)
           
 int getCurrentIndex()
           
 boolean hasByte()
          Check if the end of the stream 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(byte[] cbuf, int off, int len)
           
protected  int readBuffer(byte[] buffer, int position, int count)
          Internal function that read data into the buffer.
 long skip(long len)
           
 boolean skipBlanks()
           
 boolean skipBlanks(FastStringBuffer b)
          Skip a list of blanks characters (space, new line, tab...).
 void skipUpto(char c)
           
 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.InputStream
available, mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LookAheadInputStream

public LookAheadInputStream(java.io.InputStream is,
                            int bufferLength)
Constructor.

Method Detail

getBufferLength

public int getBufferLength()

read

public final int read()
               throws java.io.IOException
Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public int read(byte[] cbuf,
                int off,
                int len)
         throws java.io.IOException
Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

skip

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

close

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

getCurrentIndex

public int getCurrentIndex()

readBuffer

protected int readBuffer(byte[] 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

hasByte

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

Throws:
java.io.IOException

getByteAt

public final int getByteAt(int pos)
                    throws java.io.IOException
Read a byte 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

getByte

public final int getByte()
                  throws java.io.IOException
Read one byte ahead.

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

getByteAhead

public byte[] getByteAhead(int maxChars)
                    throws java.io.IOException
Get a string of # characters. Mainly for debugging!

Throws:
java.io.IOException

getChar

public char getChar()
             throws java.io.IOException
Throws:
java.io.IOException

getCharAt

public char getCharAt(int index)
               throws java.io.IOException
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

upto

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