org.apache.avro.generic
Class GenericDatumReader<D>

java.lang.Object
  extended by org.apache.avro.generic.GenericDatumReader<D>
All Implemented Interfaces:
DatumReader<D>
Direct Known Subclasses:
SpecificDatumReader

public class GenericDatumReader<D>
extends Object
implements DatumReader<D>

DatumReader for generic Java objects.


Constructor Summary
GenericDatumReader()
           
GenericDatumReader(Schema schema)
          Construct where the writer's and reader's schemas are the same.
GenericDatumReader(Schema writer, Schema reader)
          Construct given writer's and reader's schema.
 
Method Summary
protected  void addToArray(Object array, long pos, Object e)
          Called by the default implementation of readArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder) to add a value.
protected  void addToMap(Object map, Object key, Object value)
          Called by the default implementation of readMap(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder) to add a key/value pair.
protected  Object createBytes(byte[] value)
          Called to create byte arrays from default values.
protected  Object createEnum(String symbol, Schema schema)
          Called to create an enum value.
protected  Object createFixed(Object old, byte[] bytes, Schema schema)
          Called to create an fixed value.
protected  Object createFixed(Object old, Schema schema)
          Called to create an fixed value.
protected  Object createString(String value)
          Called to create a string from a default value.
protected  Object getField(Object record, String name, int position)
          Called by the default implementation of readRecord(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder) to retrieve a record field value from a reused instance.
protected  Object newArray(Object old, int size, Schema schema)
          Called to create new array instances.
protected  Object newMap(Object old, int size)
          Called to create new array instances.
protected  Object newRecord(Object old, Schema schema)
          Called to create new record instances.
protected  Object peekArray(Object array)
          Called by the default implementation of readArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder) to retrieve a value from a reused instance.
 D read(D reuse, Decoder in)
          Read a datum.
protected  Object read(Object old, Schema expected, ResolvingDecoder in)
          Called to read data.
protected  Object readArray(Object old, Schema expected, ResolvingDecoder in)
          Called to read an array instance.
protected  Object readBytes(Object old, Decoder in)
          Called to read byte arrays.
protected  Object readEnum(Schema expected, Decoder in)
          Called to read an enum value.
protected  Object readFixed(Object old, Schema expected, Decoder in)
          Called to read a fixed value.
protected  Object readInt(Object old, Schema expected, Decoder in)
          Called to read integers.
protected  Object readMap(Object old, Schema expected, ResolvingDecoder in)
          Called to read a map instance.
protected  Object readRecord(Object old, Schema expected, ResolvingDecoder in)
          Called to read a record instance.
protected  Object readString(Object old, Decoder in)
          Called to read strings.
protected  Object readString(Object old, Schema expected, Decoder in)
          Called to read strings.
protected  void removeField(Object record, String field, int position)
          Called by the default implementation of readRecord(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder) to remove a record field value from a reused instance.
 void setExpected(Schema reader)
          Set the reader's schema.
protected  void setField(Object record, String name, int position, Object o)
          Called by the default implementation of readRecord(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder) to set a record fields value to a record instance.
 void setSchema(Schema writer)
          Set the writer's schema.
static void skip(Schema schema, Decoder in)
          Skip an instance of a schema.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericDatumReader

public GenericDatumReader()

GenericDatumReader

public GenericDatumReader(Schema schema)
Construct where the writer's and reader's schemas are the same.


GenericDatumReader

public GenericDatumReader(Schema writer,
                          Schema reader)
Construct given writer's and reader's schema.

Method Detail

setSchema

public void setSchema(Schema writer)
Description copied from interface: DatumReader
Set the writer's schema.

Specified by:
setSchema in interface DatumReader<D>

setExpected

public void setExpected(Schema reader)
                 throws IOException
Set the reader's schema.

Throws:
IOException

read

public D read(D reuse,
              Decoder in)
       throws IOException
Description copied from interface: DatumReader
Read a datum. Traverse the schema, depth-first, reading all leaf values in the schema into a datum that is returned. If the provided datum is non-null it may be reused and returned.

Specified by:
read in interface DatumReader<D>
Throws:
IOException

read

protected Object read(Object old,
                      Schema expected,
                      ResolvingDecoder in)
               throws IOException
Called to read data.

Throws:
IOException

readRecord

protected Object readRecord(Object old,
                            Schema expected,
                            ResolvingDecoder in)
                     throws IOException
Called to read a record instance. May be overridden for alternate record representations.

Throws:
IOException

setField

