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

public Class ValidatingDecoder

extends ParsingDecoder
implements ActionHandler
Class Inheritance
All Implemented Interfaces
org.apache.avro.io.parsing.Parser.ActionHandler
Known Direct Subclasses
org.apache.avro.io.ResolvingDecoder
Imports
java.io.IOException, java.nio.ByteBuffer, java.util.Objects, org.apache.avro.AvroTypeException, .Schema, org.apache.avro.io.parsing.Parser, .Symbol, .ValidatingGrammarGenerator, org.apache.avro.util.Utf8

An implementation of Decoder that ensures that the sequence of operations conforms to a schema.

Use DecoderFactory#validatingDecoder(Schema, Decoder) to construct and configure.

ValidatingDecoder is not thread-safe.

See Also
Decoder, DecoderFactory

Field Summary

Modifier and TypeField and Description
protected Decoder
Inherited from org.apache.avro.io.ParsingDecoder:
parser

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv

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.
private void
checkFixed(int size)

public ValidatingDecoder
configure(Decoder in)

Re-initialize, reading from a new underlying Decoder.

public Symbol
doAction(Symbol
The input symbol from the caller of advance
input
,
Symbol
The symbol at the top the stack.
top
)

Implements org.apache.avro.io.parsing.Parser.ActionHandler.doAction.

Handle the action symbol top when the input is sought to be taken off the stack.
private static Symbol
getSymbol(Schema schema)

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

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.
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.
protected void
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.ParsingDecoder:
skipActionskipTopSymbol

Field Detail

inback to summary
protected Decoder in

Constructor Detail

ValidatingDecoderback to summary
pack-priv ValidatingDecoder(Symbol root, Decoder in) throws IOException
ValidatingDecoderback to summary
pack-priv ValidatingDecoder(Schema schema, Decoder in) throws IOException

Method Detail

arrayNextback to summary
public long arrayNext() throws IOException

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

Doc from 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.

Annotations
@Override
checkFixedback to summary
private void checkFixed(int size) throws IOException
configureback to summary
public ValidatingDecoder configure(Decoder in) throws IOException

Re-initialize, reading from a new underlying Decoder.

doActionback to summary
public Symbol doAction(Symbol input, Symbol top) throws IOException

Implements org.apache.avro.io.parsing.Parser.ActionHandler.doAction.

Doc from org.apache.avro.io.parsing.Parser.ActionHandler.doAction.

Handle the action symbol top when the input is sought to be taken off the stack.

Parameters
input:Symbol

The input symbol from the caller of advance

top:Symbol

The symbol at the top the stack.

Returns:Symbol

null if advance() is to continue processing the stack. If not null the return value will be returned by advance().

Annotations
@Override
getSymbolback to summary
private static Symbol getSymbol(Schema schema)
mapNextback to summary
public long mapNext() throws IOException

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

Doc from org.apache.avro.io.Decoder.mapNext.

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

Annotations
@Override
readArrayStartback to summary
public long readArrayStart() throws IOException

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

Doc from org.apache.avro.io.Decoder.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 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;
    }
  }
Annotations
@Override
readBooleanback to summary
public boolean readBoolean() throws IOException

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

Doc from org.apache.avro.io.Decoder.readBoolean.

Reads a boolean value written by Encoder#writeBoolean.

Annotations
@Override
readBytesback to summary
public ByteBuffer readBytes(ByteBuffer old) throws IOException

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

Doc from org.apache.avro.io.Decoder.readBytes.

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.

Annotations
@Override
readDoubleback to summary
public double readDouble() throws IOException

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

Doc from org.apache.avro.io.Decoder.readDouble.

Reads a double written by Encoder#writeDouble.

Annotations
@Override
readEnumback to summary
public int readEnum() throws IOException

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

Doc from org.apache.avro.io.Decoder.readEnum.

Reads an enumeration.

Returns:int

The enumeration's value.

Annotations
@Override
readFixedback to summary
public void readFixed(byte[] bytes, int start, int len) throws IOException

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

Doc from org.apache.avro.io.Decoder.readFixed.

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.

len:int

The size of the binary object.

Annotations
@Override
readFloatback to summary
public float readFloat() throws IOException

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

Doc from org.apache.avro.io.Decoder.readFloat.

Reads a float written by Encoder#writeFloat.

Annotations
@Override
readIndexback to summary
public int readIndex() throws IOException

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

Doc from org.apache.avro.io.Decoder.readIndex.

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

Annotations
@Override
readIntback to summary
public int readInt() throws IOException

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

Doc from org.apache.avro.io.Decoder.readInt.

Reads an integer written by Encoder#writeInt.

Annotations
@Override
readLongback to summary
public long readLong() throws IOException

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

Doc from org.apache.avro.io.Decoder.readLong.

Reads a long written by Encoder#writeLong.

Annotations
@Override
readMapStartback to summary
public long readMapStart() throws IOException

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

Doc from org.apache.avro.io.Decoder.readMapStart.

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);
  }
}
Annotations
@Override
readNullback to summary
public void readNull() throws IOException

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

Doc from org.apache.avro.io.Decoder.readNull.

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

Annotations
@Override
readStringback to summary
public Utf8 readString(Utf8 old) throws IOException

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

Doc from org.apache.avro.io.Decoder.readString.

Reads a char-string written by Encoder#writeString.

Annotations
@Override
readStringback to summary
public String readString() throws IOException

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

Doc from org.apache.avro.io.Decoder.readString.

Reads a char-string written by Encoder#writeString.

Annotations
@Override
skipArrayback to summary
public long skipArray() throws IOException

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

Doc from org.apache.avro.io.Decoder.skipArray.

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.
Annotations
@Override
skipBytesback to summary
public void skipBytes() throws IOException

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

Doc from org.apache.avro.io.Decoder.skipBytes.

Discards a byte-string written by Encoder#writeBytes.

Annotations
@Override
skipFixedback to summary
public void skipFixed(int length) throws IOException

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

Doc from org.apache.avro.io.Decoder.skipFixed.

Discards fixed sized binary object.

Parameters
length:int

The size of the binary object to be skipped.

Annotations
@Override
skipFixedback to summary
protected void skipFixed() throws IOException

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

Annotations
@Override
skipMapback to summary
public long skipMap() throws IOException

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

Doc from org.apache.avro.io.Decoder.skipMap.

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
  }
}
Annotations
@Override
skipStringback to summary
public void skipString() throws IOException

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

Doc from org.apache.avro.io.Decoder.skipString.

Discards a char-string written by Encoder#writeString.

Annotations
@Override