Package org.apache.groovy.json.internal
Class ReaderCharacterSource
java.lang.Object
org.apache.groovy.json.internal.ReaderCharacterSource
- All Implemented Interfaces:
CharacterSource
Buffered
CharacterSource implementation backed by a Reader.-
Constructor Summary
ConstructorsConstructorDescriptionReaderCharacterSource(Reader reader) Creates a buffered character source with the default read-ahead size.ReaderCharacterSource(Reader reader, int readAheadSize) Creates a buffered character source.ReaderCharacterSource(String string) Creates a character source over an in-memory string. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanconsumeIfMatch(char[] match) Consumes the supplied character sequence when it matches the current position.final intReturns the current character without advancing.errorDetails(String message) Builds an error message using the current reader context.char[]findNextChar(int match, int esc) Collects characters until the next unescaped match character.booleanReports whether the last string scan encountered an escape sequence.final booleanhasChar()Checks whether another character is available.final intlocation()Returns the current buffer index for diagnostics.final intnextChar()Advances to the next character.char[]Reads a numeric token from the current position.final intAdvances when possible and returns-1at end of input.voidAdvances past whitespace characters.
-
Constructor Details
-
ReaderCharacterSource
Creates a buffered character source.- Parameters:
reader- reader supplying charactersreadAheadSize- number of characters to read per buffer refill
-
ReaderCharacterSource
Creates a buffered character source with the default read-ahead size.- Parameters:
reader- reader supplying characters
-
ReaderCharacterSource
Creates a character source over an in-memory string.- Parameters:
string- JSON content to expose as characters
-
-
Method Details
-
nextChar
public final int nextChar()Advances to the next character.- Specified by:
nextCharin interfaceCharacterSource- Returns:
- next character code
-
currentChar
public final int currentChar()Returns the current character without advancing.- Specified by:
currentCharin interfaceCharacterSource- Returns:
- current character code
-
hasChar
public final boolean hasChar()Checks whether another character is available.- Specified by:
hasCharin interfaceCharacterSource- Returns:
truewhen more input remains
-
consumeIfMatch
public final boolean consumeIfMatch(char[] match) Consumes the supplied character sequence when it matches the current position.- Specified by:
consumeIfMatchin interfaceCharacterSource- Parameters:
match- character sequence to test- Returns:
truewhen the sequence was consumed
-
location
public final int location()Returns the current buffer index for diagnostics.- Specified by:
locationin interfaceCharacterSource- Returns:
- current character index
-
safeNextChar
public final int safeNextChar()Advances when possible and returns-1at end of input.- Specified by:
safeNextCharin interfaceCharacterSource- Returns:
- next character code or
-1when no more input remains
-
findNextChar
public char[] findNextChar(int match, int esc) Collects characters until the next unescaped match character.- Specified by:
findNextCharin interfaceCharacterSource- Parameters:
match- terminating character to search foresc- escape character that shields the following character- Returns:
- collected characters between the current position and the terminator
-
hadEscape
public boolean hadEscape()Reports whether the last string scan encountered an escape sequence.- Specified by:
hadEscapein interfaceCharacterSource- Returns:
truewhen an escape was seen
-
skipWhiteSpace
public void skipWhiteSpace()Advances past whitespace characters.- Specified by:
skipWhiteSpacein interfaceCharacterSource
-
readNumber
public char[] readNumber()Reads a numeric token from the current position.- Specified by:
readNumberin interfaceCharacterSource- Returns:
- characters that form the numeric token
-
errorDetails
Builds an error message using the current reader context.- Specified by:
errorDetailsin interfaceCharacterSource- Parameters:
message- parser-specific message- Returns:
- formatted error details
-