public class GenericDatumWriter<D> extends Object implements DatumWriter<D>
DatumWriter
for generic Java objects.Modifier | Constructor and Description |
---|---|
|
GenericDatumWriter() |
protected |
GenericDatumWriter(GenericData data) |
|
GenericDatumWriter(Schema root) |
|
GenericDatumWriter(Schema root,
GenericData data) |
Modifier and Type | Method 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).
|
protected Iterator<?> |
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. |
GenericData |
getData()
Return the
GenericData implementation. |
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 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 |
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 |
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(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.
|
public GenericDatumWriter()
protected GenericDatumWriter(GenericData data)
public GenericDatumWriter(Schema root)
public GenericDatumWriter(Schema root, GenericData data)
public GenericData getData()
GenericData
implementation.public void setSchema(Schema root)
DatumWriter
setSchema
in interface DatumWriter<D>
public void write(D datum, Encoder out) throws IOException
DatumWriter
write
in interface DatumWriter<D>
IOException
protected void write(Schema schema, Object datum, Encoder out) throws IOException
IOException
protected <T> Object convert(Schema schema, LogicalType logicalType, Conversion<T> conversion, Object datum)
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.protected void writeWithoutConversion(Schema schema, Object datum, Encoder out) throws IOException
IOException
protected NullPointerException npe(NullPointerException e, String s)
protected ClassCastException addClassCastMsg(ClassCastException e, String s)
protected AvroTypeException addAvroTypeMsg(AvroTypeException e, String s)
protected void writeRecord(Schema schema, Object datum, Encoder out) throws IOException
IOException
protected void writeField(Object datum, Schema.Field f, Encoder out, Object state) throws IOException
IOException
protected void writeEnum(Schema schema, Object datum, Encoder out) throws IOException
IOException
protected void writeArray(Schema schema, Object datum, Encoder out) throws IOException
IOException
protected int resolveUnion(Schema union, Object datum)
GenericData.resolveUnion(Schema,Object)
.protected long getArraySize(Object array)
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 Collection
.protected Iterator<?> getArrayElements(Object array)
writeArray(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder)
to enumerate
array elements. The default implementation is for Collection
.protected void writeMap(Schema schema, Object datum, Encoder out) throws IOException
IOException
protected int getMapSize(Object map)
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
.protected Iterable<Map.Entry<Object,Object>> getMapEntries(Object map)
writeMap(org.apache.avro.Schema, java.lang.Object, org.apache.avro.io.Encoder)
to enumerate map
elements. The default implementation is for Map
.protected void writeString(Schema schema, Object datum, Encoder out) throws IOException
IOException
protected void writeString(Object datum, Encoder out) throws IOException
IOException
protected void writeBytes(Object datum, Encoder out) throws IOException
IOException
protected void writeFixed(Schema schema, Object datum, Encoder out) throws IOException
IOException
Copyright © 2009–2023 The Apache Software Foundation. All rights reserved.