Top Description Inners Fields Constructors Methods
org.apache.avro.io

public Class BinaryDecoder

extends Decoder
Class Inheritance
Known Direct Subclasses
org.apache.avro.io.DirectBinaryDecoder
Imports
java.io.EOFException, .IOException, .InputStream, java.nio.Buffer, .ByteBuffer, java.util.Arrays, org.apache.avro.AvroRuntimeException, .InvalidNumberEncodingException, .SystemLimitException, org.apache.avro.util.Utf8

An Decoder for binary-format data.

Instances are created using DecoderFactory.

This class may read-ahead and buffer bytes from the source beyond what is required to serve its read methods. The number of unused bytes in the buffer can be accessed by inputStream().remaining(), if the BinaryDecoder is not 'direct'.

See Also
Encoder, SystemLimitException

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
BinaryDecoder.BufferAccessor

BufferAccessor is used by BinaryEncoder to enable ByteSources and the InputStream returned by BinaryDecoder#inputStream to access the BinaryEncoder's buffer.

private static class
BinaryDecoder.ByteArrayByteSource

This byte source is special.

pack-priv abstract static class
BinaryDecoder.ByteSource

ByteSource abstracts the source of data from the core workings of BinaryDecoder.

private static class

Field Summary

Modifier and TypeField and Description
private byte[]
private long
collectionCount

When reading a collection (MAP or ARRAY), this keeps track of the number of elements to ensure that the SystemLimitException#checkMaxCollectionLength constraint is respected.

private int
private int
private int
private final Utf8
private BinaryDecoder.ByteSource

Constructor Summary

AccessConstructor and Description
protected
BinaryDecoder()

protected constructor for child classes

pack-priv
BinaryDecoder(InputStream in, int bufferSize)

pack-priv
BinaryDecoder(byte[] data, int offset, int length)

Method Summary

Modifier and TypeMethod and Description
public long
arrayNext()

Implements abstract org.apache.avro.io.Decoder.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.
pack-priv void
pack-priv BinaryDecoder
configure(InputStream in, int bufferSize)

pack-priv BinaryDecoder
configure(byte[] data, int offset, int length)

private void
configureSource(int bufferSize, BinaryDecoder.ByteSource source)

Initializes this decoder with a new ByteSource.

protected void
doReadBytes(byte[] bytes, int start, int length)

Reads length bytes into bytes starting at start.

protected long
doReadItemCount()

Returns the number of items to follow in the current array or map.

protected void
doSkipBytes(long length)

private long

Returns:

Zero if there are no more items to skip and end of array/map is reached. Positive number if some items are found that cannot be skipped and the client needs to skip them individually.
doSkipItems
()

Reads the count of items in the current array or map and skip those items, if possible.

private void
ensureBounds(int num)

Ensures that buf[pos + num - 1] is not out of the buffer array bounds.

pack-priv byte[]
pack-priv int
pack-priv int
private long
public InputStream
inputStream()

Returns an java.io.InputStream that is aware of any buffering that may occur in this BinaryDecoder.

public boolean
isEnd()

Returns true if the current BinaryDecoder is at the end of its source data and cannot read any further without throwing an EOFException or other IOException.

public long
mapNext()

Implements abstract org.apache.avro.io.Decoder.mapNext.

Processes the next block of map entries and returns the count of them.
public long
readArrayStart()

Implements abstract org.apache.avro.io.Decoder.readArrayStart.

Reads and returns the size of the first block of an array.
public boolean
readBoolean()

Implements abstract org.apache.avro.io.Decoder.readBoolean.

Reads a boolean value written by Encoder#writeBoolean.
public ByteBuffer
readBytes(ByteBuffer old)

Implements abstract org.apache.avro.io.Decoder.readBytes.

Reads a byte-string written by Encoder#writeBytes.
public double
readDouble()

Implements abstract org.apache.avro.io.Decoder.readDouble.

Reads a double written by Encoder#writeDouble.
public int
readEnum()

Implements abstract org.apache.avro.io.Decoder.readEnum.

Reads an enumeration.
public 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
)

Implements abstract org.apache.avro.io.Decoder.readFixed.

Reads fixed sized binary object.
public float
readFloat()

Implements abstract org.apache.avro.io.Decoder.readFloat.

Reads a float written by Encoder#writeFloat.
public int
readIndex()

Implements abstract org.apache.avro.io.Decoder.readIndex.

Reads the tag of a union written by Encoder#writeIndex.
public int
readInt()

Implements abstract org.apache.avro.io.Decoder.readInt.

Reads an integer written by Encoder#writeInt.
public long
readLong()

Implements abstract org.apache.avro.io.Decoder.readLong.

Reads a long written by Encoder#writeLong.
public long
readMapStart()

Implements abstract org.apache.avro.io.Decoder.readMapStart.

Reads and returns the size of the next block of map-entries.
public void
readNull()

Implements abstract org.apache.avro.io.Decoder.readNull.

"Reads" a null value.
public Utf8
readString(Utf8 old)

Implements abstract org.apache.avro.io.Decoder.readString.

Reads a char-string written by Encoder#writeString.
public String
readString()

Implements abstract org.apache.avro.io.Decoder.readString.

Reads a char-string written by Encoder#writeString.
pack-priv void
setBuf(byte[] buf, int pos, int len)

public long
skipArray()

Implements abstract org.apache.avro.io.Decoder.skipArray.

Used for quickly skipping through an array.
public void
skipBytes()

Implements abstract org.apache.avro.io.Decoder.skipBytes.

Discards a byte-string written by Encoder#writeBytes.
public void
skipFixed(int
The size of the binary object to be skipped.
length
)

Implements abstract org.apache.avro.io.Decoder.skipFixed.

Discards fixed sized binary object.
public long
skipMap()

Implements abstract org.apache.avro.io.Decoder.skipMap.

Support for quickly skipping through a map similar to skipArray.
public void
skipString()

Implements abstract org.apache.avro.io.Decoder.skipString.

Discards a char-string written by Encoder#writeString.
Inherited from org.apache.avro.io.Decoder:
readFixed