Class Decoder

java.lang.Object
org.apache.avro.io.Decoder
Direct Known Subclasses:
BinaryDecoder, ParsingDecoder

public abstract class Decoder extends Object
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 Details

    • Decoder

      public Decoder()
  • Method Details

    • readNull

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

      public abstract boolean readBoolean() throws IOException
      Reads a boolean value written by Encoder.writeBoolean(boolean).
    • readInt

      public abstract int readInt() throws IOException
      Reads an integer written by Encoder.writeInt(int).
    • readLong

      public abstract long readLong() throws IOException
      Reads a long written by Encoder.writeLong(long).
    • readFloat

      public abstract float readFloat() throws IOException
      Reads a float written by Encoder.writeFloat(float).
    • readDouble

      public abstract double readDouble() throws IOException
      Reads a double written by Encoder.writeDouble(double).
    • readString

      public abstract Utf8 readString(Utf8 old) throws IOException
      Reads a char-string written by Encoder.writeString(org.apache.avro.util.Utf8).
    • readString

      public abstract String readString() throws IOException
      Reads a char-string written by Encoder.writeString(org.apache.avro.util.Utf8).
    • skipString

      public abstract void skipString() throws IOException
      Discards a char-string written by Encoder.writeString(org.apache.avro.util.Utf8).
    • readBytes

      public abstract ByteBuffer readBytes(ByteBuffer old) throws IOException
      Reads a byte-string written by Encoder.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

      public abstract void skipBytes() throws IOException
      Discards a byte-string written by Encoder.writeBytes(java.nio.ByteBuffer).
    • readFixed

      public abstract void readFixed(byte[] bytes, int start, int length) throws IOException
      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

      public void readFixed(byte[] bytes) throws IOException
      A shorthand for readFixed(bytes, 0, bytes.length).
    • skipFixed

      public abstract void skipFixed(int length) throws IOException
      Discards fixed sized binary object.
      Parameters:
      length - The size of the binary object to be skipped.
    • readEnum

      public abstract int readEnum() throws IOException
      Reads an enumeration.
      Returns:
      The enumeration's value.
    • readArrayStart

      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 invalid input: '<' i; j++) {
             read next element of the array;
           }
         }
       
    • arrayNext

      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.
    • skipArray

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

      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:
       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

      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.
    • skipMap

      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 invalid input: '<' i; j++) {
           in.skipString(); // Discard key
           in.readInt(); // Discard int-field of value
           in.readBoolean(); // Discard boolean-field of value
         }
       }
       
    • readIndex

      public abstract int readIndex() throws IOException
      Reads the tag of a union written by Encoder.writeIndex(int).