Package org.apache.avro.generic
Class GenericDatumWriter<D>
java.lang.Object
org.apache.avro.generic.GenericDatumWriter<D>
- All Implemented Interfaces:
DatumWriter<D>
- Direct Known Subclasses:
ProtobufDatumWriter
,SpecificDatumWriter
,ThriftDatumWriter
DatumWriter
for generic Java objects.-
Constructor Summary
ModifierConstructorDescriptionprotected
GenericDatumWriter
(Schema root) GenericDatumWriter
(Schema root, GenericData data) -
Method Summary
Modifier and TypeMethodDescriptionprotected AvroTypeException
Helper method for adding a message to an Avro Type Exception .protected ClassCastException
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).protected Iterator
<?> getArrayElements
(Object array) Called by the default implementation ofwriteArray(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 ofwriteArray(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder)
to get the size of an array.getData()
Return theGenericData
implementation.getMapEntries
(Object map) Called by the default implementation ofwriteMap(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 ofwriteMap(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder)
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.void
Set the schema.void
Write a datum.protected void
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
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
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.protected void
writeString
(Schema schema, Object datum, Encoder out) Called to write a string.protected void
writeWithoutConversion
(Schema schema, Object datum, Encoder out) Called to write data.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.avro.io.DatumWriter
toByteArray
-
Constructor Details
-
GenericDatumWriter
public GenericDatumWriter() -
GenericDatumWriter
-
GenericDatumWriter
-
GenericDatumWriter
-
-
Method Details
-
getData
Return theGenericData
implementation. -
setSchema
Description copied from interface:DatumWriter
Set the schema.- Specified by:
setSchema
in interfaceDatumWriter<D>
-
write
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 interfaceDatumWriter<D>
- Throws:
IOException
-
write
Called to write data.- Throws:
IOException
-
convert
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).- Throws:
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.
-
writeWithoutConversion
Called to write data.- Throws:
IOException
-
npe
Helper method for adding a message to an NPE . -
addClassCastMsg
Helper method for adding a message to an Class Cast Exception . -
addAvroTypeMsg
Helper method for adding a message to an Avro Type Exception . -
writeRecord
Called to write a record. May be overridden for alternate record representations.- Throws:
IOException
-
writeField
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.- Throws:
IOException
-
writeEnum
Called to write an enum value. May be overridden for alternate enum representations.- Throws:
IOException
-
writeArray
Called to write a array. May be overridden for alternate array representations.- Throws:
IOException
-
resolveUnion
Called to find the index for a datum within a union. By default callsGenericData.resolveUnion(Schema,Object)
. -
getArraySize
Called by the default implementation ofwriteArray(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder)
to get the size of an array. The default implementation is forCollection
. -
getArrayElements
Called by the default implementation ofwriteArray(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder)
to enumerate array elements. The default implementation is forCollection
. -
writeMap
Called to write a map. May be overridden for alternate map representations.- Throws:
IOException
-
getMapSize
Called by the default implementation ofwriteMap(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder)
to get the size of a map. The default implementation is forMap
. -
getMapEntries
Called by the default implementation ofwriteMap(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder)
to enumerate map elements. The default implementation is forMap
. -
writeString
Called to write a string. May be overridden for alternate string representations.- Throws:
IOException
-
writeString
Called to write a string. May be overridden for alternate string representations.- Throws:
IOException
-
writeBytes
Called to write a bytes. May be overridden for alternate bytes representations.- Throws:
IOException
-
writeFixed
Called to write a fixed value. May be overridden for alternate fixed representations.- Throws:
IOException
-