Package: org.apache.groovy.json.internal

## [Java] Class BaseJsonParser

- org.apache.groovy.json.internal.BaseJsonParser

- All Implemented Interfaces and Traits:
    JsonParser

      public abstract class BaseJsonParser
      extends Object
      implements JsonParser

  Base JSON parser. Scaled down version of Boon JsonParser with features removed that are JDK 1.7 dependent or Groovy duplicated functionality.

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `protected static int` | `ALPHA_0` | Character code for digit `0`.
    `protected static int` | `ALPHA_1` | Character code for digit `1`.
    `protected static int` | `ALPHA_2` | Character code for digit `2`.
    `protected static int` | `ALPHA_3` | Character code for digit `3`.
    `protected static int` | `ALPHA_4` | Character code for digit `4`.
    `protected static int` | `ALPHA_5` | Character code for digit `5`.
    `protected static int` | `ALPHA_6` | Character code for digit `6`.
    `protected static int` | `ALPHA_7` | Character code for digit `7`.
    `protected static int` | `ALPHA_8` | Character code for digit `8`.
    `protected static int` | `ALPHA_9` | Character code for digit `9`.
    `protected static int` | `CLOSED_BRACKET` | Character code for the closing array delimiter `]`.
    `protected static int` | `CLOSED_CURLY` | Character code for the closing object delimiter ``}.
    `protected static int` | `COLON` | Character code for the `:` name/value separator.
    `protected static int` | `COMMA` | Character code for the `,` element separator.
    `protected static int` | `DECIMAL_POINT` | Character code for the decimal point in number literals.
    `static int` | `DEFAULT_MAX_NESTING_DEPTH` | Default maximum nesting depth for arrays/objects.
    `protected static int` | `DOUBLE_QUOTE` | Character code for the JSON string delimiter `"`.
    `protected static int` | `ESCAPE` | Character code for the JSON escape marker `\`.
    `protected static int` | `LETTER_BIG_E` | Uppercase exponent marker used in JSON numbers.
    `protected static int` | `LETTER_E` | Lowercase exponent marker used in JSON numbers.
    `protected static int` | `MINUS` | Character code for the minus sign in number literals.
    `protected static int` | `PLUS` | Character code for the plus sign in exponent literals.
    `protected int` | `bufSize` | Initial buffer size used when reading character streams.
    `protected String` | `charset` | Charset used for byte-based input when no override is supplied.
    `protected static boolean` | `internKeys` | Whether parsed object keys should be interned.
    `protected static ConcurrentHashMap<String, String>` | `internedKeysCache` | Cache used when key interning is enabled.
    `protected int` | `maxNestingDepth` | Maximum nesting depth permitted for this parser.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected String` | `charDescription(int c)` Builds a readable description of a character code for parser errors.
    `` | `protected final void` | `enterNesting()` Records entry into a nested array or object, enforcing maxNestingDepth.
    `` | `protected final void` | `exitNesting()` Records exit from a nested array or object.
    `` | `protected static int` | `findEndQuote(char[] array, int index)` Finds the closing quote of a JSON string while honoring escapes.
    `` | `public int` | `getMaxNestingDepth()` Returns the maximum nesting depth permitted while parsing.
    `` | `protected static boolean` | `hasEscapeChar(char[] array, int index, int[] indexHolder)` Scans a string body until it finds an escape or the closing quote.
    `` | `protected static boolean` | `isDecimalChar(int currentChar)` Checks whether a character can appear in a decimal JSON number.
    `` | `protected static boolean` | `isDelimiter(int c)` Checks whether a character terminates the current JSON value.
    `` | `protected static final boolean` | `isDoubleQuote(int c)` Checks whether a character code is a double quote.
    `` | `protected static final boolean` | `isEscape(int c)` Checks whether a character code is the JSON escape marker.
    `` | `protected static final boolean` | `isNumberDigit(int c)` Checks whether a character code is an ASCII digit.
    `` | `public Object` | `parse(String jsonString)` Parses a JSON string.
    `` | `public Object` | `parse(byte[] bytes)` Parses JSON bytes using the parser's configured charset.
    `` | `public Object` | `parse(byte[] bytes, String charset)` Parses JSON bytes using the supplied charset.
    `` | `public Object` | `parse(CharSequence charSequence)` Parses JSON from a character sequence.
    `` | `public Object` | `parse(Reader reader)` Parses JSON from a reader.
    `` | `public Object` | `parse(InputStream input)` Parses JSON from a byte stream using the configured charset.
    `` | `public Object` | `parse(InputStream input, String charset)` Parses JSON from a byte stream using the supplied charset.
    `` | `public Object` | `parse(File file, String charset)` Parses JSON from a file.
    `` | `protected final void` | `resetNesting()` Resets the nesting-depth counter; called at the start of a top-level parse so a reused parser instance starts cleanly.
    `` | `public void` | `setCharset(String charset)` Sets the default charset used for byte and stream input.
    `` | `public void` | `setMaxNestingDepth(int maxNestingDepth)` Sets the maximum nesting depth permitted while parsing.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### protected static final int ALPHA_0

      Character code for digit `0`.

    - #### protected static final int ALPHA_1

      Character code for digit `1`.

    - #### protected static final int ALPHA_2

      Character code for digit `2`.

    - #### protected static final int ALPHA_3

      Character code for digit `3`.

    - #### protected static final int ALPHA_4

      Character code for digit `4`.

    - #### protected static final int ALPHA_5

      Character code for digit `5`.

    - #### protected static final int ALPHA_6

      Character code for digit `6`.

    - #### protected static final int ALPHA_7

      Character code for digit `7`.

    - #### protected static final int ALPHA_8

      Character code for digit `8`.

    - #### protected static final int ALPHA_9

      Character code for digit `9`.

    - #### protected static final int CLOSED_BRACKET

      Character code for the closing array delimiter `]`.

    - #### protected static final int CLOSED_CURLY

      Character code for the closing object delimiter ``}.

    - #### protected static final int COLON

      Character code for the `:` name/value separator.

    - #### protected static final int COMMA

      Character code for the `,` element separator.

    - #### protected static final int DECIMAL_POINT

      Character code for the decimal point in number literals.

    - #### public static final int DEFAULT_MAX_NESTING_DEPTH

      Default maximum nesting depth for arrays/objects. A small, crafted but deeply-nested document would otherwise drive the recursive-descent parsers into a StackOverflowError; this Groovy-level bound turns that into a clean JsonException instead. Chosen to match Jackson's `StreamReadConstraints` default so JSON is bounded consistently with the Jackson-backed YAML/TOML/CSV slurpers, while sitting far above any realistic document.

    - #### protected static final int DOUBLE_QUOTE

      Character code for the JSON string delimiter `"`.

    - #### protected static final int ESCAPE

      Character code for the JSON escape marker `\`.

    - #### protected static final int LETTER_BIG_E

      Uppercase exponent marker used in JSON numbers.

    - #### protected static final int LETTER_E

      Lowercase exponent marker used in JSON numbers.

    - #### protected static final int MINUS

      Character code for the minus sign in number literals.

    - #### protected static final int PLUS

      Character code for the plus sign in exponent literals.

    - #### protected int bufSize

      Initial buffer size used when reading character streams.

    - #### protected String charset

      Charset used for byte-based input when no override is supplied.

    - #### protected static final boolean internKeys

      Whether parsed object keys should be interned.

    - #### protected static final ConcurrentHashMap<String, String> internedKeysCache

      Cache used when key interning is enabled.

    - #### protected int maxNestingDepth

      Maximum nesting depth permitted for this parser. A value of `0` or less disables the check (restoring the previous, unbounded behaviour). Defaults to DEFAULT_MAX_NESTING_DEPTH, overridable globally via the `groovy.json.maxNestingDepth` system property.

  - ### Method Detail

    - #### protected String charDescription(int c)

      Builds a readable description of a character code for parser errors.

      Parameters:
        `c` - character code to describe
      Returns:
        human-readable description of `c`

    - #### protected final void enterNesting()

      Records entry into a nested array or object, enforcing maxNestingDepth.

      throws:
        JsonException if the configured maximum nesting depth would be exceeded

    - #### protected final void exitNesting()

      Records exit from a nested array or object.

    - #### protected static int findEndQuote(char[] array, int index)

      Finds the closing quote of a JSON string while honoring escapes.

      Parameters:
        `array` - source buffer
        `index` - index at which to start scanning
      Returns:
        index of the terminating quote or the buffer end

    - #### public int getMaxNestingDepth()

      Returns the maximum nesting depth permitted while parsing.

      Returns:
        the maximum nesting depth, or a value `<= 0` when the check is disabled

    - #### protected static boolean hasEscapeChar(char[] array, int index, int[] indexHolder)

      Scans a string body until it finds an escape or the closing quote.

      Parameters:
        `array` - source buffer
        `index` - index at which to start scanning
        `indexHolder` - single-item holder updated with the stop index
      Returns:
        `true` when an escape character is encountered before the closing quote

    - #### protected static boolean isDecimalChar(int currentChar)

      Checks whether a character can appear in a decimal JSON number.

      Parameters:
        `currentChar` - character code to test
      Returns:
        `true` for decimal-number markers

    - #### protected static boolean isDelimiter(int c)

      Checks whether a character terminates the current JSON value.

      Parameters:
        `c` - character code to test
      Returns:
        `true` when `c` is a value delimiter

    - #### protected static final boolean isDoubleQuote(int c)

      Checks whether a character code is a double quote.

      Parameters:
        `c` - character code to test
      Returns:
        `true` when `c` is `"`

    - #### protected static final boolean isEscape(int c)

      Checks whether a character code is the JSON escape marker.

      Parameters:
        `c` - character code to test
      Returns:
        `true` when `c` is `\`

    - #### protected static final boolean isNumberDigit(int c)

      Checks whether a character code is an ASCII digit.

      Parameters:
        `c` - character code to test
      Returns:
        `true` when `c` is between `0` and `9`

    - #### public Object parse(String jsonString)

      Parses a JSON string.

      Parameters:
        `jsonString` - JSON text to parse
      Returns:
        parsed Groovy JSON value

    - #### public Object parse(byte[] bytes)

      Parses JSON bytes using the parser's configured charset.

      Parameters:
        `bytes` - JSON bytes to parse
      Returns:
        parsed Groovy JSON value

    - #### public Object parse(byte[] bytes, String charset)

      Parses JSON bytes using the supplied charset.

      Parameters:
        `bytes` - JSON bytes to parse
        `charset` - charset name to use
      Returns:
        parsed Groovy JSON value

    - #### public Object parse(CharSequence charSequence)

      Parses JSON from a character sequence.

      Parameters:
        `charSequence` - JSON text to parse
      Returns:
        parsed Groovy JSON value

    - #### public Object parse(Reader reader)

      Parses JSON from a reader.

      Parameters:
        `reader` - reader supplying JSON content
      Returns:
        parsed Groovy JSON value

    - #### public Object parse(InputStream input)

      Parses JSON from a byte stream using the configured charset.

      Parameters:
        `input` - input stream supplying JSON bytes
      Returns:
        parsed Groovy JSON value

    - #### public Object parse(InputStream input, String charset)

      Parses JSON from a byte stream using the supplied charset.

      Parameters:
        `input` - input stream supplying JSON bytes
        `charset` - charset name to use
      Returns:
        parsed Groovy JSON value

    - #### public Object parse(File file, String charset)

      Parses JSON from a file.

      Parameters:
        `file` - file containing JSON content
        `charset` - charset name to use, or the platform default when blank
      Returns:
        parsed Groovy JSON value

    - #### protected final void resetNesting()

      Resets the nesting-depth counter; called at the start of a top-level parse so a reused parser instance starts cleanly.

    - #### public void setCharset(String charset)

      Sets the default charset used for byte and stream input.

      Parameters:
        `charset` - charset name to use for subsequent parsing

    - #### public void setMaxNestingDepth(int maxNestingDepth)

      Sets the maximum nesting depth permitted while parsing. A value of `0` or less disables the check.

      Parameters:
        `maxNestingDepth` - maximum number of nested arrays/objects to allow