com.ibm.portal.streaming.json
Class JsonParserReader.Entry
java.lang.Object
java.io.Reader
com.ibm.portal.streaming.json.JsonParserReader.Entry
- All Implemented Interfaces:
- Streamable, Writable, java.io.Closeable, java.io.DataInput, java.lang.Readable, java.nio.channels.Channel
- Enclosing class:
- JsonParserReader
-
public abstract static class JsonParserReader.Entry
- extends java.io.Reader
- implements Writable, Streamable, java.io.DataInput, java.nio.channels.Channel
Represents an entry in this input stream. The stream representation of
the entry will close the entry but not the complete stream. Depending on
the type of the entry, the read method represent the content:
- START_MEMBER: the name of the member
- START_STRING: the value of the string
- START_NUMBER: the value of the number
- START_BOOLEAN: the value of the boolean
In all other cases the entry stream represents the empty stream.
Fields inherited from class java.io.Reader
|
lock |
Method Summary
|
abstract void |
close()
Closes this entry, subsequent attempts to read from this reader will
fail. |
abstract java.io.InputStream |
getInputStream()
Return an InputStream that reads the entry as bytes. |
abstract JsonParserReader.TYPE |
getType()
Return the type of this entry |
abstract int |
read(java.io.Writer dst)
Reads the value of the entry and copies it into the target writer. |
abstract void |
readFully(byte[] b,
int off,
int len)
Reads the number of bytes from a base64 encoded entry |
abstract java.lang.Number |
readNumber()
Reads a number or null if the entry does not contain
data. |
abstract java.lang.String |
readString()
Reads a string or null if the entry does not contain
data. |
Methods inherited from class java.io.Reader
|
mark, markSupported, read, read, read, read, ready, reset, skip |
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.ibm.utilities.streams.Writable
|
write |
Methods inherited from interface com.ibm.utilities.streams.Streamable
|
write |
Methods inherited from interface java.io.DataInput
|
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytes |
Methods inherited from interface java.nio.channels.Channel
|
isOpen |
JsonParserReader.Entry
public JsonParserReader.Entry()
close
public abstract void close()
throws java.io.IOException
- Closes this entry, subsequent attempts to read from this reader will
fail.
- Specified by:
- close in interface java.io.Closeable
- Specified by:
- close in interface java.nio.channels.Channel
- Specified by:
- close in class java.io.Reader
- Throws:
- java.io.IOException - if an I/O error has occurred
getInputStream
public abstract java.io.InputStream getInputStream()
throws java.io.IOException
- Returns an InputStream that reads the entry as bytes. The
bytes depend on the content type:
- START_MEMBER: the name of the member as a UTF8 byte sequence
- START_STRING: the value of the string as a UTF8 byte sequence
- START_NUMBER: the value of the number, either as a long number or
a IEEE 754 floating-point in big endian format.
- START_BOOLEAN: the value of the boolean, either 0 or 1
- START_NULL: the empty stream
This is compatible to how a DataOutputStream would generate a
byte sequence.
- Returns:
- the stream, null if the entry is closed
- Throws:
- java.io.IOException - if an I/O error has occurred
getType
public abstract JsonParserReader.TYPE getType()
- Returns the type of this entry
- Returns:
- the type, not null
read
public abstract int read(java.io.Writer dst)
throws java.io.IOException
- Reads the value of the entry and copies it into the target writer.
- Parameters:
- dst - target writer, not null
- Returns:
- the number of characters actually copied
- Throws:
- java.io.IOException - - if the data could not be read or copied
readFully
public abstract void readFully(byte[] b,
int off,
int len)
throws java.io.IOException
- Reads the number of bytes from a base64 encoded entry
- Specified by:
- readFully in interface java.io.DataInput
- Parameters:
- b - target byte buffer, not null
- off - index into the buffer
- len - length of the target buffer, must be >0
- Throws:
- java.io.IOException - if an I/O error has occurred
readNumber
public abstract java.lang.Number readNumber()
throws java.io.IOException,
java.lang.NumberFormatException
- Reads a number or null if the entry does not contain
data. The number type is detected automatically. Reading a number on
an entry of type START_STRING tries to parse the string to a number.
- Returns:
- the number or null if no number exists
- Throws:
- java.io.IOException - if an I/O error has occurred
- java.lang.NumberFormatException - if the number cannot be decoded from the string
readString
public abstract java.lang.String readString()
throws java.io.IOException
- Reads a string or null if the entry does not contain
data. Reading a string for a number entry converts the number into a
string.
- Returns:
- the string or null if no string exists
- Throws:
- java.io.IOException - if an I/O error has occurred