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

java.lang.Object
  extended by org.apache.avro.generic.GenericDatumWriter<D>
All Implemented Interfaces:
DatumWriter<D>
Direct Known Subclasses:
ReflectDatumWriter

public class GenericDatumWriter<D>
extends Object
implements DatumWriter<D>

DatumWriter for generic Java objects.


Constructor Summary
GenericDatumWriter()
           
GenericDatumWriter(Schema root)
           
 
Method Summary
protected  Iterator<? extends Object> getArrayElements(Object array)
          Called by the default implementation of writeArray(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder) to enumerate array elements.
protected  long getArraySize(Object array)
          Called by the default implementation of writeArray(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder) to get the size of an array.
protected  Object getField(Object record, String field, int position)
          Called by the default implementation of writeRecord(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder) to retrieve a record field value.
protected  Iterable<Map.Entry<Object,Object>> getMapEntries(Object map)
          Called by the default implementation of writeMap(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder) to enumerate map elements.
protected  int getMapSize(Object map)
          Called by the default implementation of writeMap(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder) to get the size of a map.
protected  boolean instanceOf(Schema schema, Object datum)
          Called to resolve unions.
protected  boolean isArray(Object datum)
          Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).
protected  boolean isBytes(Object datum)
          Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).
protected  boolean isEnum(Object datum)
          Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).
protected  boolean isFixed(Object datum)
          Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).
protected  boolean isMap(Object datum)
          Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).
protected  boolean isRecord(Object datum)
          Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).
protected  boolean isString(Object datum)
          Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).
 void setSchema(Schema root)
          Set the schema.
 void write(D datum, Encoder out)
          Write a datum.
protected  void write(Schema schema, Object datum, Encoder out)
          Called to write data.
protected  void writeArray(Schema schema, Object datum, Encoder out)
          Called to write a array.
protected  void writeBytes(Object datum, Encoder out)
          Called to write a bytes.
protected  void writeEnum(Schema schema, Object datum, Encoder out)
          Called to write an enum value.
protected  void writeFixed(Schema schema, Object datum, Encoder out)
          Called to write a fixed value.
protected  void writeMap(Schema schema, Object datum, Encoder out)
          Called to write a map.
protected  void writeRecord(Schema schema, Object datum, Encoder out)
          Called to write a record.
protected  void writeString(Object datum, Encoder out)
          Called to write a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericDatumWriter

public GenericDatumWriter()

GenericDatumWriter

public GenericDatumWriter(Schema root)
Method Detail

setSchema

public void setSchema(Schema root)
Description copied from interface: DatumWriter
Set the schema.

Specified by:
setSchema in interface DatumWriter<D>

write

public void write(D datum,
                  Encoder out)
           throws IOException
Description copied from interface: DatumWriter
Write a datum. Traverse the schema, depth first, writing each leaf value in the schema from the datum to the output.

Specified by:
write in interface DatumWriter<D>
Throws:
IOException

write

protected void write(Schema schema,
                     Object datum,
                     Encoder out)
              throws IOException
Called to write data.

Throws:
IOException

writeRecord

protected void writeRecord(Schema schema,
                           Object datum,
                           Encoder out)
                    throws IOException
Called to write a record. May be overridden for alternate record representations.

Throws:
IOException

getField

protected Object getField(Object record,
                          String field,
                          int position)
Called by the default implementation of writeRecord(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder) to retrieve a record field value. The default implementation is for GenericRecord.


writeEnum

protected void writeEnum(Schema schema,
                         Object datum,
                         Encoder out)
                  throws IOException
Called to write an enum value. May be overridden for alternate enum representations.

Throws:
IOException

writeArray

protected void writeArray(Schema schema,
                          Object datum,
                          Encoder out)
                   throws IOException
Called to write a array. May be overridden for alternate array representations.

Throws:
IOException

getArraySize

protected long getArraySize(Object array)
Called by the default implementation of writeArray(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder) to get the size of an array. The default implementation is for GenericArray.


getArrayElements

protected Iterator<? extends Object> getArrayElements(Object array)
Called by the default implementation of writeArray(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder) to enumerate array elements. The default implementation is for GenericArray.


writeMap

protected void writeMap(Schema schema,
                        Object datum,
                        Encoder out)
                 throws IOException
Called to write a map. May be overridden for alternate map representations.

Throws:
IOException

getMapSize

protected int getMapSize(Object map)
Called by the default implementation of writeMap(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder) to get the size of a map. The default implementation is for Map.


getMapEntries

protected Iterable<Map.Entry<Object,Object>> getMapEntries(Object map)
Called by the default implementation of writeMap(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder) to enumerate map elements. The default implementation is for Map.


writeString

protected void writeString(Object datum,
                           Encoder out)
                    throws IOException
Called to write a string. May be overridden for alternate string representations.

Throws:
IOException

writeBytes

protected void writeBytes(Object datum,
                          Encoder out)
                   throws IOException
Called to write a bytes. May be overridden for alternate bytes representations.

Throws:
IOException

instanceOf

protected boolean instanceOf(Schema schema,
                             Object datum)
Called to resolve unions. May be overridden for alternate data representations.


writeFixed

protected void writeFixed(Schema schema,
                          Object datum,
                          Encoder out)
                   throws IOException
Called to write a fixed value. May be overridden for alternate fixed representations.

Throws:
IOException

isArray

protected boolean isArray(Object datum)
Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).


isRecord

protected boolean isRecord(Object datum)
Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).


isEnum

protected boolean isEnum(Object datum)
Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).


isMap

protected boolean isMap(Object datum)
Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).


isFixed

protected boolean isFixed(Object datum)
Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).


isString

protected boolean isString(Object datum)
Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).


isBytes

protected boolean isBytes(Object datum)
Called by the default implementation of instanceOf(org.apache.avro.Schema, java.lang.Object).



Copyright © 2009 The Apache Software Foundation