Package org.apache.groovy.json.internal
Class BaseJsonParser
java.lang.Object
org.apache.groovy.json.internal.BaseJsonParser
- All Implemented Interfaces:
JsonParser
- Direct Known Subclasses:
JsonParserCharArray,JsonParserUsingCharacterSource
Base JSON parser.
Scaled down version of Boon JsonParser with features
removed that are JDK 1.7 dependent or Groovy duplicated functionality.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intCharacter code for digit0.protected static final intCharacter code for digit1.protected static final intCharacter code for digit2.protected static final intCharacter code for digit3.protected static final intCharacter code for digit4.protected static final intCharacter code for digit5.protected static final intCharacter code for digit6.protected static final intCharacter code for digit7.protected static final intCharacter code for digit8.protected static final intCharacter code for digit9.protected intInitial buffer size used when reading character streams.protected StringCharset used for byte-based input when no override is supplied.protected static final intCharacter code for the closing array delimiter].protected static final intCharacter code for the closing object delimiter }.protected static final intCharacter code for the:name/value separator.protected static final intCharacter code for the,element separator.protected static final intCharacter code for the decimal point in number literals.protected static final intCharacter code for the JSON string delimiter".protected static final intCharacter code for the JSON escape marker\.protected static final ConcurrentHashMap<String,String> Cache used when key interning is enabled.protected static final booleanWhether parsed object keys should be interned.protected static final intUppercase exponent marker used in JSON numbers.protected static final intLowercase exponent marker used in JSON numbers.protected static final intCharacter code for the minus sign in number literals.protected static final intCharacter code for the plus sign in exponent literals. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringcharDescription(int c) Builds a readable description of a character code for parser errors.protected static intfindEndQuote(char[] array, int index) Finds the closing quote of a JSON string while honoring escapes.protected static booleanhasEscapeChar(char[] array, int index, int[] indexHolder) Scans a string body until it finds an escape or the closing quote.protected static booleanisDecimalChar(int currentChar) Checks whether a character can appear in a decimal JSON number.protected static booleanisDelimiter(int c) Checks whether a character terminates the current JSON value.protected static final booleanisDoubleQuote(int c) Checks whether a character code is a double quote.protected static final booleanisEscape(int c) Checks whether a character code is the JSON escape marker.protected static final booleanisNumberDigit(int c) Checks whether a character code is an ASCII digit.parse(byte[] bytes) Parses JSON bytes using the parser's configured charset.Parses JSON bytes using the supplied charset.Parses JSON from a file.parse(InputStream input) 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.Parses JSON from a reader.parse(CharSequence charSequence) Parses JSON from a character sequence.Parses a JSON string.voidsetCharset(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, waitMethods inherited from interface groovy.json.JsonParser
parse
-
Field Details
-
COLON
protected static final int COLONCharacter code for the:name/value separator.- See Also:
-
COMMA
protected static final int COMMACharacter code for the,element separator.- See Also:
-
CLOSED_CURLY
protected static final int CLOSED_CURLYCharacter code for the closing object delimiter }.- See Also:
-
CLOSED_BRACKET
protected static final int CLOSED_BRACKETCharacter code for the closing array delimiter].- See Also:
-
LETTER_E
protected static final int LETTER_ELowercase exponent marker used in JSON numbers.- See Also:
-
LETTER_BIG_E
protected static final int LETTER_BIG_EUppercase exponent marker used in JSON numbers.- See Also:
-
MINUS
protected static final int MINUSCharacter code for the minus sign in number literals.- See Also:
-
PLUS
protected static final int PLUSCharacter code for the plus sign in exponent literals.- See Also:
-
DECIMAL_POINT
protected static final int DECIMAL_POINTCharacter code for the decimal point in number literals.- See Also:
-
ALPHA_0
protected static final int ALPHA_0Character code for digit0.- See Also:
-
ALPHA_1
protected static final int ALPHA_1Character code for digit1.- See Also:
-
ALPHA_2
protected static final int ALPHA_2Character code for digit2.- See Also:
-
ALPHA_3
protected static final int ALPHA_3Character code for digit3.- See Also:
-
ALPHA_4
protected static final int ALPHA_4Character code for digit4.- See Also:
-
ALPHA_5
protected static final int ALPHA_5Character code for digit5.- See Also:
-
ALPHA_6
protected static final int ALPHA_6Character code for digit6.- See Also:
-
ALPHA_7
protected static final int ALPHA_7Character code for digit7.- See Also:
-
ALPHA_8
protected static final int ALPHA_8Character code for digit8.- See Also:
-
ALPHA_9
protected static final int ALPHA_9Character code for digit9.- See Also:
-
DOUBLE_QUOTE
protected static final int DOUBLE_QUOTECharacter code for the JSON string delimiter".- See Also:
-
ESCAPE
protected static final int ESCAPECharacter code for the JSON escape marker\.- See Also:
-
internKeys
protected static final boolean internKeysWhether parsed object keys should be interned. -
internedKeysCache
Cache used when key interning is enabled. -
charset
Charset used for byte-based input when no override is supplied. -
bufSize
protected int bufSizeInitial buffer size used when reading character streams.
-
-
Constructor Details
-
BaseJsonParser
public BaseJsonParser()
-
-
Method Details
-
charDescription
Builds a readable description of a character code for parser errors.- Parameters:
c- character code to describe- Returns:
- human-readable description of
c
-
setCharset
Sets the default charset used for byte and stream input.- Parameters:
charset- charset name to use for subsequent parsing
-
parse
Parses a JSON string.- Specified by:
parsein interfaceJsonParser- Parameters:
jsonString- JSON text to parse- Returns:
- parsed Groovy JSON value
-
parse
Parses JSON bytes using the parser's configured charset.- Specified by:
parsein interfaceJsonParser- Parameters:
bytes- JSON bytes to parse- Returns:
- parsed Groovy JSON value
-
parse
Parses JSON bytes using the supplied charset.- Specified by:
parsein interfaceJsonParser- Parameters:
bytes- JSON bytes to parsecharset- charset name to use- Returns:
- parsed Groovy JSON value
-
parse
Parses JSON from a character sequence.- Specified by:
parsein interfaceJsonParser- Parameters:
charSequence- JSON text to parse- Returns:
- parsed Groovy JSON value
-
parse
Parses JSON from a reader.- Specified by:
parsein interfaceJsonParser- Parameters:
reader- reader supplying JSON content- Returns:
- parsed Groovy JSON value
-
parse
Parses JSON from a byte stream using the configured charset.- Specified by:
parsein interfaceJsonParser- Parameters:
input- input stream supplying JSON bytes- Returns:
- parsed Groovy JSON value
-
parse
Parses JSON from a byte stream using the supplied charset.- Specified by:
parsein interfaceJsonParser- Parameters:
input- input stream supplying JSON bytescharset- charset name to use- Returns:
- parsed Groovy JSON value
-
parse
Parses JSON from a file.- Specified by:
parsein interfaceJsonParser- Parameters:
file- file containing JSON contentcharset- 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:
truefor 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:
truewhencis 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:
truewhencis between0and9
-
isDoubleQuote
protected static final boolean isDoubleQuote(int c) Checks whether a character code is a double quote.- Parameters:
c- character code to test- Returns:
truewhencis"
-
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:
truewhencis\
-
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 bufferindex- index at which to start scanningindexHolder- single-item holder updated with the stop index- Returns:
truewhen 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 bufferindex- index at which to start scanning- Returns:
- index of the terminating quote or the buffer end
-