Class Scanner

  • All Implemented Interfaces:
    Direct Known Subclasses:

    public class Scanner
    extends Object
    implements Iterator<String>
    A class that will take in an a Readable object and will perform scanning functions on it. This provides the ability to grab a String of characters up to a delimiter, following a pattern, or a certain length.
    This is somewhat a replacement for java's built in Scanner class, but isn't final and provides some extra methods, while excluding the next[data type] type methods.
    Jerry Vos
    See Also:
    • Method Detail

      • buffer

        protected void buffer()
      • handleIOException

        protected void handleIOException​(IOException e)
      • bufferMore

        protected void bufferMore()
      • hasNext

        public boolean hasNext()
        Returns true if there are some characters left to be returned, otherwise false.
        Specified by:
        hasNext in interface Iterator<String>
        true if there are characters left
      • getNextDelimited

        public String getNextDelimited()
        Fetches the next String of characters up to the current delimiter. If the end of the buffer is reached while trying to find the delimiter, the String of characters from the current position to the end of the stream will be returned. If we're at the end of the stream a NoSuchElementException will be thrown.
        the next String of characters up to the delimiter or end of the stream, whichever comes first
        See Also:
      • getNextPattern

        public String getNextPattern​(String pattern)
        Retrieves a sequence of characters that matches the specified pattern. This sequence must begin with the next character in the stream. If the pattern isn't matched (or isn't matched including the first character) an InputMismatchException will be thrown.
        pattern - the pattern to fetch based off of
        a String that matches the specified pattern
        See Also:
      • getNextLength

        public String getNextLength​(int length)
        Retrieves the next n characters from the stream, where n is the specified length. If there are not enough characters left an exception will be thrown.
        length - how many characters to fetch
        a string of the specified number of characters
        See Also:
      • useDelimiter

        public Pattern useDelimiter​(String delimiter)
        Sets the delimiter pattern used for next() and getNextDelimited(). This is a regular expression and will be converted to a Pattern.
        the previous delimiter pattern
        See Also:
      • ioException

        public IOException ioException()
        Returns the last IOException that occurred.
        the last IOException that occurred