Package com.backblaze.b2.json
Class B2JsonReader
- java.lang.Object
-
- com.backblaze.b2.json.B2JsonReader
-
public class B2JsonReader extends java.lang.ObjectReads a stream of characters and converts them to JSON tokens.This class is NOT thread safe.
-
-
Constructor Summary
Constructors Constructor Description B2JsonReader(java.io.Reader in)Initializes a new reader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanarrayHasMoreValues()Are there more values in an array?voidfinishArray()Reads the close bracket for an array.voidfinishObject()Reads the close brace for an object.booleannextNonWhitespaceIsEof()Is the next character the given char?booleanobjectHasMoreFields()Does the object have any more fields?charpeekNextNotWhitespaceChar()Returns the next char that is not whitespace, but does not consume it.voidreadFalse()Skips over "false".voidreadNull()Skips over "null".java.lang.StringreadNumberAsString()Reads the next value, which is expected to be a number, and returns it as a string.java.lang.StringreadObjectFieldNameAndColon()Reads the name of the next object field.java.lang.StringreadString()Reads a string value, returning its contents.voidreadTrue()Skips over "true".voidskipObjectColon()voidskipValue()Skips over a value of any type.booleanstartArrayAndCheckForContents()Starts reading an array by reading the "[".booleanstartObjectAndCheckForContents()Reads the open brace for an object.
-
-
-
Method Detail
-
peekNextNotWhitespaceChar
public char peekNextNotWhitespaceChar() throws java.io.IOException, B2JsonExceptionReturns the next char that is not whitespace, but does not consume it.- Throws:
java.io.IOExceptionB2JsonException
-
skipValue
public void skipValue() throws java.io.IOException, B2JsonExceptionSkips over a value of any type.- Throws:
java.io.IOExceptionB2JsonException
-
readNumberAsString
public java.lang.String readNumberAsString() throws java.io.IOException, B2JsonExceptionReads the next value, which is expected to be a number, and returns it as a string. Throws JsonError if the next thing is not a number.- Throws:
java.io.IOExceptionB2JsonException
-
readString
public java.lang.String readString() throws B2JsonException, java.io.IOExceptionReads a string value, returning its contents.- Throws:
B2JsonExceptionjava.io.IOException
-
startObjectAndCheckForContents
public boolean startObjectAndCheckForContents() throws B2JsonException, java.io.IOExceptionReads the open brace for an object. Returns true iff the object has any fields. To read an object, use this structure: if (in.startObjectAndCheckForContents()) { do { String fieldName = on.readObjectFieldNameAndColon } while (in.objectHasMoreFields()); } in.finishObject();- Throws:
B2JsonExceptionjava.io.IOException
-
objectHasMoreFields
public boolean objectHasMoreFields() throws java.io.IOException, B2JsonExceptionDoes the object have any more fields?- Throws:
java.io.IOExceptionB2JsonException
-
nextNonWhitespaceIsEof
public boolean nextNonWhitespaceIsEof() throws java.io.IOException, B2JsonExceptionIs the next character the given char?- Throws:
java.io.IOExceptionB2JsonException
-
readObjectFieldNameAndColon
public java.lang.String readObjectFieldNameAndColon() throws B2JsonException, java.io.IOExceptionReads the name of the next object field. After calling this, you can read the value using whichever method is right for the value type.- Throws:
B2JsonExceptionjava.io.IOException
-
skipObjectColon
public void skipObjectColon() throws java.io.IOException, B2JsonException- Throws:
java.io.IOExceptionB2JsonException
-
finishObject
public void finishObject() throws B2JsonException, java.io.IOExceptionReads the close brace for an object.- Throws:
B2JsonExceptionjava.io.IOException
-
startArrayAndCheckForContents
public boolean startArrayAndCheckForContents() throws java.io.IOException, B2JsonExceptionStarts reading an array by reading the "[". Returns true iff there is anything in the array. Use this code to read an array: if (in.startArrayAndCheckForContents()) { do { // read value } while (in.arrayHasMoreValues()); } finishArray();- Throws:
java.io.IOExceptionB2JsonException
-
arrayHasMoreValues
public boolean arrayHasMoreValues() throws java.io.IOException, B2JsonExceptionAre there more values in an array?- Throws:
java.io.IOExceptionB2JsonException
-
finishArray
public void finishArray() throws B2JsonException, java.io.IOExceptionReads the close bracket for an array.- Throws:
B2JsonExceptionjava.io.IOException
-
readNull
public void readNull() throws java.io.IOException, B2JsonExceptionSkips over "null".- Throws:
java.io.IOExceptionB2JsonException
-
readFalse
public void readFalse() throws java.io.IOException, B2JsonExceptionSkips over "false".- Throws:
java.io.IOExceptionB2JsonException
-
readTrue
public void readTrue() throws java.io.IOException, B2JsonExceptionSkips over "true".- Throws:
java.io.IOExceptionB2JsonException
-
-