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
    Read all the data from the resource into memory.
    Construct.
  • Method Summary

    Modifier and Type
    Method
    Description
    final char
    charAt(int pos)
    Get the character at the position provided
    final void
    countLinesTo(int end)
    Counts lines starting where we last left off up to the index provided.
    final int
    find(char ch)
    Find a char starting at the current input position
    final int
    find(char ch, int startPos)
    Find a char starting at the position provided
    final int
    find(String str)
    Find the string starting at the current input position
    final int
    find(String str, int startPos)
    Find the string starting at the position provided
    int
    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.
    final int
    Get the column number.
    final int
    Get the line number.
    final int
    Gets the current input position
    getSubstring(int toPos)
    Get the characters from the position marker to toPos.
    getSubstring(int fromPos, int toPos)
    Get the characters from in between both positions including the char at fromPos, excluding the char at toPos
    final void
    setPosition(int pos)
    Position the reader at the index provided.
    final void
    Remember the current position in markup
    final int
    Get the number of character read from the source resource.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • 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 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 String toString()
      Overrides:
      toString in class 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(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 for
      startPos - 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 for
      startPos - 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 for
      startPos - The index to start at
      quotationChar - 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