- java.lang.Object
-
- io.github.mmm.scanner.AbstractCharStreamScanner
-
- io.github.mmm.scanner.CharReaderScanner
-
- All Implemented Interfaces:
CharStreamScanner
public class CharReaderScanner extends AbstractCharStreamScanner
Implementation ofCharStreamScannerthat adapts aReaderto read and parse textual data.
-
-
Field Summary
-
Fields inherited from class io.github.mmm.scanner.AbstractCharStreamScanner
buffer, limit, offset
-
-
Constructor Summary
Constructors Constructor Description CharReaderScanner()The constructor.CharReaderScanner(int capacity)The constructor.CharReaderScanner(int capacity, Reader reader)The constructor.CharReaderScanner(Reader reader)The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanexpectRestWithLookahead(char[] stopChars, boolean ignoreCase, Runnable appender, boolean skip)booleanexpectStrict(String expected, boolean ignoreCase)This method acts asCharStreamScanner.expect(String, boolean)but if the expected String is NOT completely present, no character isconsumedand the state of the scanner remains unchanged.
Attention:
This method requires lookahead.protected booleanfill()Fills the internalAbstractCharStreamScanner.bufferwith further data (if available from underlying source such as a stream/reader).protected booleanisEob()booleanisEos()booleanisEot()voidsetReader(Reader reader)Resets this buffer for reuse with a newReader.protected voidverifyLookahead(String substring)-
Methods inherited from class io.github.mmm.scanner.AbstractCharStreamScanner
append, builder, consumeDecimal, eot, expect, expect, forceNext, forcePeek, getAppended, hasNext, next, peek, read, readDigit, readJavaCharLiteral, readJavaStringLiteral, readLine, readLong, readUntil, readUntil, readUntil, readUntil, readUntil, readUntil, readWhile, require, require, reset, skip, skipOver, skipUntil, skipUntil, skipWhile, skipWhile, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.github.mmm.scanner.CharStreamScanner
expect, expectStrict, readDigit, readDouble, readFloat, readJavaCharLiteral, readJavaStringLiteral, readLine, readUntil, readUntil, readWhile, skipOver, skipOver, skipWhile, skipWhileAndPeek, skipWhileAndPeek
-
-
-
-
Constructor Detail
-
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.
-
-
Method Detail
-
setReader
public void setReader(Reader reader)
Resets this buffer for reuse with a newReader.- Parameters:
reader- the newReaderto set. May benullto entirely clear this buffer.
-
fill
protected boolean fill()
Description copied from class:AbstractCharStreamScannerFills the internalAbstractCharStreamScanner.bufferwith further data (if available from underlying source such as a stream/reader). If theend of the streamhas not been reached, all buffers should be filled now.- Overrides:
fillin classAbstractCharStreamScanner- Returns:
trueif data was filled,falseifEOS.
-
isEos
public boolean isEos()
- Specified by:
isEosin interfaceCharStreamScanner- Overrides:
isEosin classAbstractCharStreamScanner- Returns:
trueif the end of stream (EOS) has been reached,falseotherwise. Iftrue(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,EOThas been reached. For instances of that are not backed by an underlying stream of data (likeCharSequenceScanner) this method will always returntrue.
-
isEob
protected boolean isEob()
- Overrides:
isEobin classAbstractCharStreamScanner- Returns:
trueif end of buffer (EOB) or in other words no data is available after the currentAbstractCharStreamScanner.buffer,falseotherwise (e.g. if notEOS).
-
isEot
public boolean isEot()
- Specified by:
isEotin interfaceCharStreamScanner- Overrides:
isEotin classAbstractCharStreamScanner- Returns:
trueif end of text (EOT) is known to have been reached,falseotherwise. The returned result will be almost the same as!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 returningCharStreamScanner.hasNext()-1to signalEOSthis method may returnfalseeven though the next call ofCharStreamScanner.hasNext()may also returnfalse.
-
expectStrict
public boolean expectStrict(String expected, boolean ignoreCase)
Description copied from interface:CharStreamScannerThis method acts asCharStreamScanner.expect(String, boolean)but if the expected String is NOT completely present, no character isconsumedand the state of the scanner remains unchanged.
Attention:
This method requires lookahead. For implementations that are backed by an underlying stream (or reader) thelengthof the expectedStringshall not exceed the available lookahead size (buffer capacity given at construction time). Otherwise the method may fail.- Parameters:
expected- is the expected string.ignoreCase- - iftruethe case of the characters is ignored when compared.- Returns:
trueif theexpectedstring was successfully consumed from this scanner,falseotherwise.
-
verifyLookahead
protected void verifyLookahead(String substring)
- Overrides:
verifyLookaheadin classAbstractCharStreamScanner- 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:
expectRestWithLookaheadin classAbstractCharStreamScanner- Parameters:
stopChars- the stopStringaschar[]. IfignoreCaseistruein lower case.ignoreCase- -trueto (also) compare chars inlower case,falseotherwise.appender- an optional lambda torunbefore shifting buffers to append data.skip- -trueto update buffers and offset such that on success this scanner points after the expected stopString,falseotherwise (to not consume any character in any case).- Returns:
trueif the stopString(stopChars) was found and consumed,falseotherwise (and no data consumed).- See Also:
CharStreamScanner.readUntil(CharFilter, boolean, String, boolean),AbstractCharStreamScanner.skipOver(String, boolean, CharFilter)
-
-