Class CharacterParser

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.BufferedReader br  
      private int columnNumber
      The position, within the current line, of the character being parsed.
      private java.lang.String currentLine  
      private static int END_OF_STREAM  
      private int lineNumber
      The line number of the current line being parsed.
    • Constructor Summary

      Constructors 
      Constructor Description
      CharacterParser​(java.io.BufferedReader br)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) int getColumnNumber()
      Returns the index, in the line currently being parsed, of the character that will be returned by the next call to getNext().
      (package private) java.lang.String getLine()
      Returns the entire contents of the line currently being parsed.
      (package private) int getLineNumber()
      Returns the line number of the line currently being parsed.
      (package private) int getNext()
      Reads a single character.
      (package private) int peek()
      Reads a single character but does not consume it.
      (package private) void rewind()
      Moves the parser back one character.
      (package private) void rewind​(int numberOfCharacters)
      Moves the parser back by the specified number of characters.
      (package private) void skipLine()
      Skips the remainder of the line currently being parsed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • br

        private final java.io.BufferedReader br
      • currentLine

        private java.lang.String currentLine
      • lineNumber

        private int lineNumber
        The line number of the current line being parsed.

        Required in order to provide useful information if a ParserException is thrown.

      • columnNumber

        private int columnNumber
        The position, within the current line, of the character being parsed.

        Required in order to provide useful information if a ParserException is thrown.

    • Constructor Detail

      • CharacterParser

        CharacterParser​(java.io.BufferedReader br)
    • Method Detail

      • getNext

        int getNext()
        Reads a single character.

        Every call to getNext() causes the parser to move forward one character - meaning that by making repeated calls to getNext() all characters in the the underlying stream represented by this object will be returned.

        Returns:
        The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
        Throws:
        ParserException - if an I/O error occurs
        See Also:
        peek()
      • peek

        int peek()
        Reads a single character but does not consume it.
        Returns:
        The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
        Throws:
        ParserException - if an I/O error occurs
        See Also:
        getNext()
      • rewind

        void rewind()
        Moves the parser back one character.
        Throws:
        ParserException - if attempting to rewind back past the start of the current line
      • rewind

        void rewind​(int numberOfCharacters)
        Moves the parser back by the specified number of characters.
        Throws:
        ParserException - if attempting to rewind back past the start of the current line
      • skipLine

        void skipLine()
        Skips the remainder of the line currently being parsed.
      • getLine

        java.lang.String getLine()
        Returns the entire contents of the line currently being parsed.
      • getLineNumber

        int getLineNumber()
        Returns the line number of the line currently being parsed.
      • getColumnNumber

        int getColumnNumber()
        Returns the index, in the line currently being parsed, of the character that will be returned by the next call to getNext().