Class JsopTokenizer
java.lang.Object
org.apache.jackrabbit.oak.commons.json.JsopTokenizer
- All Implemented Interfaces:
JsopReader
A tokenizer for Json and Jsop strings.
-
Field Summary
Fields inherited from interface org.apache.jackrabbit.oak.commons.json.JsopReader
COMMENT, END, ERROR, FALSE, IDENTIFIER, NULL, NUMBER, STRING, TRUE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Decode a Json string.static String
Decode a quoted Json string.Get the last encoded (raw) string, including escape sequences.int
int
getPos()
getToken()
Get the last token value if the the token type was STRING or NUMBER.int
Get the token type of the last token.boolean
matches
(int type) Read a token which must match a given token type.int
read()
Read a token and return the token type.read
(int type) Read a token which must match a given token type.Read a value and return the raw Json representation.Read a string.void
Reset the position to 0, so that to restart reading.void
setPos
(int pos) toString()
-
Constructor Details
-
JsopTokenizer
-
JsopTokenizer
-
-
Method Details
-
resetReader
public void resetReader()Description copied from interface:JsopReader
Reset the position to 0, so that to restart reading.- Specified by:
resetReader
in interfaceJsopReader
-
toString
-
getTokenType
public int getTokenType()Get the token type of the last token.- Specified by:
getTokenType
in interfaceJsopReader
- Returns:
- the token type
-
getToken
Get the last token value if the the token type was STRING or NUMBER. For STRING, the text is decoded; for NUMBER, it is returned as parsed. In all other cases the result is undefined.- Specified by:
getToken
in interfaceJsopReader
- Returns:
- the token
-
getEscapedToken
Get the last encoded (raw) string, including escape sequences.- Returns:
- the encoded string
-
read
Read a token which must match a given token type.- Specified by:
read
in interfaceJsopReader
- Parameters:
type
- the token type- Returns:
- the token (a null object when reading a null value)
- Throws:
IllegalStateException
- if the token type doesn't match
-
readString
Read a string.- Specified by:
readString
in interfaceJsopReader
- Returns:
- the de-escaped string
- Throws:
IllegalStateException
- if the token type doesn't match
-
matches
public boolean matches(int type) Read a token which must match a given token type.- Specified by:
matches
in interfaceJsopReader
- Parameters:
type
- the token type- Returns:
- true if there was a match
-
read
public int read()Read a token and return the token type.- Specified by:
read
in interfaceJsopReader
- Returns:
- the token type
-
decodeQuoted
Decode a quoted Json string.- Parameters:
s
- the encoded string, with double quotes- Returns:
- the string
-
decode
Decode a Json string.- Parameters:
s
- the encoded string, without double quotes- Returns:
- the string
-
readRawValue
Read a value and return the raw Json representation. This includes arrays and nested arrays.- Specified by:
readRawValue
in interfaceJsopReader
- Returns:
- the Json representation of the value
-
getPos
public int getPos() -
getLastPos
public int getLastPos() -
setPos
public void setPos(int pos)
-