Interface CharacterInput

  • All Known Implementing Classes:
    AbstractInput, ArrayInput, ReaderInput

    public interface CharacterInput
    Interface for sources of characters.

    The readXXX() and peek() methods do not throw any exception when the end of the available data is reached, but return special non-null values.

    The readCharXXX() and peekChar() methods do throw a RuntimeException when the end of the available data is reached.

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      int peek()
      Returns the next character, without moving the reading position forward.
      int peek​(int n)
      Returns the next (n+1)th character, without moving the reading position forward.
      char peekChar()
      Returns the next character, without moving the reading position forward.
      char peekChar​(int n)
      Returns the next (n+1)th character, without moving the reading position forward.
      void pushBack​(char c)
      Pushes a character back to the input, so that it will be returned by the next reading operation.
      int read()
      Reads the next character.
      default CharsWrapper read​(int n)
      Reads the next n characters, if possible.
      default int readAndSkip​(char[] toSkip)
      Reads the next characters, skipping some characters.
      char readChar()
      Reads the next character, throwing an exception if there is no more available data.
      default char readCharAndSkip​(char[] toSkip)
      Reads the next characters, skipping some characters.
      default CharsWrapper readChars​(int n)
      Reads the next n characters.
      CharsWrapper readCharsUntil​(char[] stop)
      Reads all the characters until a character contained in stop is reached, and returns the CharsWrapper that contains all the characters before the stop.
      CharsWrapper readUntil​(char[] stop)
      Reads all the character until a character containde in stop is reached or there is no more available data, and returns the CharsWrapper that contains all the characters before the stop (or the end of the data).
      void skipPeeks()
      Skips all the character that have been peeked and not parsed yet.
    • Method Detail

      • read

        int read()
        Reads the next character.
        Returns:
        the next char, or -1 if there is no more available data
      • readChar

        char readChar()
        Reads the next character, throwing an exception if there is no more available data.
        Returns:
        the next character
        Throws:
        ParsingException - if there is no more available data
      • readAndSkip

        default int readAndSkip​(char[] toSkip)
        Reads the next characters, skipping some characters. Returns the next character that is not in the given array.
        Parameters:
        toSkip - the characters to skip
        Returns:
        the next character that is not in toSkip, or -1 if there is no more available data
      • readCharAndSkip

        default char readCharAndSkip​(char[] toSkip)
        Reads the next characters, skipping some characters. Returns the next character that is not in the given array. This method throws an exception if there is no more available data.
        Parameters:
        toSkip - the characters to skip
        Returns:
        the next character that is not in toSkip
        Throws:
        ParsingException - if there is no more available data
      • read

        default CharsWrapper read​(int n)
        Reads the next n characters, if possible. If there are less than n available characters, return all the remaining characters.
        Parameters:
        n - the number of characters to parse
        Returns:
        an array containing at most n characters, not null
      • readChars

        default CharsWrapper readChars​(int n)
        Reads the next n characters. If there isn't n available characters, this method throws an exception.
        Parameters:
        n - the number of characters to parse
        Returns:
        an array containing the next n characters, not null
        Throws:
        ParsingException - if there is no more available data
      • readUntil

        CharsWrapper readUntil​(char[] stop)
        Reads all the character until a character containde in stop is reached or there is no more available data, and returns the CharsWrapper that contains all the characters before the stop (or the end of the data).
        Parameters:
        stop - the characters to stop at
        Returns:
        a CharsWrapper that contains all the characters parse before the stop (or the end of the data), not null
      • readCharsUntil

        CharsWrapper readCharsUntil​(char[] stop)
        Reads all the characters until a character contained in stop is reached, and returns the CharsWrapper that contains all the characters before the stop.
        Parameters:
        stop - the characters to stop at
        Returns:
        a CharsWrapper that contains all the characters parse before the stop
        Throws:
        ParsingException - if the end of the data is reached before a stop character
      • peek

        int peek()
        Returns the next character, without moving the reading position forward. After a call to peek(), the method read() will return the exact same character.

        This method behaves exactly like peek(0)

        Returns:
        the next character, or -1 if there is no more available data
      • peek

        int peek​(int n)
        Returns the next (n+1)th character, without moving the reading position forward. The next character is n=0, then it's n=1 and so on.
        Parameters:
        n - the position to peek
        Returns:
        the next (n+1)th character
        Throws:
        ParsingException - if there is no (n+1)th character
      • peekChar

        char peekChar()
        Returns the next character, without moving the reading position forward. After a call to peek(), the method read() will return the exact same character.

        This method behaves exactly like peekChar(0)

        This method throws an exception if there is no more available data.

        Returns:
        the next character
        Throws:
        ParsingException - if there is no more available data
      • peekChar

        char peekChar​(int n)
        Returns the next (n+1)th character, without moving the reading position forward. The next character is n=0, then it's n=1 and so on.

        This method throws an exception if there is no more available data.

        Parameters:
        n - the position to peek
        Returns:
        the next (n+1)th character
        Throws:
        ParsingException - if there is no (n+1)th character
      • skipPeeks

        void skipPeeks()
        Skips all the character that have been peeked and not parsed yet.
      • pushBack

        void pushBack​(char c)
        Pushes a character back to the input, so that it will be returned by the next reading operation.
        Parameters:
        c - the character to push back