Package com.backblaze.b2.json
Class B2JsonReader
- java.lang.Object
-
- com.backblaze.b2.json.B2JsonReader
-
public class B2JsonReader extends java.lang.Object
Reads 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 boolean
arrayHasMoreValues()
Are there more values in an array?void
finishArray()
Reads the close bracket for an array.void
finishObject()
Reads the close brace for an object.boolean
nextNonWhitespaceIsEof()
Is the next character the given char?boolean
objectHasMoreFields()
Does the object have any more fields?char
peekNextNotWhitespaceChar()
Returns the next char that is not whitespace, but does not consume it.void
readFalse()
Skips over "false".void
readNull()
Skips over "null".java.lang.String
readNumberAsString()
Reads the next value, which is expected to be a number, and returns it as a string.java.lang.String
readObjectFieldNameAndColon()
Reads the name of the next object field.java.lang.String
readString()
Reads a string value, returning its contents.void
readTrue()
Skips over "true".void
skipObjectColon()
void
skipValue()
Skips over a value of any type.boolean
startArrayAndCheckForContents()
Starts reading an array by reading the "[".boolean
startObjectAndCheckForContents()
Reads the open brace for an object.
-
-
-
Method Detail
-
peekNextNotWhitespaceChar
public char peekNextNotWhitespaceChar() throws java.io.IOException, B2JsonException
Returns the next char that is not whitespace, but does not consume it.- Throws:
java.io.IOException
B2JsonException
-
skipValue
public void skipValue() throws java.io.IOException, B2JsonException
Skips over a value of any type.- Throws:
java.io.IOException
B2JsonException
-
readNumberAsString
public java.lang.String readNumberAsString() throws java.io.IOException, B2JsonException
Reads 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.IOException
B2JsonException
-
readString
public java.lang.String readString() throws B2JsonException, java.io.IOException
Reads a string value, returning its contents.- Throws:
B2JsonException
java.io.IOException
-
startObjectAndCheckForContents
public boolean startObjectAndCheckForContents() throws B2JsonException, java.io.IOException
Reads 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:
B2JsonException
java.io.IOException
-
objectHasMoreFields
public boolean objectHasMoreFields() throws java.io.IOException, B2JsonException
Does the object have any more fields?- Throws:
java.io.IOException
B2JsonException
-
nextNonWhitespaceIsEof
public boolean nextNonWhitespaceIsEof() throws java.io.IOException, B2JsonException
Is the next character the given char?- Throws:
java.io.IOException
B2JsonException
-
readObjectFieldNameAndColon
public java.lang.String readObjectFieldNameAndColon() throws B2JsonException, java.io.IOException
Reads 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:
B2JsonException
java.io.IOException
-
skipObjectColon
public void skipObjectColon() throws java.io.IOException, B2JsonException
- Throws:
java.io.IOException
B2JsonException
-
finishObject
public void finishObject() throws B2JsonException, java.io.IOException
Reads the close brace for an object.- Throws:
B2JsonException
java.io.IOException
-
startArrayAndCheckForContents
public boolean startArrayAndCheckForContents() throws java.io.IOException, B2JsonException
Starts 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.IOException
B2JsonException
-
arrayHasMoreValues
public boolean arrayHasMoreValues() throws java.io.IOException, B2JsonException
Are there more values in an array?- Throws:
java.io.IOException
B2JsonException
-
finishArray
public void finishArray() throws B2JsonException, java.io.IOException
Reads the close bracket for an array.- Throws:
B2JsonException
java.io.IOException
-
readNull
public void readNull() throws java.io.IOException, B2JsonException
Skips over "null".- Throws:
java.io.IOException
B2JsonException
-
readFalse
public void readFalse() throws java.io.IOException, B2JsonException
Skips over "false".- Throws:
java.io.IOException
B2JsonException
-
readTrue
public void readTrue() throws java.io.IOException, B2JsonException
Skips over "true".- Throws:
java.io.IOException
B2JsonException
-
-