Class JsonReader
- java.lang.Object
-
- com.oracle.coherence.io.json.genson.stream.JsonReader
-
- All Implemented Interfaces:
ObjectReader,Closeable,AutoCloseable
public class JsonReader extends Object implements ObjectReader
-
-
Field Summary
Fields Modifier and Type Field Description protected double_doubleValueprotected long_intValueprotected static int[]SKIPPED_TOKENS
-
Constructor Summary
Constructors Constructor Description JsonReader(Reader reader, boolean strictDoubleParse, boolean readMetadata)JsonReader(String source)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbegin(int character, JsonType type)ObjectReaderbeginArray()Starts reading an array.ObjectReaderbeginObject()Starts reading a object.voidclose()intcolumn()protected ValueTypeconsumeLiteral()Reads the next literal value into _booleanValue, _doubleValue or _intValue and returns the type of the readed literal, possible values are : INTEGER, DOUBLE, BOOLEAN, NULL.protected StringconsumeString(int token)protected ValueTypeconsumeValue()JsonTypeenclosingType()protected voidend(int character, JsonType type)ObjectReaderendArray()Ends the array.ObjectReaderendObject()Ends the object.ValueTypegetValueType()booleanhasNext()protected booleanisEOF()Map<String,Object>metadata()Return the map containing all metadata.Stringmetadata(String name)The value of a specified metadata attribute.BooleanmetadataAsBoolean(String name)LongmetadataAsLong(String name)Stringname()ValueTypenext()If we are in a object it will read the next name/value pair and if we are in an array it will read the next value (except if value is of complex type, in that case after the call to next() you must use one of beginXXX methods).ObjectReadernextObjectMetadata()Will read nexts object metadata.protected charreadEscaped()protected voidreadMetadata()protected intreadNextToken(boolean consume)introw()ObjectReaderskipValue()If the value is of complex type it will skip its content.booleanvalueAsBoolean()byte[]valueAsByteArray()doublevalueAsDouble()floatvalueAsFloat()intvalueAsInt()longvalueAsLong()shortvalueAsShort()StringvalueAsString()
-
-
-
Method Detail
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
beginArray
public ObjectReader beginArray()
Description copied from interface:ObjectReaderStarts reading an array. Arrays contain only values. CallObjectReader.endArray()when the array contains no more values.- Specified by:
beginArrayin interfaceObjectReader- Returns:
- a reference to the reader.
-
beginObject
public ObjectReader beginObject()
Description copied from interface:ObjectReaderStarts reading a object. Objects contain name/value pairs. CallObjectReader.endObject()when the objects contains no more properties.- Specified by:
beginObjectin interfaceObjectReader- Returns:
- a reference to the reader.
-
nextObjectMetadata
public ObjectReader nextObjectMetadata()
Description copied from interface:ObjectReaderWill read nexts object metadata. You can call this method as many times as you want, with the condition that you use onlyObjectReader.metadata(String)method. For example if you callObjectReader.beginObject()you wont be able to do it anymore (however you still can retrieve the metadata!).- Specified by:
nextObjectMetadatain interfaceObjectReader- Returns:
- a reference to the reader.
-
endArray
public ObjectReader endArray()
Description copied from interface:ObjectReaderEnds the array. If you were not in an array or the array contains more data, an exception will be thrown.- Specified by:
endArrayin interfaceObjectReader- Returns:
- a reference to the reader.
-
endObject
public ObjectReader endObject()
Description copied from interface:ObjectReaderEnds the object. If you were not in an object or the object contains more data, an exception will be thrown.- Specified by:
endObjectin interfaceObjectReader- Returns:
- a reference to the reader.
-
name
public String name()
- Specified by:
namein interfaceObjectReader- Returns:
- the name of current property, valid only if we are in a object and you called
ObjectReader.next()before.
-
valueAsString
public String valueAsString()
- Specified by:
valueAsStringin interfaceObjectReader- Returns:
- the current value as a String. It will try to convert the actual value to String if its not of that type.
-
valueAsInt
public int valueAsInt()
- Specified by:
valueAsIntin interfaceObjectReader- See Also:
ObjectReader.valueAsString()
-
valueAsLong
public long valueAsLong()
- Specified by:
valueAsLongin interfaceObjectReader- See Also:
ObjectReader.valueAsString()
-
valueAsDouble
public double valueAsDouble()
- Specified by:
valueAsDoublein interfaceObjectReader- See Also:
ObjectReader.valueAsString()
-
valueAsShort
public short valueAsShort()
- Specified by:
valueAsShortin interfaceObjectReader- See Also:
ObjectReader.valueAsString()
-
valueAsFloat
public float valueAsFloat()
- Specified by:
valueAsFloatin interfaceObjectReader- See Also:
ObjectReader.valueAsString()
-
valueAsBoolean
public boolean valueAsBoolean()
- Specified by:
valueAsBooleanin interfaceObjectReader- See Also:
ObjectReader.valueAsString()
-
valueAsByteArray
public byte[] valueAsByteArray()
- Specified by:
valueAsByteArrayin interfaceObjectReader- Returns:
- the incoming base64 string converted to a byte array.
-
metadata
public Map<String,Object> metadata()
Description copied from interface:ObjectReaderReturn the map containing all metadata.- Specified by:
metadatain interfaceObjectReader- Returns:
- the map containing all metadata key/value pairs.
-
metadata
public String metadata(String name)
Description copied from interface:ObjectReaderThe value of a specified metadata attribute.- Specified by:
metadatain interfaceObjectReader- Parameters:
name- the name of the metadata attribute to retrieve.- Returns:
- the value of metadata with name as key or null if there is no such metadata attribute.
-
metadataAsLong
public Long metadataAsLong(String name)
- Specified by:
metadataAsLongin interfaceObjectReader- See Also:
ObjectReader.metadata(String)
-
metadataAsBoolean
public Boolean metadataAsBoolean(String name)
- Specified by:
metadataAsBooleanin interfaceObjectReader- See Also:
ObjectReader.metadata(String)
-
getValueType
public ValueType getValueType()
- Specified by:
getValueTypein interfaceObjectReader- Returns:
- The type of current value.
- See Also:
ValueType
-
skipValue
public ObjectReader skipValue()
Description copied from interface:ObjectReaderIf the value is of complex type it will skip its content.- Specified by:
skipValuein interfaceObjectReader- Returns:
- a reference to the reader.
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfaceObjectReader- Returns:
- true if there is a next property or value, false otherwise.
-
next
public ValueType next()
Description copied from interface:ObjectReaderIf we are in a object it will read the next name/value pair and if we are in an array it will read the next value (except if value is of complex type, in that case after the call to next() you must use one of beginXXX methods).- Specified by:
nextin interfaceObjectReader- Returns:
- the type of the value, see
ValueTypefor possible types.
-
enclosingType
public JsonType enclosingType()
- Specified by:
enclosingTypein interfaceObjectReader
-
consumeValue
protected final ValueType consumeValue()
-
readMetadata
protected final void readMetadata()
-
begin
protected final void begin(int character, JsonType type)
-
end
protected final void end(int character, JsonType type)
-
consumeString
protected final String consumeString(int token)
-
consumeLiteral
protected final ValueType consumeLiteral()
Reads the next literal value into _booleanValue, _doubleValue or _intValue and returns the type of the readed literal, possible values are : INTEGER, DOUBLE, BOOLEAN, NULL. When calling this method the _cursor must be positioned on the first character of the value in the _buffer, you can ensure that by callingreadNextToken(boolean).
-
readNextToken
protected final int readNextToken(boolean consume)
-
readEscaped
protected final char readEscaped()
-
isEOF
protected final boolean isEOF()
-
column
public int column()
- Specified by:
columnin interfaceObjectReader
-
row
public int row()
- Specified by:
rowin interfaceObjectReader
-
-