Class JsopStream
java.lang.Object
org.apache.jackrabbit.oak.commons.json.JsopStream
- All Implemented Interfaces:
JsopReader
,JsopWriter
A fast Jsop writer / reader.
-
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 TypeMethodDescriptionappend
(JsopWriter w) Append all entries of the given writer.array()
Append '['.encodedValue
(String raw) Append an already encoded value.endArray()
Append ']'.Append '}'.getToken()
Get the last token value if the the token type was STRING or NUMBER.int
Get the token type of the last token.Append the key (in quotes) plus a colon.boolean
matches
(int type) Read a token which must match a given token type.newline()
Append a newline character.object()
Append '{'.int
read()
Read a token and return the token type.read
(int type) Read a token which must match a given token type.Return the row (escaped) token.Read a string.void
Reset the position to 0, so that to restart reading.void
Resets this instance, so that all data is discarded.void
setLineLength
(int i) Set the line length, after which a newline is added (to improve readability).tag
(char tag) Append a Jsop tag character.toString()
value
(boolean b) Append the boolean value 'true' or 'false'.value
(long x) Append a number.Append a string or null.
-
Constructor Details
-
JsopStream
public JsopStream()
-
-
Method Details
-
append
Description copied from interface:JsopWriter
Append all entries of the given writer.- Specified by:
append
in interfaceJsopWriter
- Parameters:
w
- the writer- Returns:
- this
-
tag
Description copied from interface:JsopWriter
Append a Jsop tag character.- Specified by:
tag
in interfaceJsopWriter
- Parameters:
tag
- the string to append- Returns:
- this
-
array
Description copied from interface:JsopWriter
Append '['. A comma is appended first if needed.- Specified by:
array
in interfaceJsopWriter
- Returns:
- this
-
encodedValue
Description copied from interface:JsopWriter
Append an already encoded value. A comma is appended first if needed.- Specified by:
encodedValue
in interfaceJsopWriter
- Parameters:
raw
- the value- Returns:
- this
-
endArray
Description copied from interface:JsopWriter
Append ']'.- Specified by:
endArray
in interfaceJsopWriter
- Returns:
- this
-
endObject
Description copied from interface:JsopWriter
Append '}'.- Specified by:
endObject
in interfaceJsopWriter
- Returns:
- this
-
key
Description copied from interface:JsopWriter
Append the key (in quotes) plus a colon. A comma is appended first if needed.- Specified by:
key
in interfaceJsopWriter
- Parameters:
key
- the key- Returns:
- this
-
newline
Description copied from interface:JsopWriter
Append a newline character.- Specified by:
newline
in interfaceJsopWriter
- Returns:
- this
-
object
Description copied from interface:JsopWriter
Append '{'. A comma is appended first if needed.- Specified by:
object
in interfaceJsopWriter
- Returns:
- this
-
value
Description copied from interface:JsopWriter
Append a string or null. A comma is appended first if needed.- Specified by:
value
in interfaceJsopWriter
- Parameters:
value
- the value- Returns:
- this
-
value
Description copied from interface:JsopWriter
Append a number. A comma is appended first if needed.- Specified by:
value
in interfaceJsopWriter
- Parameters:
x
- the value- Returns:
- this
-
value
Description copied from interface:JsopWriter
Append the boolean value 'true' or 'false'. A comma is appended first if needed.- Specified by:
value
in interfaceJsopWriter
- Parameters:
b
- the value- Returns:
- this
-
resetReader
public void resetReader()Description copied from interface:JsopReader
Reset the position to 0, so that to restart reading.- Specified by:
resetReader
in interfaceJsopReader
-
resetWriter
public void resetWriter()Description copied from interface:JsopWriter
Resets this instance, so that all data is discarded.- Specified by:
resetWriter
in interfaceJsopWriter
-
setLineLength
public void setLineLength(int i) Description copied from interface:JsopWriter
Set the line length, after which a newline is added (to improve readability).- Specified by:
setLineLength
in interfaceJsopWriter
- Parameters:
i
- the length
-
getToken
Description copied from interface:JsopReader
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
-
getTokenType
public int getTokenType()Description copied from interface:JsopReader
Get the token type of the last token. The token type is one of the known types (END, STRING, NUMBER,...), or, for Jsop tags such as "+", "-", it is the Unicode character code of the tag.- Specified by:
getTokenType
in interfaceJsopReader
- Returns:
- the token type
-
matches
public boolean matches(int type) Description copied from interface:JsopReader
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
Description copied from interface:JsopReader
Read a token which must match a given token type.- Specified by:
read
in interfaceJsopReader
- Parameters:
type
- the token type- Returns:
- the token (null when reading a null value)
-
read
public int read()Description copied from interface:JsopReader
Read a token and return the token type.- Specified by:
read
in interfaceJsopReader
- Returns:
- the token type
-
readRawValue
Description copied from interface:JsopReader
Return the row (escaped) token.- Specified by:
readRawValue
in interfaceJsopReader
- Returns:
- the escaped string (null when reading a null value)
-
readString
Description copied from interface:JsopReader
Read a string.- Specified by:
readString
in interfaceJsopReader
- Returns:
- the de-escaped string (null when reading a null value)
-
toString
-