Class ParseReader

All Implemented Interfaces:
Closeable, AutoCloseable, Readable

@Deprecated public class ParseReader extends ProcessingBufferedReader
Deprecated.
Class which provides methods for parsing data from a stream.
Author:
Garret Wilson
  • Constructor Details

    • ParseReader

      public ParseReader(Reader reader)
      Deprecated.
      Constructor that specifies another reader.
      Parameters:
      reader - The reader that contains the data.
    • ParseReader

      public ParseReader(Reader reader, String name)
      Deprecated.
      Constructor that specifies another reader and a name.
      Parameters:
      reader - The reader that contains the data.
      name - The name of the reader.
    • ParseReader

      public ParseReader(String inString) throws IOException
      Deprecated.
      Constructor to create a reader from the contents of a string.
      Parameters:
      inString - The string that should be used for input.
      Throws:
      IOException - Thrown when an I/O error occurs.
    • ParseReader

      public ParseReader(String inString, String name) throws IOException
      Deprecated.
      Constructor to create a reader from the contents of a string.
      Parameters:
      inString - The string that should be used for input.
      name - The name of the reader.
      Throws:
      IOException - Thrown when an I/O error occurs.
    • ParseReader

      public ParseReader(Reader inReader, StringBuffer prereadCharacters) throws IOException
      Deprecated.
      Constructor to create a ParseReader from another reader, along with several characters that have already been read. prereadCharacters must be less than or equal to the length of the buffer.
      Parameters:
      inReader - The reader that contains the data.
      prereadCharacters - The characters that have already been read.
      Throws:
      IOException - Thrown if prereadCharacters is too long for the buffer.
      See Also:
    • ParseReader

      public ParseReader(Reader inReader, Object sourceObject) throws IOException
      Deprecated.
      Constructor to create a ParseReader from another reader, along with a source object. prereadCharacters must be less than or equal to the length of the buffer.
      Parameters:
      inReader - The reader that contains the data.
      sourceObject - The source of the data (e.g. a String, File, or URL).
      Throws:
      IOException - Thrown if prereadCharacters is too long for the buffer.
      See Also:
    • ParseReader

      public ParseReader(Reader inReader, StringBuffer prereadCharacters, Object sourceObject) throws IOException
      Deprecated.
      Constructor to create a ParseReader from another reader, along with several characters that have already been read and a source object. prereadCharacters must be less than or equal to the length of the buffer.
      Parameters:
      inReader - The reader that contains the data.
      prereadCharacters - The characters that have already been read.
      sourceObject - The source of the data (e.g. a String, File, or URL).
      Throws:
      IOException - Thrown if prereadCharacters is too long for the buffer.
      See Also:
  • Method Details

    • getSourceObject

      public Object getSourceObject()
      Deprecated.
      Returns:
      The source of the data, if one has been assigned.
    • setSourceObject

      public void setSourceObject(Object newSourceObject)
      Deprecated.
      Sets the source of the reader's data.
      Parameters:
      newSourceObject - The new source of the reader's data.
    • getName

      public String getName()
      Deprecated.
      Returns the name of this reader. If there is no name, and there is a source object, the source object in string form is returned. This function is guaranteed not to return null.
      Returns:
      The name of this reader, if one has been assigned, else the empty string.
      See Also:
    • setName

      public void setName(String newName)
      Deprecated.
      Sets the name of the reader.
      Parameters:
      newName - The new name of the reader.
    • getLineIndex

      public long getLineIndex(int bufferIndex)
      Deprecated.
      Parameters:
      bufferIndex - The buffer index of specified character.
      Returns:
      The index of the line of the character at the specified index in the buffer.
      See Also:
    • getLineIndex

      public long getLineIndex()
      Deprecated.
      Returns:
      The index of the line of the character last read, or 0 if no characters have been read.
      See Also:
    • setLineIndex

      public void setLineIndex(long newLineIndex)
      Deprecated.
      Changes the line index of the last character read.
      Parameters:
      newLineIndex - The new line index.
      See Also:
    • getCharIndex

      public long getCharIndex(int bufferIndex)
      Deprecated.
      Parameters:
      bufferIndex - The buffer index of the specified character.
      Returns:
      The character index of the character at the specified index in the buffer.
      See Also:
    • getCharIndex

      public long getCharIndex()
      Deprecated.
      Returns:
      The index of the character last read, or -1 if no characters have been read.
      See Also:
    • setCharIndex

      public void setCharIndex(long newCharIndex)
      Deprecated.
      Changes the index of the last character read.
      Parameters:
      newCharIndex - The new character index.
      See Also:
    • getLastPositionIndex

      protected int getLastPositionIndex()
      Deprecated.
      Returns:
      The index of the last time the line and character indexes were updated.
      See Also:
    • setLastPositionIndex

      protected void setLastPositionIndex(int lastPositionIndex)
      Deprecated.
      Sets the index of the last time the line and character indexes were updated. This is usually set to the current read index after synchronizing the position.
      Parameters:
      lastPositionIndex - The index of the last time the line and character indexes were updated.
      See Also:
    • initializeIndexes

      protected void initializeIndexes()
      Deprecated.
      Initializes relevant buffer indexes when, for example, the buffer is first created. The parent version of the method is first called and then the last position index is set.
      Overrides:
      initializeIndexes in class ProcessingBufferedReader
      See Also:
    • adjustIndexes

      protected void adjustIndexes(int moveDelta)
      Deprecated.
      Adjusts all indexes by a certain amount. This method calls the parent version of this method and then updates the last position index.
      Overrides:
      adjustIndexes in class ProcessingBufferedReader
      Parameters:
      moveDelta - The number of characters to move the indexes, positive for forwards, negative for backwards.
      See Also:
    • moveBuffer

      protected void moveBuffer(int sourceIndex, int destIndex, int len)
      Deprecated.
      Moves a portion of the buffer. This method updates the line and character positions before the data is moved.
      Overrides:
      moveBuffer in class ProcessingBufferedReader
      Parameters:
      sourceIndex - The index in the buffer to be moved.
      destIndex - The destination in the buffer for the data being moved.
      len - The number of characters to move.
      See Also:
    • updatePosition

      protected void updatePosition(int updateIndex)
      Deprecated.
      Updates the line and character indexes and sets the last position index to one character before the given index, which is usually the read index. This method counts the line breaks between the last position index and the read index -1 and updates the line and character indexes appropriately. This method is called by getLineIndex(), getCharIndex(), and moveBuffer().
      Parameters:
      updateIndex - The index of the character after the position should be updated to.
      See Also:
    • readChar

      public char readChar() throws IOException, ParseEOFException
      Deprecated.
      Read a single character, and throws an exception if the end of the file is reached.
      Returns:
      The character read.
      Throws:
      IOException - Thrown if a general I/O error occurs.
      ParseEOFException - Thrown if the end of the file is reached unexpectedly.
      See Also:
    • peekChar

      public char peekChar() throws IOException, ParseEOFException
      Deprecated.
      Peeks at the next character to be read, and throws an exception if there are no more characters to read. Each successive peek will return a successive character. This function is reset with every call to read(). Since every peek reads a successive character, resetPeek() should be called if it must be ensured that the next character peeked is the next character to be read. This function really reads a character, but all characters peeked will be unread before characters are read in a call to readCharacter().
      Returns:
      The next character that will be read after the character retrieved in the last read() or peek().
      Throws:
      IOException - Thrown when a general I/O error occurs.
      ParseEOFException - Thrown if the end of the file is reached unexpectedly.
      See Also:
    • peekString

      public String peekString(int len) throws IOException, ParseEOFException
      Deprecated.
      Peeks the specified number of characters, and throws an exception if the end of the file is reached. This function is reset with every call to read().
      Parameters:
      len - The number of characters to peek.
      Returns:
      A string containing the characters peeked.
      Throws:
      IOException - Thrown when a general I/O error occurs.
      ParseEOFException - Thrown if the end of the file is reached unexpectedly.
    • peekStringEOF

      public String peekStringEOF(int len) throws IOException
      Deprecated.
      Peeks the specified number of characters, but does not throw an exception if the end of the file is reached. This function is reset with every call to read().
      Parameters:
      len - The number of characters to peek.
      Returns:
      A string containing the characters peeked.
      Throws:
      IOException - Thrown when a general I/O error occurs.
    • isPeekStringEOF

      public boolean isPeekStringEOF(String string) throws IOException
      Deprecated.
      Peeks to check if the next characters are the given string, but does not throw an exception if the end of the file is reached. This function is reset with every call to read().
      Parameters:
      string - The string to be verified if it is the next characters on the file.
      Returns:
      true if the upcoming characters match the given string.
      Throws:
      IOException - Thrown when a general I/O error occurs.
    • peekExpectedChar

      public char peekExpectedChar(String expectedChars) throws IOException, ParseUnexpectedDataException, ParseEOFException
      Deprecated.
      Makes sure the next character to be read is one we expect, but that character is left to be read. This function is reset with every call to read().
      Parameters:
      expectedChars - A string with the list of allowed characters.
      Returns:
      The next character that will be read after the character retrieved in the last read() or peek().
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseUnexpectedDataException - Thrown when an unexpected character is found.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
    • peekExpectedStrings

      public int peekExpectedStrings(String[] expectedStrings) throws IOException, ParseUnexpectedDataException, ParseEOFException
      Deprecated.
      Checks to see if the string of characters waiting to be read matches any that are expected. If several strings match, the index of the first match will be returned. It is not required that peeking be reset before calling this function, but doing so will ensure that any error messages will correctly reflect the beginning search position. TODO perhaps we could fix this Performance will be increased if strings are arranged in the array from shortest to longest. TODO do this automatically, later To have this function not throw an exception of none of the strings are found, pass an empty string as the last argument in expectedStrings.
      Parameters:
      expectedStrings - An array of strings to expect.
      Returns:
      The index of the string which is waiting to be read.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseUnexpectedDataException - Thrown when an unexpected character is found.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
      See Also:
    • readExpectedStrings

      public int readExpectedStrings(String[] expectedStrings) throws IOException, ParseUnexpectedDataException, ParseEOFException
      Deprecated.
      Reads a string of characters and makes sure they match a string in a given list, returning the index of the matched string. If several strings match, the index of the first match will be returned. Resets peeking. Performance will be increased if strings are arranged in the array from shortest to longest. TODO do this automatically, later To have this function not throw an exception of none of the strings are found, pass an empty string as the last argument in expectedStrings.
      Parameters:
      expectedStrings - An array of strings to expect.
      Returns:
      The index of the string which is waiting to be read.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseUnexpectedDataException - Thrown when an unexpected character is found.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
      See Also:
    • skipChars

      public long skipChars(long n) throws IOException, ParseEOFException
      Deprecated.
      Skips the specified number of characters, and throws an exception if the end of the file is reached. Resets peeking.
      Parameters:
      n - The number of characters to skip.
      Returns:
      The number of characters actually skipped.
      Throws:
      IOException - Thrown when a general I/O error occurs.
      ParseEOFException - Thrown if the end of the file is reached unexpectedly.
    • skipChars

      public long skipChars(String skipChars) throws IOException, ParseEOFException
      Deprecated.
      Skips every character that matches the skip characters, and returns the number of characters skipped. Throws an exception if the end of the file is unexpectedly reached. Resets peeking.
      Parameters:
      skipChars - The characters which should be skipped.
      Returns:
      The number of characters skipped.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseEOFException - Thrown if the end of the file is reached unexpectedly.
    • skipCharsEOF

      public long skipCharsEOF(String skipChars) throws IOException
      Deprecated.
      Skips every character that matches the skip characters, and returns the number of characters skipped. No exception is thrown if the end of the file is reached. Resets peeking.
      Parameters:
      skipChars - The characters which should be skipped.
      Returns:
      The number of characters skipped.
      Throws:
      IOException - Thrown when an i/o error occurs.
    • readStringUntilChar

      public String readStringUntilChar(char delimiterChar) throws IOException, ParseEOFException
      Deprecated.
      Reads characters until a particular character is reached. The delimiter character reached will be the next character read.
      Parameters:
      delimiterChar - The character which indicates reading should stop.
      Returns:
      The characters up to but not including the delimiter character reached.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
    • readStringUntilCharEOF

      public String readStringUntilCharEOF(char delimiterChar) throws IOException
      Deprecated.
      Reads characters until a particular character is reached or the end of the file is reached. If a delimiter character was reached, it will be the next character read. No exception is thrown if the end of the file is reached.
      Parameters:
      delimiterChar - The character which indicates reading should stop.
      Returns:
      The characters up to but not including the delimiter character reached or the end of the file.
      Throws:
      IOException - Thrown when an i/o error occurs.
    • readStringUntilChar

      public String readStringUntilChar(String delimiterCharString) throws IOException, ParseEOFException
      Deprecated.
      Reads characters until one of the characters in delimiterCharString is reached. The delimiter character reached will be the next character read. Resets peeking. Note that this function has a limitation of the largest integer for the number of characters returned.
      Parameters:
      delimiterCharString - A list of characters which indicate reading should stop.
      Returns:
      The characters up to but not including the delimiter character reached.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
    • readStringUntilString

      public String readStringUntilString(String delimiterString) throws IOException, ParseEOFException
      Deprecated.
      Reads characters until the given string is reached. The first character of the delimiter string reached will be the next character read. Resets peeking. Note that this function has a limitation of the largest integer for the number of characters returned.
      Parameters:
      delimiterString - The string that indicates reading should stop.
      Returns:
      The characters up to but not including the delimiter string reached.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
    • readStringUntilSkipString

      public String readStringUntilSkipString(String delimiterString) throws IOException, ParseEOFException
      Deprecated.
      Reads characters up to the given string and skips the given string. Resets peeking. Note that this function has a limitation of the largest integer for the number of characters returned.
      Parameters:
      delimiterString - The string that indicates reading should stop.
      Returns:
      The characters up to but not including the delimiter string reached.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
    • readStringUntilCharEOF

      public String readStringUntilCharEOF(String delimiterCharString) throws IOException
      Deprecated.
      Reads characters until one of the characters in delimiterCharString is reached, or the end of the file is reached. If a delimiter character was reached, it will be the next character read. No exception is thrown if the end of the file is reached. Resets peeking. Note that this function has a limitation of the largest integer for the number of characters returned.
      Parameters:
      delimiterCharString - A list of characters which indicate reading should stop.
      Returns:
      The characters up to but not including the delimiter character reached or the end of the file.
      Throws:
      IOException - Thrown when an i/o error occurs.
    • readExpectedChar

      public char readExpectedChar(char expectedChar) throws IOException, ParseUnexpectedDataException, ParseEOFException
      Deprecated.
      Gets the next character from the reader, and make sure it's the character we expected; otherwise an exception is thrown.
      Parameters:
      expectedChar - The character expected.
      Returns:
      The character read.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseUnexpectedDataException - Thrown when an unexpected character is found.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
    • readExpectedChar

      public char readExpectedChar(String expectedChars) throws IOException, ParseUnexpectedDataException, ParseEOFException
      Deprecated.
      Gets the next character from the reader, and make sure it's a character we expect; otherwise an exception is thrown.
      Parameters:
      expectedChars - A string with the list of allowed characters.
      Returns:
      The character read.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseUnexpectedDataException - Thrown when an unexpected character is found.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
    • readString

      public String readString(int len) throws IOException, ParseEOFException
      Deprecated.
      Gets the specified number of characters from the reader.
      Parameters:
      len - The number of characters to read.
      Returns:
      The characters read.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseEOFException - Thrown if the end of the file is reached unexpectedly.
    • readExpectedString

      public String readExpectedString(String expectedString) throws IOException, ParseUnexpectedDataException, ParseEOFException
      Deprecated.
      Gets the a certain number of characters from the reader, and makes sure they are what we expected; otherwise an exception is thrown.
      Parameters:
      expectedString - The characters expected.
      Returns:
      The string read.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseUnexpectedDataException - Thrown when an unexpected character is found.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
    • readExpectedStringIgnoreCase

      public String readExpectedStringIgnoreCase(String expectedString) throws IOException, ParseUnexpectedDataException, ParseEOFException
      Deprecated.
      Gets the a certain number of characters from the reader, and makes sure they are what we expected, ignoring case; otherwise an exception is thrown.
      Parameters:
      expectedString - The characters expected.
      Returns:
      The string read.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseUnexpectedDataException - Thrown when an unexpected character is found.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
    • readDelimitedString

      public String readDelimitedString(String endDelimiter) throws IOException, ParseEOFException
      Deprecated.
      Reads text from an input stream that ends in a certain delimiter. The ending delimiter will be discarded.
      Parameters:
      endDelimiter - The string to expect at the end of the characters.
      Returns:
      The characters before the delimiter.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
    • readDelimitedString

      public String readDelimitedString(String startDelimiter, String endDelimiter) throws IOException, ParseUnexpectedDataException, ParseEOFException
      Deprecated.
      Reads text from an input stream that that has certain beginning and ending delimiters. The ending delimiter will be discarded.
      Parameters:
      startDelimiter - The string to expect at the first of the characters.
      endDelimiter - The string to expect at the end of the characters.
      Returns:
      The characters between the delimiters.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseUnexpectedDataException - Thrown when an unexpected character is found.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
    • readDelimitedString

      public String readDelimitedString(char startDelimiter, char endDelimiter) throws IOException, ParseUnexpectedDataException, ParseEOFException
      Deprecated.
      Reads text from an input stream that that has certain beginning and ending delimiter characters. The ending delimiter will be discarded.
      Parameters:
      startDelimiter - The character to expect at the first of the characters.
      endDelimiter - The character to expect at the end of the characters.
      Returns:
      The characters between the delimiters.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseUnexpectedDataException - Thrown when an unexpected character is found.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
    • readDelimitedStringInclusive

      public String readDelimitedStringInclusive(char startDelimiter, char endDelimiter) throws IOException, ParseUnexpectedDataException, ParseEOFException
      Deprecated.
      Reads text from an input stream that that has certain beginning and ending delimiter characters, and returns the string including the delimiters.
      Parameters:
      startDelimiter - The character to expect at the first of the characters.
      endDelimiter - The character to expect at the end of the characters.
      Returns:
      The delimiters with the character between them.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseUnexpectedDataException - Thrown when an unexpected character is found.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.
    • readDelimitedStringInclusive

      public String readDelimitedStringInclusive(String startDelimiter, String endDelimiter) throws IOException, ParseUnexpectedDataException, ParseEOFException
      Deprecated.
      Reads text from an input stream that that has certain beginning and ending delimiters, and returns the string including the delimiters.
      Parameters:
      startDelimiter - The string to expect at the first of the characters.
      endDelimiter - The string to expect at the end of the characters.
      Returns:
      The delimiters with the character between them.
      Throws:
      IOException - Thrown when an i/o error occurs.
      ParseUnexpectedDataException - Thrown when an unexpected character is found.
      ParseEOFException - Thrown when the end of the input stream is reached unexpectedly.