Class BaseJsonParser

java.lang.Object
org.apache.groovy.json.internal.BaseJsonParser
All Implemented Interfaces:
JsonParser
Direct Known Subclasses:
JsonParserCharArray, JsonParserUsingCharacterSource

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
    Modifier and Type
    Field
    Description
    protected static final int
    Character code for digit 0.
    protected static final int
    Character code for digit 1.
    protected static final int
    Character code for digit 2.
    protected static final int
    Character code for digit 3.
    protected static final int
    Character code for digit 4.
    protected static final int
    Character code for digit 5.
    protected static final int
    Character code for digit 6.
    protected static final int
    Character code for digit 7.
    protected static final int
    Character code for digit 8.
    protected static final int
    Character code for digit 9.
    protected int
    Initial buffer size used when reading character streams.
    protected String
    Charset used for byte-based input when no override is supplied.
    protected static final int
    Character code for the closing array delimiter ].
    protected static final int
    Character code for the closing object delimiter }.
    protected static final int
    Character code for the : name/value separator.
    protected static final int
    Character code for the , element separator.
    protected static final int
    Character code for the decimal point in number literals.
    protected static final int
    Character code for the JSON string delimiter ".
    protected static final int
    Character code for the JSON escape marker \.
    protected static final ConcurrentHashMap<String,String>
    Cache used when key interning is enabled.
    protected static final boolean
    Whether parsed object keys should be interned.
    protected static final int
    Uppercase exponent marker used in JSON numbers.
    protected static final int
    Lowercase exponent marker used in JSON numbers.
    protected static final int
    Character code for the minus sign in number literals.
    protected static final int
    Character code for the plus sign in exponent literals.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    Builds a readable description of a character code for parser errors.
    protected static int
    findEndQuote(char[] array, int index)
    Finds the closing quote of a JSON string while honoring escapes.
    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
    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
    Checks whether a character code is an ASCII digit.
    parse(byte[] bytes)
    Parses JSON bytes using the parser's configured charset.
    parse(byte[] bytes, String charset)
    Parses JSON bytes using the supplied charset.
    parse(File file, String charset)
    Parses JSON from a file.
    Parses JSON from a byte stream using the configured charset.
    parse(InputStream input, String charset)
    Parses JSON from a byte stream using the supplied charset.
    parse(Reader reader)
    Parses JSON from a reader.
    parse(CharSequence charSequence)
    Parses JSON from a character sequence.
    parse(String jsonString)
    Parses a JSON string.
    void
    setCharset(String charset)
    Sets the default charset used for byte and stream input.

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface groovy.json.JsonParser

    parse
  • Field Details

    • COLON

      protected static final int COLON
      Character code for the : name/value separator.
      See Also:
    • COMMA

      protected static final int COMMA
      Character code for the , element separator.
      See Also:
    • CLOSED_CURLY

      protected static final int CLOSED_CURLY
      Character code for the closing object delimiter }.
      See Also:
    • CLOSED_BRACKET

      protected static final int CLOSED_BRACKET
      Character code for the closing array delimiter ].
      See Also:
    • LETTER_E

      protected static final int LETTER_E
      Lowercase exponent marker used in JSON numbers.
      See Also:
    • LETTER_BIG_E

      protected static final int LETTER_BIG_E
      Uppercase exponent marker used in JSON numbers.
      See Also:
    • MINUS

      protected static final int MINUS
      Character code for the minus sign in number literals.
      See Also:
    • PLUS

      protected static final int PLUS
      Character code for the plus sign in exponent literals.
      See Also:
    • DECIMAL_POINT

      protected static final int DECIMAL_POINT
      Character code for the decimal point in number literals.
      See Also:
    • ALPHA_0

      protected static final int ALPHA_0
      Character code for digit 0.
      See Also:
    • ALPHA_1

      protected static final int ALPHA_1
      Character code for digit 1.
      See Also:
    • ALPHA_2

      protected static final int ALPHA_2
      Character code for digit 2.
      See Also:
    • ALPHA_3

      protected static final int ALPHA_3
      Character code for digit 3.
      See Also:
    • ALPHA_4

      protected static final int ALPHA_4
      Character code for digit 4.
      See Also:
    • ALPHA_5

      protected static final int ALPHA_5
      Character code for digit 5.
      See Also:
    • ALPHA_6

      protected static final int ALPHA_6
      Character code for digit 6.
      See Also:
    • ALPHA_7

      protected static final int ALPHA_7
      Character code for digit 7.
      See Also:
    • ALPHA_8

      protected static final int ALPHA_8
      Character code for digit 8.
      See Also:
    • ALPHA_9

      protected static final int ALPHA_9
      Character code for digit 9.
      See Also:
    • DOUBLE_QUOTE

      protected static final int DOUBLE_QUOTE
      Character code for the JSON string delimiter ".
      See Also:
    • ESCAPE

      protected static final int ESCAPE
      Character code for the JSON escape marker \.
      See Also:
    • internKeys

      protected static final boolean internKeys
      Whether parsed object keys should be interned.
    • internedKeysCache

      protected static final ConcurrentHashMap<String,String> internedKeysCache
      Cache used when key interning is enabled.
    • charset

      protected String charset
      Charset used for byte-based input when no override is supplied.
    • bufSize

      protected int bufSize
      Initial buffer size used when reading character streams.
  • Constructor Details

    • BaseJsonParser

      public BaseJsonParser()
  • Method Details

    • charDescription

      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
    • setCharset

      public void setCharset(String charset)
      Sets the default charset used for byte and stream input.
      Parameters:
      charset - charset name to use for subsequent parsing
    • parse

      public Object parse(String jsonString)
      Parses a JSON string.
      Specified by:
      parse in interface JsonParser
      Parameters:
      jsonString - JSON text to parse
      Returns:
      parsed Groovy JSON value
    • parse

      public Object parse(byte[] bytes)
      Parses JSON bytes using the parser's configured charset.
      Specified by:
      parse in interface JsonParser
      Parameters:
      bytes - JSON bytes to parse
      Returns:
      parsed Groovy JSON value
    • parse

      public Object parse(byte[] bytes, String charset)
      Parses JSON bytes using the supplied charset.
      Specified by:
      parse in interface JsonParser
      Parameters:
      bytes - JSON bytes to parse
      charset - charset name to use
      Returns:
      parsed Groovy JSON value
    • parse

      public Object parse(CharSequence charSequence)
      Parses JSON from a character sequence.
      Specified by:
      parse in interface JsonParser
      Parameters:
      charSequence - JSON text to parse
      Returns:
      parsed Groovy JSON value
    • parse

      public Object parse(Reader reader)
      Parses JSON from a reader.
      Specified by:
      parse in interface JsonParser
      Parameters:
      reader - reader supplying JSON content
      Returns:
      parsed Groovy JSON value
    • parse

      public Object parse(InputStream input)
      Parses JSON from a byte stream using the configured charset.
      Specified by:
      parse in interface JsonParser
      Parameters:
      input - input stream supplying JSON bytes
      Returns:
      parsed Groovy JSON value
    • parse

      public Object parse(InputStream input, String charset)
      Parses JSON from a byte stream using the supplied charset.
      Specified by:
      parse in interface JsonParser
      Parameters:
      input - input stream supplying JSON bytes
      charset - charset name to use
      Returns:
      parsed Groovy JSON value
    • parse

      public Object parse(File file, String charset)
      Parses JSON from a file.
      Specified by:
      parse in interface JsonParser
      Parameters:
      file - file containing JSON content
      charset - charset name to use, or the platform default when blank
      Returns:
      parsed Groovy JSON value
    • isDecimalChar

      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
    • isDelimiter

      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
    • isNumberDigit

      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
    • isDoubleQuote

      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 "
    • isEscape

      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 \
    • hasEscapeChar

      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
    • findEndQuote

      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