Package org.apache.groovy.json.internal

# Class ReaderCharacterSource

java.lang.Object
org.apache.groovy.json.internal.ReaderCharacterSource

All Implemented Interfaces:
  `CharacterSource`

public class ReaderCharacterSource extends Object implements CharacterSource
Buffered `CharacterSource` implementation backed by a `Reader`.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ReaderCharacterSource(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 Type
  Method
  Description
  `final boolean`
  `consumeIfMatch(char[] match)`
  Consumes the supplied character sequence when it matches the current position.
  `final int`
  `currentChar()`
  Returns the current character without advancing.
  `String`
  `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.
  `boolean`
  `hadEscape()`
  Reports whether the last string scan encountered an escape sequence.
  `final boolean`
  `hasChar()`
  Checks whether another character is available.
  `final int`
  `location()`
  Returns the current buffer index for diagnostics.
  `final int`
  `nextChar()`
  Advances to the next character.
  `char[]`
  `readNumber()`
  Reads a numeric token from the current position.
  `final int`
  `safeNextChar()`
  Advances when possible and returns `-1` at end of input.
  `void`
  `skipWhiteSpace()`
  Advances past whitespace characters.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ReaderCharacterSource

    public ReaderCharacterSource(Reader reader, int readAheadSize)
    Creates a buffered character source.
    Parameters:
      `reader` - reader supplying characters
      `readAheadSize` - number of characters to read per buffer refill

  - ### ReaderCharacterSource

    public ReaderCharacterSource(Reader reader)
    Creates a buffered character source with the default read-ahead size.
    Parameters:
      `reader` - reader supplying characters

  - ### ReaderCharacterSource

    public ReaderCharacterSource(String string)
    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:
      `nextChar` in interface `CharacterSource`
    Returns:
      next character code

  - ### currentChar

    public final int currentChar()
    Returns the current character without advancing.
    Specified by:
      `currentChar` in interface `CharacterSource`
    Returns:
      current character code

  - ### hasChar

    public final boolean hasChar()
    Checks whether another character is available.
    Specified by:
      `hasChar` in interface `CharacterSource`
    Returns:
      `true` when more input remains

  - ### consumeIfMatch

    public final boolean consumeIfMatch(char[] match)
    Consumes the supplied character sequence when it matches the current position.
    Specified by:
      `consumeIfMatch` in interface `CharacterSource`
    Parameters:
      `match` - character sequence to test
    Returns:
      `true` when the sequence was consumed

  - ### location

    public final int location()
    Returns the current buffer index for diagnostics.
    Specified by:
      `location` in interface `CharacterSource`
    Returns:
      current character index

  - ### safeNextChar

    public final int safeNextChar()
    Advances when possible and returns `-1` at end of input.
    Specified by:
      `safeNextChar` in interface `CharacterSource`
    Returns:
      next character code or `-1` when no more input remains

  - ### findNextChar

    public char[] findNextChar(int match, int esc)
    Collects characters until the next unescaped match character.
    Specified by:
      `findNextChar` in interface `CharacterSource`
    Parameters:
      `match` - terminating character to search for
      `esc` - 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:
      `hadEscape` in interface `CharacterSource`
    Returns:
      `true` when an escape was seen

  - ### skipWhiteSpace

    public void skipWhiteSpace()
    Advances past whitespace characters.
    Specified by:
      `skipWhiteSpace` in interface `CharacterSource`

  - ### readNumber

    public char[] readNumber()
    Reads a numeric token from the current position.
    Specified by:
      `readNumber` in interface `CharacterSource`
    Returns:
      characters that form the numeric token

  - ### errorDetails

    public String errorDetails(String message)
    Builds an error message using the current reader context.
    Specified by:
      `errorDetails` in interface `CharacterSource`
    Parameters:
      `message` - parser-specific message
    Returns:
      formatted error details