Package org.apache.avro.io
Class Decoder
java.lang.Object
org.apache.avro.io.Decoder
- Direct Known Subclasses:
BinaryDecoder,ParsingDecoder
Low-level support for de-serializing Avro values.
This class has two types of methods. One type of methods support the reading
of leaf values (for example,
readLong() and readString(org.apache.avro.util.Utf8)).
The other type of methods support the reading of maps and arrays. These
methods are readArrayStart(), arrayNext(), and similar methods
for maps). See readArrayStart() for details on these methods.)
DecoderFactory contains Decoder construction and configuration
facilities.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract longProcesses the next block of an array and returns the number of items in the block and let's the caller read those items.abstract longmapNext()Processes the next block of map entries and returns the count of them.abstract longReads and returns the size of the first block of an array.abstract booleanReads a boolean value written byEncoder.writeBoolean(boolean).abstract ByteBufferreadBytes(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.abstract doubleReads a double written byEncoder.writeDouble(double).abstract intreadEnum()Reads an enumeration.voidreadFixed(byte[] bytes) A shorthand for readFixed(bytes, 0, bytes.length).abstract voidreadFixed(byte[] bytes, int start, int length) Reads fixed sized binary object.abstract floatReads a float written byEncoder.writeFloat(float).abstract intReads the tag of a union written byEncoder.writeIndex(int).abstract intreadInt()Reads an integer written byEncoder.writeInt(int).abstract longreadLong()Reads a long written byEncoder.writeLong(long).abstract longReads and returns the size of the next block of map-entries.abstract voidreadNull()"Reads" a null value.abstract StringReads a char-string written byEncoder.writeString(org.apache.avro.util.Utf8).abstract Utf8readString(Utf8 old) Reads a char-string written byEncoder.writeString(org.apache.avro.util.Utf8).abstract longUsed for quickly skipping through an array.abstract voidDiscards a byte-string written byEncoder.writeBytes(java.nio.ByteBuffer).abstract voidskipFixed(int length) Discards fixed sized binary object.abstract longskipMap()Support for quickly skipping through a map similar toskipArray().abstract voidDiscards a char-string written byEncoder.writeString(org.apache.avro.util.Utf8).
-
Constructor Details
-
Decoder
public Decoder()
-
-
Method Details
-
readNull
"Reads" a null value. (Doesn't actually read anything, but advances the state of the parser if the implementation is stateful.) -
readBoolean
Reads a boolean value written byEncoder.writeBoolean(boolean). -
readInt
Reads an integer written byEncoder.writeInt(int). -
readLong
Reads a long written byEncoder.writeLong(long). -
readFloat
Reads a float written byEncoder.writeFloat(float). -
readDouble
Reads a double written byEncoder.writeDouble(double). -
readString
Reads a char-string written byEncoder.writeString(org.apache.avro.util.Utf8). -
readString
Reads a char-string written byEncoder.writeString(org.apache.avro.util.Utf8). -
skipString
Discards a char-string written byEncoder.writeString(org.apache.avro.util.Utf8). -
readBytes
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. -
skipBytes
Discards a byte-string written byEncoder.writeBytes(java.nio.ByteBuffer). -
readFixed
Reads fixed sized binary object.- Parameters:
bytes- The buffer to store the contents being read.start- The position where the data needs to be written.length- The size of the binary object.
-
readFixed
A shorthand for readFixed(bytes, 0, bytes.length). -
skipFixed
Discards fixed sized binary object.- Parameters:
length- The size of the binary object to be skipped.
-
readEnum
Reads an enumeration.- Returns:
- The enumeration's value.
-
readArrayStart
Reads 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 callarrayNext()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; } } -
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. -
skipArray
Used for quickly skipping through an array. Note you can either skip the entire array, or read the entire array (withreadArrayStart()), 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. -
readMapStart
Reads and returns the size of the next block of map-entries. Similar toreadArrayStart(). 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); } }
-
mapNext
Processes the next block of map entries and returns the count of them. Similar toarrayNext(). SeereadMapStart()for details. -
skipMap
Support for quickly skipping through a map similar toskipArray(). 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 } } -
readIndex
Reads the tag of a union written byEncoder.writeIndex(int).
-