Class JsopStream
- java.lang.Object
-
- org.apache.jackrabbit.oak.commons.json.JsopStream
-
- All Implemented Interfaces:
JsopReader,JsopWriter
public class JsopStream extends java.lang.Object implements 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 Constructor Description JsopStream()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsopStreamappend(JsopWriter w)Append all entries of the given writer.JsopStreamarray()Append '['.JsopStreamencodedValue(java.lang.String raw)Append an already encoded value.JsopStreamendArray()Append ']'.JsopStreamendObject()Append '}'.java.lang.StringgetToken()Get the last token value if the the token type was STRING or NUMBER.intgetTokenType()Get the token type of the last token.JsopStreamkey(java.lang.String key)Append the key (in quotes) plus a colon.booleanmatches(int type)Read a token which must match a given token type.JsopStreamnewline()Append a newline character.JsopStreamobject()Append '{'.intread()Read a token and return the token type.java.lang.Stringread(int type)Read a token which must match a given token type.java.lang.StringreadRawValue()Return the row (escaped) token.java.lang.StringreadString()Read a string.voidresetReader()Reset the position to 0, so that to restart reading.voidresetWriter()Resets this instance, so that all data is discarded.voidsetLineLength(int i)Set the line length, after which a newline is added (to improve readability).JsopStreamtag(char tag)Append a Jsop tag character.java.lang.StringtoString()JsopStreamvalue(boolean b)Append the boolean value 'true' or 'false'.JsopStreamvalue(long x)Append a number.JsopStreamvalue(java.lang.String value)Append a string or null.
-
-
-
Method Detail
-
append
public JsopStream append(JsopWriter w)
Description copied from interface:JsopWriterAppend all entries of the given writer.- Specified by:
appendin interfaceJsopWriter- Parameters:
w- the writer- Returns:
- this
-
tag
public JsopStream tag(char tag)
Description copied from interface:JsopWriterAppend a Jsop tag character.- Specified by:
tagin interfaceJsopWriter- Parameters:
tag- the string to append- Returns:
- this
-
array
public JsopStream array()
Description copied from interface:JsopWriterAppend '['. A comma is appended first if needed.- Specified by:
arrayin interfaceJsopWriter- Returns:
- this
-
encodedValue
public JsopStream encodedValue(java.lang.String raw)
Description copied from interface:JsopWriterAppend an already encoded value. A comma is appended first if needed.- Specified by:
encodedValuein interfaceJsopWriter- Parameters:
raw- the value- Returns:
- this
-
endArray
public JsopStream endArray()
Description copied from interface:JsopWriterAppend ']'.- Specified by:
endArrayin interfaceJsopWriter- Returns:
- this
-
endObject
public JsopStream endObject()
Description copied from interface:JsopWriterAppend '}'.- Specified by:
endObjectin interfaceJsopWriter- Returns:
- this
-
key
public JsopStream key(java.lang.String key)
Description copied from interface:JsopWriterAppend the key (in quotes) plus a colon. A comma is appended first if needed.- Specified by:
keyin interfaceJsopWriter- Parameters:
key- the key- Returns:
- this
-
newline
public JsopStream newline()
Description copied from interface:JsopWriterAppend a newline character.- Specified by:
newlinein interfaceJsopWriter- Returns:
- this
-
object
public JsopStream object()
Description copied from interface:JsopWriterAppend '{'. A comma is appended first if needed.- Specified by:
objectin interfaceJsopWriter- Returns:
- this
-
value
public JsopStream value(java.lang.String value)
Description copied from interface:JsopWriterAppend a string or null. A comma is appended first if needed.- Specified by:
valuein interfaceJsopWriter- Parameters:
value- the value- Returns:
- this
-
value
public JsopStream value(long x)
Description copied from interface:JsopWriterAppend a number. A comma is appended first if needed.- Specified by:
valuein interfaceJsopWriter- Parameters:
x- the value- Returns:
- this
-
value
public JsopStream value(boolean b)
Description copied from interface:JsopWriterAppend the boolean value 'true' or 'false'. A comma is appended first if needed.- Specified by:
valuein interfaceJsopWriter- Parameters:
b- the value- Returns:
- this
-
resetReader
public void resetReader()
Description copied from interface:JsopReaderReset the position to 0, so that to restart reading.- Specified by:
resetReaderin interfaceJsopReader
-
resetWriter
public void resetWriter()
Description copied from interface:JsopWriterResets this instance, so that all data is discarded.- Specified by:
resetWriterin interfaceJsopWriter
-
setLineLength
public void setLineLength(int i)
Description copied from interface:JsopWriterSet the line length, after which a newline is added (to improve readability).- Specified by:
setLineLengthin interfaceJsopWriter- Parameters:
i- the length
-
getToken
public java.lang.String getToken()
Description copied from interface:JsopReaderGet 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:
getTokenin interfaceJsopReader- Returns:
- the token
-
getTokenType
public int getTokenType()
Description copied from interface:JsopReaderGet 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:
getTokenTypein interfaceJsopReader- Returns:
- the token type
-
matches
public boolean matches(int type)
Description copied from interface:JsopReaderRead a token which must match a given token type.- Specified by:
matchesin interfaceJsopReader- Parameters:
type- the token type- Returns:
- true if there was a match
-
read
public java.lang.String read(int type)
Description copied from interface:JsopReaderRead a token which must match a given token type.- Specified by:
readin interfaceJsopReader- Parameters:
type- the token type- Returns:
- the token (null when reading a null value)
-
read
public int read()
Description copied from interface:JsopReaderRead a token and return the token type.- Specified by:
readin interfaceJsopReader- Returns:
- the token type
-
readRawValue
public java.lang.String readRawValue()
Description copied from interface:JsopReaderReturn the row (escaped) token.- Specified by:
readRawValuein interfaceJsopReader- Returns:
- the escaped string (null when reading a null value)
-
readString
public java.lang.String readString()
Description copied from interface:JsopReaderRead a string.- Specified by:
readStringin interfaceJsopReader- Returns:
- the de-escaped string (null when reading a null value)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-