Class CharReaderScanner

java.lang.Object
io.github.mmm.scanner.AbstractCharStreamScanner
io.github.mmm.scanner.CharReaderScanner
All Implemented Interfaces:
CharStreamScanner

public class CharReaderScanner extends AbstractCharStreamScanner
Implementation of CharStreamScanner that adapts a Reader to read and parse textual data.
  • Field Details

  • Constructor Details

    • CharReaderScanner

      public CharReaderScanner()
      The constructor.
    • CharReaderScanner

      public CharReaderScanner(Reader reader)
      The constructor.
      Parameters:
      reader - the (initial) Reader.
    • CharReaderScanner

      public CharReaderScanner(int capacity)
      The constructor.
      Parameters:
      capacity - the buffer capacity.
    • CharReaderScanner

      public CharReaderScanner(int capacity, Reader reader)
      The constructor.
      Parameters:
      capacity - the buffer capacity.
      reader - the (initial) Reader.
  • Method Details

    • getPosition

      public int getPosition()
      Returns:
      the position in the sequence to scan or in other words the number of bytes that have been read. Will initially be 0. Please note that this API is designed for scanning textual content (for parsers). Therefore we consider 2.1 terabyte as a suitable limit.
    • setReader

      public void setReader(Reader reader)
      Resets this buffer for reuse with a new Reader.
      This will also reset the position.
      Parameters:
      reader - the new Reader to set. May be null to entirely clear this buffer.
    • fill

      protected boolean fill()
      Description copied from class: AbstractCharStreamScanner
      Fills the internal AbstractCharStreamScanner.buffer with further data (if available from underlying source such as a stream/reader). If the end of the stream has not been reached, all buffers should be filled now.
      Overrides:
      fill in class AbstractCharStreamScanner
      Returns:
      true if data was filled, false if EOS.
    • isEos

      public boolean isEos()
      Overrides:
      isEos in class AbstractCharStreamScanner
      Returns:
      true if the end of stream (EOS) has been reached, false otherwise. If true (EOS) the internal buffer contains the entire rest of the data to scan in memory. If then also all data is consumed from the buffer, EOT has been reached. For instances of that are not backed by an underlying stream of data (like CharSequenceScanner) this method will always return true.
    • isEob

      protected boolean isEob()
      Overrides:
      isEob in class AbstractCharStreamScanner
      Returns:
      true if end of buffer (EOB) or in other words no data is available after the current AbstractCharStreamScanner.buffer, false otherwise (e.g. if not EOS).
    • isEot

      public boolean isEot()
      Description copied from class: AbstractCharStreamScanner
      ATTENTION:
      Overrides:
      isEot in class AbstractCharStreamScanner
      Returns:
      true if end of text (EOT) is known to have been reached, false otherwise. The returned result will be almost the same as !AbstractCharStreamScanner.hasNext() but this method will not modify the state of this scanner (read additional data, modify buffers, etc.). However, if the underlying stream is already consumed without returning -1 to signal EOS this method may return false even though the next call of AbstractCharStreamScanner.hasNext() may also return false.
    • expectStrict

      public boolean expectStrict(String expected, boolean ignoreCase, boolean lookahead)
      Description copied from interface: CharStreamScanner
      This method acts as CharStreamScanner.expectUnsafe(String, boolean) but if the expected String is NOT completely present, no character is consumed and the state of the scanner remains unchanged.
      Attention:
      This method requires lookahead. For implementations that are backed by an underlying stream (or reader) the length of the expected String shall not exceed the available lookahead size (buffer capacity given at construction time). Otherwise the method may fail.
      Parameters:
      expected - is the expected string.
      ignoreCase - - if true the case of the characters is ignored when compared.
      lookahead - - if true the state of the scanner remains unchanged even if the expected String has been found, false otherwise.
      Returns:
      true if the expected string was successfully consumed from this scanner, false otherwise.
    • verifyLookahead

      protected void verifyLookahead(String substring)
      Overrides:
      verifyLookahead in class AbstractCharStreamScanner
      Parameters:
      substring - the substring to match without consuming what requires a lookahead.
    • expectRestWithLookahead

      protected boolean expectRestWithLookahead(char[] stopChars, boolean ignoreCase, Runnable appender, boolean skip)
      Specified by:
      expectRestWithLookahead in class AbstractCharStreamScanner
      Parameters:
      stopChars - the stop String as char[]. If ignoreCase is true in lower case.
      ignoreCase - - true to (also) compare chars in lower case, false otherwise.
      appender - an optional lambda to run before shifting buffers to append data.
      skip - - true to update buffers and offset such that on success this scanner points after the expected stop String, false otherwise (to not consume any character in any case).
      Returns:
      true if the stop String (stopChars) was found and consumed, false otherwise (and no data consumed).
      See Also: