Package org.apache.avro.io
Class JsonDecoder
java.lang.Object
org.apache.avro.io.Decoder
org.apache.avro.io.ParsingDecoder
org.apache.avro.io.JsonDecoder
- All Implemented Interfaces:
Parser.ActionHandler,SkipParser.SkipHandler
A
Decoder for Avro's JSON data encoding.
Construct using DecoderFactory.
JsonDecoder is not thread-safe.-
Field Summary
Fields inherited from class org.apache.avro.io.ParsingDecoder
parser -
Method Summary
Modifier and TypeMethodDescriptionlongProcesses the next block of an array and returns the number of items in the block and let's the caller read those items.configure(InputStream in) Reconfigures this JsonDecoder to use the InputStream provided.Reconfigures this JsonDecoder to use the String provided for input.Handle the action symbol top when the input is sought to be taken off the stack.longmapNext()Processes the next block of map entries and returns the count of them.longReads and returns the size of the first block of an array.booleanReads a boolean value written byEncoder.writeBoolean(boolean).readBytes(ByteBuffer old) Reads a byte-string written byEncoder.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.doubleReads a double written byEncoder.writeDouble(double).intreadEnum()Reads an enumeration.voidreadFixed(byte[] bytes, int start, int len) Reads fixed sized binary object.floatReads a float written byEncoder.writeFloat(float).intReads the tag of a union written byEncoder.writeIndex(int).intreadInt()Reads an integer written byEncoder.writeInt(int).longreadLong()Reads a long written byEncoder.writeLong(long).longReads and returns the size of the next block of map-entries.voidreadNull()"Reads" a null value.Reads a char-string written byEncoder.writeString(org.apache.avro.util.Utf8).readString(Utf8 old) Reads a char-string written byEncoder.writeString(org.apache.avro.util.Utf8).longUsed for quickly skipping through an array.voidDiscards a byte-string written byEncoder.writeBytes(java.nio.ByteBuffer).protected voidvoidskipFixed(int length) Discards fixed sized binary object.longskipMap()Support for quickly skipping through a map similar toDecoder.skipArray().voidDiscards a char-string written byEncoder.writeString(org.apache.avro.util.Utf8).Methods inherited from class org.apache.avro.io.ParsingDecoder
skipAction, skipTopSymbol
-
Method Details
-
configure
Reconfigures this JsonDecoder to use the InputStream provided. If the InputStream provided is null, a NullPointerException is thrown. Otherwise, this JsonDecoder will reset its state and then reconfigure its input.- Parameters:
in- The InputStream to read from. Cannot be null.- Returns:
- this JsonDecoder
- Throws:
IOExceptionNullPointerException- ifinisnull
-
configure
Reconfigures this JsonDecoder to use the String provided for input. If the String provided is null, a NullPointerException is thrown. Otherwise, this JsonDecoder will reset its state and then reconfigure its input.- Parameters:
in- The String to read from. Cannot be null.- Returns:
- this JsonDecoder
- Throws:
IOExceptionNullPointerException- ifinisnull
-
readNull
Description copied from class:Decoder"Reads" a null value. (Doesn't actually read anything, but advances the state of the parser if the implementation is stateful.)- Specified by:
readNullin classDecoder- Throws:
IOException
-
readBoolean
Description copied from class:DecoderReads a boolean value written byEncoder.writeBoolean(boolean).- Specified by:
readBooleanin classDecoder- Throws:
IOException
-
readInt
Description copied from class:DecoderReads an integer written byEncoder.writeInt(int).- Specified by:
readIntin classDecoder- Throws:
IOException
-
readLong
Description copied from class:DecoderReads a long written byEncoder.writeLong(long).- Specified by:
readLongin classDecoder- Throws:
IOException
-
readFloat
Description copied from class:DecoderReads a float written byEncoder.writeFloat(float).- Specified by:
readFloatin classDecoder- Throws:
IOException
-
readDouble
Description copied from class:DecoderReads a double written byEncoder.writeDouble(double).- Specified by:
readDoublein classDecoder- Throws:
IOException
-
readString
Description copied from class:DecoderReads a char-string written byEncoder.writeString(org.apache.avro.util.Utf8).- Specified by:
readStringin classDecoder- Throws:
IOException
-
readString
Description copied from class:DecoderReads a char-string written byEncoder.writeString(org.apache.avro.util.Utf8).- Specified by:
readStringin classDecoder- Throws:
IOException
-
skipString
Description copied from class:DecoderDiscards a char-string written byEncoder.writeString(org.apache.avro.util.Utf8).- Specified by:
skipStringin classDecoder- Throws:
IOException
-
readBytes
Description copied from class:DecoderReads a byte-string written byEncoder.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.- Specified by:
readBytesin classDecoder- Throws:
IOException
-
skipBytes
Description copied from class:DecoderDiscards a byte-string written byEncoder.writeBytes(java.nio.ByteBuffer).- Specified by:
skipBytesin classDecoder- Throws:
IOException
-
readFixed
Description copied from class:DecoderReads fixed sized binary object.- Specified by:
readFixedin classDecoder- Parameters:
bytes- 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.- Throws:
IOException
-
skipFixed
Description copied from class:DecoderDiscards fixed sized binary object.- Specified by:
skipFixedin classDecoder- Parameters:
length- The size of the binary object to be skipped.- Throws:
IOException
-
skipFixed
- Specified by:
skipFixedin classParsingDecoder- Throws:
IOException
-
readEnum
Description copied from class:DecoderReads an enumeration.- Specified by:
readEnumin classDecoder- Returns:
- The enumeration's value.
- Throws:
IOException
-
readArrayStart
Description copied from class:DecoderReads and returns the size of the first block of an array. If this method returns non-zero, then the caller should read the indicated number of items, and then callDecoder.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 invalid input: '<' i; j++) { read next element of the array; } }- Specified by:
readArrayStartin classDecoder- Throws:
IOException
-
arrayNext
Description copied from class:DecoderProcesses the next block of an array and returns the number of items in the block and let's the caller read those items.- Specified by:
arrayNextin classDecoder- Throws:
IOException
-
skipArray
Description copied from class:DecoderUsed for quickly skipping through an array. Note you can either skip the entire array, or read the entire array (withDecoder.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 invalid input: '<' 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.- Specified by:
skipArrayin classDecoder- Throws:
IOException
-
readMapStart
Description copied from class:DecoderReads and returns the size of the next block of map-entries. Similar toDecoder.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:Mapinvalid input: '<'String, Record> m = new HashMapinvalid input: '<'String, Record>(); Record reuse = new Record(); for (long i = in.readMapStart(); i != 0; i = in.readMapNext()) { for (long j = 0; j invalid input: '<' i; j++) { String key = in.readString(); reuse.intField = in.readInt(); reuse.boolField = in.readBoolean(); m.put(key, reuse); } }
- Specified by:
readMapStartin classDecoder- Throws:
IOException
-
mapNext
Description copied from class:DecoderProcesses the next block of map entries and returns the count of them. Similar toDecoder.arrayNext(). SeeDecoder.readMapStart()for details.- Specified by:
mapNextin classDecoder- Throws:
IOException
-
skipMap
Description copied from class:DecoderSupport for quickly skipping through a map similar toDecoder.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 invalid input: '<' i; j++) { in.skipString(); // Discard key in.readInt(); // Discard int-field of value in.readBoolean(); // Discard boolean-field of value } }- Specified by:
skipMapin classDecoder- Throws:
IOException
-
readIndex
Description copied from class:DecoderReads the tag of a union written byEncoder.writeIndex(int).- Specified by:
readIndexin classDecoder- Throws:
IOException
-
doAction
Description copied from interface:Parser.ActionHandlerHandle the action symbol top when the input is sought to be taken off the stack.- Specified by:
doActionin interfaceParser.ActionHandler- Parameters:
input- The input symbol from the caller of advancetop- The symbol at the top the stack.- Returns:
- null if advance() is to continue processing the stack. If not null the return value will be returned by advance().
- Throws:
IOException
-