Package org.apache.wicket.util.io
Class FullyBufferedReader
- java.lang.Object
-
- org.apache.wicket.util.io.FullyBufferedReader
-
public final class FullyBufferedReader extends Object
This is not a reader like e.g. FileReader. It rather reads the whole data until 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 conveniently 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
Constructors Constructor Description FullyBufferedReader(Reader reader)
Read all the data from the resource into memory.FullyBufferedReader(String input)
Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description char
charAt(int pos)
Get the character at the position providedvoid
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 positionint
find(char ch, int startPos)
Find a char starting at the position providedint
find(String str)
Find the string starting at the current input positionint
find(String str, int startPos)
Find the string starting at the position providedint
findOutOfQuotes(char ch, int startPos)
Find a char starting at the position provided.int
findOutOfQuotes(char ch, int startPos, char quotationChar)
Find a char starting at the position provided.int
getColumnNumber()
Get the column number.int
getLineNumber()
Get the line number.int
getPosition()
Gets the current input positionCharSequence
getSubstring(int toPos)
Get the characters from the position marker to toPos.CharSequence
getSubstring(int fromPos, int toPos)
Get the characters from in between both positions including the char at fromPos, excluding the char at toPosvoid
setPosition(int pos)
Position the reader at the index provided.void
setPositionMarker(int pos)
Remember the current position in markupint
size()
Get the number of character read from the source resource.String
toString()
-
-
-
Constructor Detail
-
FullyBufferedReader
public FullyBufferedReader(Reader reader) throws IOException
Read all the data from the resource into memory.- Parameters:
reader
- The source reader to load the data from- Throws:
IOException
-
FullyBufferedReader
public FullyBufferedReader(String input)
Construct.- Parameters:
input
- The source string
-
-
Method Detail
-
getSubstring
public final 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 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 indextoPos
- 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
-
-
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 forstartPos
- The index to start at- Returns:
- -1 if not found
-
find
public final int find(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(String str, int startPos)
Find the string starting at the position provided- Parameters:
str
- The string to search forstartPos
- The index to start at- Returns:
- -1 if not found
-
findOutOfQuotes
public int findOutOfQuotes(char ch, int startPos) throws ParseException
Find a char starting at the position provided. The char must not be inside a quoted string (single or double)- Parameters:
ch
- The char to search forstartPos
- The index to start at- Returns:
- -1 if not found
- Throws:
ParseException
-
findOutOfQuotes
public int findOutOfQuotes(char ch, int startPos, char quotationChar) throws ParseException
Find a char starting at the position provided. The char must not be inside a quoted string (single or double)- Parameters:
ch
- The char to search forstartPos
- The index to start atquotationChar
- The current quotation char. Must be ' or ", otherwise will be ignored.- Returns:
- -1 if not found
- Throws:
ParseException
-
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
-
-