org.apache.jackrabbit.oak.commons.json
Class JsopStream

java.lang.Object
  extended by org.apache.jackrabbit.oak.commons.json.JsopStream
All Implemented Interfaces:
JsopReader, JsopWriter

public class JsopStream
extends 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
JsopStream()
           
 
Method Summary
 JsopStream append(JsopWriter w)
          Append all entries of the given writer.
 JsopStream array()
          Append '['.
 JsopStream encodedValue(String raw)
          Append an already encoded value.
 JsopStream endArray()
          Append ']'.
 JsopStream endObject()
          Append '}'.
 String getToken()
          Get the last token value if the the token type was STRING or NUMBER.
 int getTokenType()
          Get the token type of the last token.
 JsopStream key(String key)
          Append the key (in quotes) plus a colon.
 boolean matches(int type)
          Read a token which must match a given token type.
 JsopStream newline()
          Append a newline character.
 JsopStream object()
          Append '{'.
 int read()
          Read a token and return the token type.
 String read(int type)
          Read a token which must match a given token type.
 String readRawValue()
          Return the row (escaped) token.
 String readString()
          Read a string.
 void resetReader()
          Reset the position to 0, so that to restart reading.
 void resetWriter()
          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).
 JsopStream tag(char tag)
          Append a Jsop tag character.
 String toString()
           
 JsopStream value(boolean b)
          Append the boolean value 'true' or 'false'.
 JsopStream value(long x)
          Append a number.
 JsopStream value(String value)
          Append a string or null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JsopStream

public JsopStream()
Method Detail

append

public JsopStream append(JsopWriter w)
Description copied from interface: JsopWriter
Append all entries of the given writer.

Specified by:
append in interface JsopWriter
Parameters:
w - the writer
Returns:
this

tag

public JsopStream tag(char tag)
Description copied from interface: JsopWriter
Append a Jsop tag character.

Specified by:
tag in interface JsopWriter
Parameters:
tag - the string to append
Returns:
this

array

public JsopStream array()
Description copied from interface: JsopWriter
Append '['. A comma is appended first if needed.

Specified by:
array in interface JsopWriter
Returns:
this

encodedValue

public JsopStream encodedValue(String raw)
Description copied from interface: JsopWriter
Append an already encoded value. A comma is appended first if needed.

Specified by:
encodedValue in interface JsopWriter
Parameters:
raw - the value
Returns:
this

endArray

public JsopStream endArray()
Description copied from interface: JsopWriter
Append ']'.

Specified by:
endArray in interface JsopWriter
Returns:
this

endObject

public JsopStream endObject()
Description copied from interface: JsopWriter
Append '}'.

Specified by:
endObject in interface JsopWriter
Returns:
this

key

public JsopStream key(String 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 interface JsopWriter
Parameters:
key - the key
Returns:
this

newline

public JsopStream newline()
Description copied from interface: JsopWriter
Append a newline character.

Specified by:
newline in interface JsopWriter
Returns:
this

object

public JsopStream object()
Description copied from interface: JsopWriter
Append '{'. A comma is appended first if needed.

Specified by:
object in interface JsopWriter
Returns:
this

value

public JsopStream value(String value)
Description copied from interface: JsopWriter
Append a string or null. A comma is appended first if needed.

Specified by:
value in interface JsopWriter
Parameters:
value - the value
Returns:
this

value

public JsopStream value(long x)
Description copied from interface: JsopWriter
Append a number. A comma is appended first if needed.

Specified by:
value in interface JsopWriter
Parameters:
x - the value
Returns:
this

value

public JsopStream value(boolean b)
Description copied from interface: JsopWriter
Append the boolean value 'true' or 'false'. A comma is appended first if needed.

Specified by:
value in interface JsopWriter
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 interface JsopReader

resetWriter

public void resetWriter()
Description copied from interface: JsopWriter
Resets this instance, so that all data is discarded.

Specified by:
resetWriter in interface JsopWriter

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 interface JsopWriter
Parameters:
i - the length

getToken

public String 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 interface JsopReader
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 interface JsopReader
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 interface JsopReader
Parameters:
type - the token type
Returns:
true if there was a match

read

public String read(int type)
Description copied from interface: JsopReader
Read a token which must match a given token type.

Specified by:
read in interface JsopReader
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 interface JsopReader
Returns:
the token type

readRawValue

public String readRawValue()
Description copied from interface: JsopReader
Return the row (escaped) token.

Specified by:
readRawValue in interface JsopReader
Returns:
the escaped string (null when reading a null value)

readString

public String readString()
Description copied from interface: JsopReader
Read a string.

Specified by:
readString in interface JsopReader
Returns:
the de-escaped string (null when reading a null value)

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012-2014 The Apache Software Foundation. All Rights Reserved.