public class JsonDecoder extends ParsingDecoder implements Parser.ActionHandler
Decoder for Avro's JSON data encoding.
Construct using DecoderFactory.
JsonDecoder is not thread-safe.parser| Modifier and Type | Method and Description |
|---|---|
long |
arrayNext()
Processes the next block of an array and returns the number of items in the
block and let's the caller read those items.
|
JsonDecoder |
configure(InputStream in)
Reconfigures this JsonDecoder to use the InputStream provided.
|
JsonDecoder |
configure(String in)
Reconfigures this JsonDecoder to use the String provided for input.
|
Symbol |
doAction(Symbol input,
Symbol top)
Handle the action symbol top when the input is sought to be
taken off the stack.
|
long |
mapNext()
Processes the next block of map entries and returns the count of them.
|
long |
readArrayStart()
Reads and returns the size of the first block of an array.
|
boolean |
readBoolean()
Reads a boolean value written by
Encoder.writeBoolean(boolean). |
ByteBuffer |
readBytes(ByteBuffer old)
Reads a byte-string written by
Encoder.writeBytes(java.nio.ByteBuffer). |
double |
readDouble()
Reads a double written by
Encoder.writeDouble(double). |
int |
readEnum()
Reads an enumeration.
|
void |
readFixed(byte[] bytes,
int start,
int len)
Reads fixed sized binary object.
|
float |
readFloat()
Reads a float written by
Encoder.writeFloat(float). |
int |
readIndex()
Reads the tag of a union written by
Encoder.writeIndex(int). |
int |
readInt()
Reads an integer written by
Encoder.writeInt(int). |
long |
readLong()
Reads a long written by
Encoder.writeLong(long). |
long |
readMapStart()
Reads and returns the size of the next block of map-entries.
|
void |
readNull()
"Reads" a null value.
|
String |
readString()
Reads a char-string written by
Encoder.writeString(org.apache.avro.util.Utf8). |
Utf8 |
readString(Utf8 old)
Reads a char-string written by
Encoder.writeString(org.apache.avro.util.Utf8). |
long |
skipArray()
Used for quickly skipping through an array.
|
void |
skipBytes()
Discards a byte-string written by
Encoder.writeBytes(java.nio.ByteBuffer). |
protected void |
skipFixed() |
void |
skipFixed(int length)
Discards fixed sized binary object.
|
long |
skipMap()
Support for quickly skipping through a map similar to
Decoder.skipArray(). |
void |
skipString()
Discards a char-string written by
Encoder.writeString(org.apache.avro.util.Utf8). |
skipAction, skipTopSymbolpublic JsonDecoder configure(InputStream in) throws IOException
in - The InputStream to read from. Cannot be null.IOExceptionpublic JsonDecoder configure(String in) throws IOException
in - The String to read from. Cannot be null.IOExceptionpublic void readNull()
throws IOException
DecoderreadNull in class DecoderIOExceptionpublic boolean readBoolean()
throws IOException
DecoderEncoder.writeBoolean(boolean).readBoolean in class DecoderIOExceptionpublic int readInt()
throws IOException
DecoderEncoder.writeInt(int).readInt in class DecoderIOExceptionpublic long readLong()
throws IOException
DecoderEncoder.writeLong(long).readLong in class DecoderIOExceptionpublic float readFloat()
throws IOException
DecoderEncoder.writeFloat(float).readFloat in class DecoderIOExceptionpublic double readDouble()
throws IOException
DecoderEncoder.writeDouble(double).readDouble in class DecoderIOExceptionpublic Utf8 readString(Utf8 old) throws IOException
DecoderEncoder.writeString(org.apache.avro.util.Utf8).readString in class DecoderIOExceptionpublic String readString() throws IOException
DecoderEncoder.writeString(org.apache.avro.util.Utf8).readString in class DecoderIOExceptionpublic void skipString()
throws IOException
DecoderEncoder.writeString(org.apache.avro.util.Utf8).skipString in class DecoderIOExceptionpublic ByteBuffer readBytes(ByteBuffer old) throws IOException
DecoderEncoder.writeBytes(java.nio.ByteBuffer). if old is
not null and has sufficient capacity to take in the bytes being read, the
bytes are returned in old.readBytes in class DecoderIOExceptionpublic void skipBytes()
throws IOException
DecoderEncoder.writeBytes(java.nio.ByteBuffer).skipBytes in class DecoderIOExceptionpublic void readFixed(byte[] bytes,
int start,
int len)
throws IOException
DecoderreadFixed in class Decoderbytes - The buffer to store the contents being read.start - The position where the data needs to be written.len - The size of the binary object.IOExceptionpublic void skipFixed(int length)
throws IOException
DecoderskipFixed in class Decoderlength - The size of the binary object to be skipped.IOExceptionprotected void skipFixed()
throws IOException
skipFixed in class ParsingDecoderIOExceptionpublic int readEnum()
throws IOException
DecoderreadEnum in class DecoderIOExceptionpublic long readArrayStart()
throws IOException
DecoderDecoder.arrayNext() to find out the number of items in the next
block. The typical pattern for consuming an array looks like:
for(long i = in.readArrayStart(); i != 0; i = in.arrayNext()) {
for (long j = 0; j < i; j++) {
read next element of the array;
}
}
readArrayStart in class DecoderIOExceptionpublic long arrayNext()
throws IOException
DecoderarrayNext in class DecoderIOExceptionpublic long skipArray()
throws IOException
DecoderDecoder.readArrayStart()), but
you can't mix the two on the same array.
This method will skip through as many items as it can, all of them if
possible. It will return zero if there are no more items to skip through, or
an item count if it needs the client's help in skipping. The typical usage
pattern is:
for(long i = in.skipArray(); i != 0; i = i.skipArray()) {
for (long j = 0; j < i; j++) {
read and discard the next element of the array;
}
}
Note that this method can automatically skip through items if a byte-count is
found in the underlying data, or if a schema has been provided to the
implementation, but otherwise the client will have to skip through items
itself.skipArray in class DecoderIOExceptionpublic long readMapStart()
throws IOException
DecoderDecoder.readArrayStart().
As an example, let's say you want to read a map of records, the record
consisting of an Long field and a Boolean field. Your code would look
something like this:
Mapm = new HashMap (); Record reuse = new Record(); for (long i = in.readMapStart(); i != 0; i = in.readMapNext()) { for (long j = 0; j < i; j++) { String key = in.readString(); reuse.intField = in.readInt(); reuse.boolField = in.readBoolean(); m.put(key, reuse); } }
readMapStart in class DecoderIOExceptionpublic long mapNext()
throws IOException
DecoderDecoder.arrayNext(). See Decoder.readMapStart() for details.mapNext in class DecoderIOExceptionpublic long skipMap()
throws IOException
DecoderDecoder.skipArray().
As an example, let's say you want to skip a map of records, the record
consisting of an Long field and a Boolean field. Your code would look
something like this:
for (long i = in.skipMap(); i != 0; i = in.skipMap()) {
for (long j = 0; j < i; j++) {
in.skipString(); // Discard key
in.readInt(); // Discard int-field of value
in.readBoolean(); // Discard boolean-field of value
}
}
skipMap in class DecoderIOExceptionpublic int readIndex()
throws IOException
DecoderEncoder.writeIndex(int).readIndex in class DecoderIOExceptionpublic Symbol doAction(Symbol input, Symbol top) throws IOException
Parser.ActionHandlerdoAction in interface Parser.ActionHandlerinput - The input symbol from the caller of advancetop - The symbol at the top the stack.IOExceptionCopyright © 2009–2020 The Apache Software Foundation. All rights reserved.