Class AbstractInput
- java.lang.Object
-
- com.electronwill.nightconfig.core.io.AbstractInput
-
- All Implemented Interfaces:
CharacterInput
- Direct Known Subclasses:
ArrayInput,ReaderInput
public abstract class AbstractInput extends java.lang.Object implements CharacterInput
Abstract base class for CharacterInputs.
-
-
Constructor Summary
Constructors Constructor Description AbstractInput()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected CharsWrapperconsumeDeque(char[] array, int offset, boolean mustReadAll)Consumes the chars of the deque and put them in an array.protected abstract intdirectRead()Tries to parse the next character without taking care of the peek deque.protected abstract chardirectReadChar()Tries to parse the next character without taking care of the peek deque.intpeek()Returns the next character, without moving the reading position forward.intpeek(int n)Returns the next (n+1)th character, without moving the reading position forward.charpeekChar()Returns the next character, without moving the reading position forward.charpeekChar(int n)Returns the next (n+1)th character, without moving the reading position forward.voidpushBack(char c)Pushes a character back to the input, so that it will be returned by the next reading operation.intread()Reads the next character.charreadChar()Reads the next character, throwing an exception if there is no more available data.CharsWrapperreadCharsUntil(char[] stop)Reads all the characters until a character contained instopis reached, and returns theCharsWrapperthat contains all the characters before the stop.CharsWrapperreadUntil(char[] stop)Reads all the character until a character containde instopis reached or there is no more available data, and returns theCharsWrapperthat contains all the characters before the stop (or the end of the data).voidskipPeeks()Skips all the character that have been peeked and not parsed yet.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.electronwill.nightconfig.core.io.CharacterInput
read, readAndSkip, readCharAndSkip, readChars
-
-
-
-
Field Detail
-
deque
protected final IntDeque deque
Contains the peeked characters that haven't been read (by the read methods) yet.
-
-
Method Detail
-
directRead
protected abstract int directRead()
Tries to parse the next character without taking care of the peek deque.- Returns:
- the next character, or -1 if the EOS has been reached
-
directReadChar
protected abstract char directReadChar()
Tries to parse the next character without taking care of the peek deque.- Returns:
- the next character
- Throws:
ParsingException- if the EOS has been reached
-
read
public int read()
Description copied from interface:CharacterInputReads the next character.- Specified by:
readin interfaceCharacterInput- Returns:
- the next char, or -1 if there is no more available data
-
readChar
public char readChar()
Description copied from interface:CharacterInputReads the next character, throwing an exception if there is no more available data.- Specified by:
readCharin interfaceCharacterInput- Returns:
- the next character
-
peek
public int peek()
Description copied from interface:CharacterInputReturns the next character, without moving the reading position forward. After a call topeek(), the methodCharacterInput.read()will return the exact same character.This method behaves exactly like
peek(0)- Specified by:
peekin interfaceCharacterInput- Returns:
- the next character, or -1 if there is no more available data
-
peek
public int peek(int n)
Description copied from interface:CharacterInputReturns 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.- Specified by:
peekin interfaceCharacterInput- Parameters:
n- the position to peek- Returns:
- the next (n+1)th character
-
peekChar
public char peekChar()
Description copied from interface:CharacterInputReturns the next character, without moving the reading position forward. After a call topeek(), the methodCharacterInput.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.
- Specified by:
peekCharin interfaceCharacterInput- Returns:
- the next character
-
peekChar
public char peekChar(int n)
Description copied from interface:CharacterInputReturns 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.
- Specified by:
peekCharin interfaceCharacterInput- Parameters:
n- the position to peek- Returns:
- the next (n+1)th character
-
skipPeeks
public void skipPeeks()
Description copied from interface:CharacterInputSkips all the character that have been peeked and not parsed yet.- Specified by:
skipPeeksin interfaceCharacterInput
-
pushBack
public void pushBack(char c)
Description copied from interface:CharacterInputPushes a character back to the input, so that it will be returned by the next reading operation.- Specified by:
pushBackin interfaceCharacterInput- Parameters:
c- the character to push back
-
readUntil
public CharsWrapper readUntil(char[] stop)
Description copied from interface:CharacterInputReads all the character until a character containde instopis reached or there is no more available data, and returns theCharsWrapperthat contains all the characters before the stop (or the end of the data).- Specified by:
readUntilin interfaceCharacterInput- 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
public CharsWrapper readCharsUntil(char[] stop)
Description copied from interface:CharacterInputReads all the characters until a character contained instopis reached, and returns theCharsWrapperthat contains all the characters before the stop.- Specified by:
readCharsUntilin interfaceCharacterInput- Parameters:
stop- the characters to stop at- Returns:
- a CharsWrapper that contains all the characters parse before the stop
-
consumeDeque
protected CharsWrapper consumeDeque(char[] array, int offset, boolean mustReadAll)
Consumes the chars of the deque and put them in an array.- Parameters:
array- the destination arrayoffset- the beginning index in the arraymustReadAll-trueto throw an exception if the array can't be fulled,falseto return a CharsWrapper containing the read characters.- Returns:
- a CharsWrapper containing the read characters if the array can't be fulled, or null
-
-