protected void setField(Object record,
                        String name,
                        int position,
                        Object o)
Called by the default implementation of readRecord(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder) to set a record fields value to a record instance. The default implementation is for IndexedRecord.


getField

protected Object getField(Object record,
                          String name,
                          int position)
Called by the default implementation of readRecord(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder) to retrieve a record field value from a reused instance. The default implementation is for IndexedRecord.


removeField

protected void removeField(Object record,
                           String field,
                           int position)
Called by the default implementation of readRecord(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder) to remove a record field value from a reused instance. The default implementation is for GenericRecord.


readEnum

protected Object readEnum(Schema expected,
                          Decoder in)
                   throws IOException
Called to read an enum value. May be overridden for alternate enum representations. By default, returns a GenericEnumSymbol.

Throws:
IOException

createEnum

protected Object createEnum(String symbol,
                            Schema schema)
Called to create an enum value. May be overridden for alternate enum representations. By default, returns a GenericEnumSymbol.


readArray

protected Object readArray(Object old,
                           Schema expected,
                           ResolvingDecoder in)
                    throws IOException
Called to read an array instance. May be overridden for alternate array representations.

Throws:
IOException

peekArray

protected Object peekArray(Object array)
Called by the default implementation of readArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder) to retrieve a value from a reused instance. The default implementation is for GenericArray.


addToArray

protected void addToArray(Object array,
                          long pos,
                          Object e)
Called by the default implementation of readArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder) to add a value. The default implementation is for Collection.


readMap

protected Object readMap(Object old,
                         Schema expected,
                         ResolvingDecoder in)
                  throws IOException
Called to read a map instance. May be overridden for alternate map representations.

Throws:
IOException

addToMap

protected void addToMap(Object map,
                        Object key,
                        Object value)
Called by the default implementation of readMap(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder) to add a key/value pair. The default implementation is for Map.


readFixed

protected Object readFixed(Object old,
                           Schema expected,
                           Decoder in)
                    throws IOException
Called to read a fixed value. May be overridden for alternate fixed representations. By default, returns GenericFixed.

Throws:
IOException

createFixed

protected Object createFixed(Object old,
                             Schema schema)
Called to create an fixed value. May be overridden for alternate fixed representations. By default, returns GenericFixed.


createFixed

protected Object createFixed(Object old,
                             byte[] bytes,
                             Schema schema)
Called to create an fixed value. May be overridden for alternate fixed representations. By default, returns GenericFixed.


newRecord

protected Object newRecord(Object old,
                           Schema schema)
Called to create new record instances. Subclasses may override to use a different record implementation. The returned instance must conform to the schema provided. If the old object contains fields not present in the schema, they should either be removed from the old object, or it should create a new instance that conforms to the schema. By default, this returns a GenericData.Record.


newArray

protected Object newArray(Object old,
                          int size,
                          Schema schema)
Called to create new array instances. Subclasses may override to use a different array implementation. By default, this returns a GenericData.Array.


newMap

protected Object newMap(Object old,
                        int size)
Called to create new array instances. Subclasses may override to use a different map implementation. By default, this returns a HashMap.


readString

protected Object readString(Object old,
                            Schema expected,
                            Decoder in)
                     throws IOException
Called to read strings. Subclasses may override to use a different string representation. By default, this calls readString(Object,Decoder).

Throws:
IOException

readString

protected Object readString(Object old,
                            Decoder in)
                     throws IOException
Called to read strings. Subclasses may override to use a different string representation. By default, this calls Decoder.readString(Utf8).

Throws:
IOException

createString

protected Object createString(String value)
Called to create a string from a default value. Subclasses may override to use a different string representation. By default, this calls Utf8.Utf8(String).


readBytes

protected Object readBytes(Object old,
                           Decoder in)
                    throws IOException
Called to read byte arrays. Subclasses may override to use a different byte array representation. By default, this calls Decoder.readBytes(ByteBuffer).

Throws:
IOException

readInt

protected Object readInt(Object old,
                         Schema expected,
                         Decoder in)
                  throws IOException
Called to read integers. Subclasses may override to use a different integer representation. By default, this calls Decoder.readInt().

Throws:
IOException

createBytes

protected Object createBytes(byte[] value)
Called to create byte arrays from default values. Subclasses may override to use a different byte array representation. By default, this calls ByteBuffer.wrap(byte[]).


skip

public static void skip(Schema schema,
                        Decoder in)
                 throws IOException
Skip an instance of a schema.

Throws:
IOException


Copyright © 2010 The Apache Software Foundation