wicket.util.io
Class FullyBufferedReader

java.lang.Object
  extended by wicket.util.io.FullyBufferedReader

public final class FullyBufferedReader
extends java.lang.Object

This is not a reader like e.g. FileReader. It rather reads the whole data untill the end from a source reader into memory and besides that it maintains the current position (like a reader) it provides String like methods which conviniently let you navigate (usually forward) in the stream.

Because the source data are expected to be text, the line and column numbers are maintained as well for location precise error messages. But it does NOT automatically update the line and column numbers. You must call countLinesTo(int)

Author:
Juergen Donnerstag

Constructor Summary
FullyBufferedReader(java.io.Reader reader)
          Read all the data from the resource into memory.
 
Method Summary
 char charAt(int pos)
          Get the character at the position provided
 void countLinesTo(int end)
          Counts lines starting where we last left off up to the index provided.
 int find(char ch)
          Find a char starting at the current input position
 int find(char ch, int startPos)
          Find a char starting at the position provided
 int find(java.lang.String str)
          Find the string starting at the current input position
 int find(java.lang.String str, int startPos)
          Find the string starting at the position provided
 int getColumnNumber()
          Get the column number.
 int getLineNumber()
          Get the line number.
 int getPosition()
          Gets the current input position
 java.lang.CharSequence getSubstring(int toPos)
          Get the characters from the position marker to toPos.
 java.lang.CharSequence getSubstring(int fromPos, int toPos)
          Get the characters from in between both positions including the char at fromPos, excluding the char at toPos
 void setPosition(int pos)
          Position the reader at the index provided.
 void setPositionMarker(int pos)
          Remember the current position in markup
 int size()
          Get the number of character read from the source resource.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FullyBufferedReader

public FullyBufferedReader(java.io.Reader reader)
                    throws java.io.IOException
Read all the data from the resource into memory.

Parameters:
reader - The source reader to load the data from
Throws:
java.io.IOException
Method Detail

getSubstring

public final java.lang.CharSequence getSubstring(int toPos)
Get the characters from the position marker to toPos.

If toPos < 0, than get all data from the position marker until the end. If toPos less than the current position marker than return an empty string ""

Parameters:
toPos - Index of first character not included
Returns:
Raw markup (a string) in between these two positions.

getSubstring

public final java.lang.CharSequence getSubstring(int fromPos,
                                                 int toPos)
Get the characters from in between both positions including the char at fromPos, excluding the char at toPos

Parameters:
fromPos - first index
toPos - second index
Returns:
the string (raw markup) in between both positions

getPosition

public final int getPosition()
Gets the current input position

Returns:
input position

setPositionMarker

public final void setPositionMarker(int pos)
Remember the current position in markup

Parameters:
pos -

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
The markup to be parsed

countLinesTo

public final void countLinesTo(int end)
Counts lines starting where we last left off up to the index provided.

Parameters:
end - End index

find

public final int find(char ch)
Find a char starting at the current input position

Parameters:
ch - The char to search for
Returns:
-1 if not found

find

public final int find(char ch,
                      int startPos)
Find a char starting at the position provided

Parameters:
ch - The char to search for
startPos - The index to start at
Returns:
-1 if not found

find

public final int find(java.lang.String str)
Find the string starting at the current input position

Parameters:
str - The string to search for
Returns:
-1 if not found

find

public final int find(java.lang.String str,
                      int startPos)
Find the string starting at the position provided

Parameters:
str - The string to search for
startPos - The index to start at
Returns:
-1 if not found

setPosition

public final void setPosition(int pos)
Position the reader at the index provided. Could be anywhere within the data

Parameters:
pos - The new current position

getColumnNumber

public final int getColumnNumber()
Get the column number. Note: The column number depends on you calling countLinesTo(pos). It is not necessarily the column number matching the current position in the stream.

Returns:
column number

getLineNumber

public final int getLineNumber()
Get the line number. Note: The line number depends on you calling countLinesTo(pos). It is not necessarily the line number matching the current position in the stream.

Returns:
line number

size

public final int size()
Get the number of character read from the source resource. The whole content, not just until the current position.

Returns:
Size of the data

charAt

public final char charAt(int pos)
Get the character at the position provided

Parameters:
pos - The position
Returns:
char at position


Copyright © 2004-2007 Wicket developers. All Rights Reserved.