Top Description Constructors Methods
org.apache.avro.io

public abstract Class Decoder

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.avro.io.ParsingDecoder, org.apache.avro.io.BinaryDecoder
Imports
java.io.IOException, java.nio.ByteBuffer, org.apache.avro.util.Utf8

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).

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
DecoderFactory, Encoder

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract 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.

public abstract long
mapNext()

Processes the next block of map entries and returns the count of them.

public abstract long
readArrayStart()

Reads and returns the size of the first block of an array.

public abstract boolean
readBoolean()

Reads a boolean value written by Encoder#writeBoolean.

public abstract ByteBuffer
readBytes(ByteBuffer old)

Reads a byte-string written by Encoder#writeBytes.

public abstract double
readDouble()

Reads a double written by Encoder#writeDouble.

public abstract int

Returns:

The enumeration's value.
readEnum
()

Reads an enumeration.

public abstract void
readFixed(byte[]
The buffer to store the contents being read.
bytes
,
int
The position where the data needs to be written.
start
,
int
The size of the binary object.
length
)

Reads fixed sized binary object.

public void
readFixed(byte[] bytes)

A shorthand for readFixed(bytes, 0, bytes.length).

public abstract float
readFloat()

Reads a float written by Encoder#writeFloat.

public abstract int
readIndex()

Reads the tag of a union written by Encoder#writeIndex.

public abstract int
readInt()

Reads an integer written by Encoder#writeInt.

public abstract long
readLong()

Reads a long written by Encoder#writeLong.

public abstract long
readMapStart()

Reads and returns the size of the next block of map-entries.

public abstract void
readNull()

"Reads" a null value.

public abstract Utf8
readString(Utf8 old)

Reads a char-string written by Encoder#writeString.

public abstract String
readString()

Reads a char-string written by Encoder#writeString.

public abstract long
skipArray()

Used for quickly skipping through an array.

public abstract void
skipBytes()

Discards a byte-string written by Encoder#writeBytes.

public abstract void
skipFixed(int
The size of the binary object to be skipped.
length
)

Discards fixed sized binary object.

public abstract long
skipMap()

Support for quickly skipping through a map similar to skipArray.

public abstract void
skipString()

Discards a char-string written by Encoder#writeString.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Decoderback to summary
public Decoder()

Method Detail

arrayNextback to summary
public abstract long arrayNext() throws IOException

Processes the next block of an array and returns the number of items in the block and let's the caller read those items.

Exceptions
AvroTypeException:
When called outside of an array context
mapNextback to summary
public abstract long mapNext() throws IOException

Processes the next block of map entries and returns the count of them. Similar to arrayNext. See readMapStart for details.

Exceptions
AvroTypeException:
When called outside of a map context
readArrayStartback to summary
public abstract long readArrayStart() throws IOException

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 call 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;
    }
  }
Exceptions
AvroTypeException:
If this is a stateful reader and array is not the type of the next value to be read
readBooleanback to summary
public abstract boolean readBoolean() throws IOException

Reads a boolean value written by Encoder#writeBoolean.

Exceptions
AvroTypeException:
If this is a stateful reader and boolean is not the type of the next value to be read
readBytesback to summary
public abstract ByteBuffer readBytes(ByteBuffer old) throws IOException

Reads a byte-string written by Encoder#writeBytes. if old is not null and has sufficient capacity to take in the bytes being read, the bytes are returned in old.

Exceptions
AvroTypeException:
If this is a stateful reader and byte-string is not the type of the next value to be read
readDoubleback to summary
public abstract double readDouble() throws IOException

Reads a double written by Encoder#writeDouble.

Exceptions
AvroTypeException:
If this is a stateful reader and is not the type of the next value to be read
readEnumback to summary
public abstract int readEnum() throws IOException

Reads an enumeration.

Returns:int

The enumeration's value.

Exceptions
AvroTypeException:
If this is a stateful reader and enumeration is not the type of the next value to be read.
readFixedback to summary
public abstract void readFixed(byte[] bytes, int start, int length) throws IOException

Reads fixed sized binary object.

Parameters
bytes:byte[]

The buffer to store the contents being read.

start:int

The position where the data needs to be written.

length:int

The size of the binary object.

Exceptions
AvroTypeException:
If this is a stateful reader and fixed sized binary object is not the type of the next value to be read or the length is incorrect.
readFixedback to summary
public void readFixed(byte[] bytes) throws IOException

A shorthand for readFixed(bytes, 0, bytes.length).

Exceptions
AvroTypeException:
If this is a stateful reader and fixed sized binary object is not the type of the next value to be read or the length is incorrect.
readFloatback to summary
public abstract float readFloat() throws IOException

Reads a float written by Encoder#writeFloat.

Exceptions
AvroTypeException:
If this is a stateful reader and is not the type of the next value to be read
readIndexback to summary
public abstract int readIndex() throws IOException

Reads the tag of a union written by Encoder#writeIndex.

Exceptions
AvroTypeException:
If this is a stateful reader and union is not the type of the next value to be read
readIntback to summary
public abstract int readInt() throws IOException

Reads an integer written by Encoder#writeInt.

Exceptions
AvroTypeException:
  • If encoded value is larger than 32-bits
  • If this is a stateful reader and int is not the type of the next value to be read
readLongback to summary
public abstract long readLong() throws IOException

Reads a long written by Encoder#writeLong.

Exceptions
AvroTypeException:
If this is a stateful reader and long is not the type of the next value to be read
readMapStartback to summary
public abstract long readMapStart() throws IOException

Reads and returns the size of the next block of map-entries. Similar to 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:

Map m = 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);
  }
}
Exceptions
AvroTypeException:
If this is a stateful reader and map is not the type of the next value to be read
readNullback to summary
public abstract void readNull() throws IOException

"Reads" a null value. (Doesn't actually read anything, but advances the state of the parser if the implementation is stateful.)

Exceptions
AvroTypeException:
If this is a stateful reader and null is not the type of the next value to be read
readStringback to summary
public abstract Utf8 readString(Utf8 old) throws IOException

Reads a char-string written by Encoder#writeString.

Exceptions
AvroTypeException:
If this is a stateful reader and char-string is not the type of the next value to be read
readStringback to summary
public abstract String readString() throws IOException

Reads a char-string written by Encoder#writeString.

Exceptions
AvroTypeException:
If this is a stateful reader and char-string is not the type of the next value to be read
skipArrayback to summary
public abstract long skipArray() throws IOException

Used for quickly skipping through an array. Note you can either skip the entire array, or read the entire array (with 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.
Exceptions
AvroTypeException:
If this is a stateful reader and array is not the type of the next value to be read
skipBytesback to summary
public abstract void skipBytes() throws IOException

Discards a byte-string written by Encoder#writeBytes.

Exceptions
AvroTypeException:
If this is a stateful reader and byte-string is not the type of the next value to be read
skipFixedback to summary
public abstract void skipFixed(int length) throws IOException

Discards fixed sized binary object.

Parameters
length:int

The size of the binary object to be skipped.

Exceptions
AvroTypeException:
If this is a stateful reader and fixed sized binary object is not the type of the next value to be read or the length is incorrect.
skipMapback to summary
public abstract long skipMap() throws IOException

Support for quickly skipping through a map similar to 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
  }
}
Exceptions
AvroTypeException:
If this is a stateful reader and array is not the type of the next value to be read
skipStringback to summary
public abstract void skipString() throws IOException

Discards a char-string written by Encoder#writeString.

Exceptions
AvroTypeException:
If this is a stateful reader and char-string is not the type of the next value to be read