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

public Class GenericDatumWriter<D>

extends Object
implements DatumWriter<D>
Class Inheritance
All Implemented Interfaces
org.apache.avro.io.DatumWriter
Known Direct Subclasses
org.apache.avro.specific.SpecificDatumWriter
Imports
java.io.IOException, java.nio.ByteBuffer, java.util.ConcurrentModificationException, .Iterator, .Map, .Objects, .Collection, org.apache.avro.AvroRuntimeException, .AvroTypeException, .Conversion, .Conversions, .LogicalType, .Schema, .Schema.Field, .UnresolvedUnionException, org.apache.avro.path.TracingAvroTypeException, .ArrayPositionPredicate, .LocationStep, .MapKeyPredicate, .TracingClassCastException, .TracingNullPointException, .UnionTypePredicate, org.apache.avro.io.DatumWriter, .Encoder, org.apache.avro.util.SchemaUtil

DatumWriter for generic Java objects.

Field Summary

Modifier and TypeField and Description
private final GenericData
private Schema

Constructor Summary

AccessConstructor and Description
public
protected
public
public

Method Summary

Modifier and TypeMethod and Description
protected AvroTypeException
addAvroTypeMsg(AvroTypeException e, String s)

Helper method for adding a message to an Avro Type Exception .

protected ClassCastException
addClassCastMsg(ClassCastException e, String s)

Helper method for adding a message to an Class Cast Exception .

protected <T> Object
convert(Schema schema, LogicalType logicalType, Conversion<T> conversion, Object datum)

Convert a high level representation of a logical type (such as a BigDecimal) to its underlying representation object (such as a ByteBuffer).

private void
error(Schema schema, Object datum)

protected Iterator<?>
getArrayElements(Object array)

Called by the default implementation of writeArray to enumerate array elements.

protected long
getArraySize(Object array)

Called by the default implementation of writeArray to get the size of an array.

public GenericData
getData()

Return the GenericData implementation.

protected Iterable<Map.Entry<Object, Object>>
getMapEntries(Object map)

Called by the default implementation of writeMap to enumerate map elements.

protected int
getMapSize(Object map)

Called by the default implementation of writeMap to get the size of a map.

protected NullPointerException
npe(NullPointerException e, String s)

Helper method for adding a message to an NPE .

protected int
resolveUnion(Schema union, Object datum)

Called to find the index for a datum within a union.

public void
public void
write(D datum, Encoder out)

Implements org.apache.avro.io.DatumWriter.write.

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
writeField(Object datum, Schema.Field f, Encoder out, Object state)

Called to write a single field of a record.

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(Schema schema, Object datum, Encoder out)

Called to write a string.

protected void
writeString(Object datum, Encoder out)

Called to write a string.

protected void
writeWithoutConversion(Schema schema, Object datum, Encoder out)

Called to write data.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

databack to summary
private final GenericData data
rootback to summary
private Schema root

Constructor Detail

GenericDatumWriterback to summary
public GenericDatumWriter()
GenericDatumWriterback to summary
protected GenericDatumWriter(GenericData data)
GenericDatumWriterback to summary
public GenericDatumWriter(Schema root)
GenericDatumWriterback to summary
public GenericDatumWriter(Schema root, GenericData data)

Method Detail

addAvroTypeMsgback to summary
protected AvroTypeException addAvroTypeMsg(AvroTypeException e, String s)

Helper method for adding a message to an Avro Type Exception .

addClassCastMsgback to summary
protected ClassCastException addClassCastMsg(ClassCastException e, String s)

Helper method for adding a message to an Class Cast Exception .

convertback to summary
protected <T> Object convert(Schema schema, LogicalType logicalType, Conversion<T> conversion, Object datum)

Convert a high level representation of a logical type (such as a BigDecimal) to its underlying representation object (such as a ByteBuffer).

Exceptions
IllegalArgumentException:
if a null schema or logicalType is passed in while datum and conversion are not null. Please be noticed that the exception type has changed. With version 1.8.0 and earlier, in above circumstance, the exception thrown out depends on the implementation of conversion (most likely a NullPointerException). Now, an IllegalArgumentException will be thrown out instead.
errorback to summary
private void error(Schema schema, Object datum)
getArrayElementsback to summary
protected Iterator<?> getArrayElements(Object array)

Called by the default implementation of writeArray to enumerate array elements. The default implementation is for Collection.

getArraySizeback to summary
protected long getArraySize(Object array)

Called by the default implementation of writeArray to get the size of an array. The default implementation is for Collection.

getDataback to summary
public GenericData getData()

Return the GenericData implementation.

getMapEntriesback to summary
protected Iterable<Map.Entry<Object, Object>> getMapEntries(Object map)

Called by the default implementation of writeMap to enumerate map elements. The default implementation is for Map.

Annotations
@SuppressWarnings:unchecked
getMapSizeback to summary
protected int getMapSize(Object map)

Called by the default implementation of writeMap to get the size of a map. The default implementation is for Map.

Annotations
@SuppressWarnings:unchecked
npeback to summary
protected NullPointerException npe(NullPointerException e, String s)

Helper method for adding a message to an NPE .

resolveUnionback to summary
protected int resolveUnion(Schema union, Object datum)

Called to find the index for a datum within a union. By default calls GenericData#resolveUnion(Schema, Object).

setSchemaback to summary
public void setSchema(Schema root)

Implements org.apache.avro.io.DatumWriter.setSchema.

Doc from org.apache.avro.io.DatumWriter.setSchema.

Set the schema.

writeback to summary
public void write(D datum, Encoder out) throws IOException

Implements org.apache.avro.io.DatumWriter.write.

Doc from org.apache.avro.io.DatumWriter.write.

Write a datum. Traverse the schema, depth first, writing each leaf value in the schema from the datum to the output.

writeback to summary
protected void write(Schema schema, Object datum, Encoder out) throws IOException

Called to write data.

writeArrayback to summary
protected void writeArray(Schema schema, Object datum, Encoder out) throws IOException

Called to write a array. May be overridden for alternate array representations.

writeBytesback to summary
protected void writeBytes(Object datum, Encoder out) throws IOException

Called to write a bytes. May be overridden for alternate bytes representations.

writeEnumback to summary
protected void writeEnum(Schema schema, Object datum, Encoder out) throws IOException

Called to write an enum value. May be overridden for alternate enum representations.

writeFieldback to summary
protected void writeField(Object datum, Schema.Field f, Encoder out, Object state) throws IOException

Called to write a single field of a record. May be overridden for more efficient or alternate implementations.

writeFixedback to summary
protected void writeFixed(Schema schema, Object datum, Encoder out) throws IOException

Called to write a fixed value. May be overridden for alternate fixed representations.

writeMapback to summary
protected void writeMap(Schema schema, Object datum, Encoder out) throws IOException

Called to write a map. May be overridden for alternate map representations.

writeRecordback to summary
protected void writeRecord(Schema schema, Object datum, Encoder out) throws IOException

Called to write a record. May be overridden for alternate record representations.

writeStringback to summary
protected void writeString(Schema schema, Object datum, Encoder out) throws IOException

Called to write a string. May be overridden for alternate string representations.

writeStringback to summary
protected void writeString(Object datum, Encoder out) throws IOException

Called to write a string. May be overridden for alternate string representations.

writeWithoutConversionback to summary
protected void writeWithoutConversion(Schema schema, Object datum, Encoder out) throws IOException

Called to write data.