Package org.apache.avro.generic
Class GenericDatumReader<D>
java.lang.Object
org.apache.avro.generic.GenericDatumReader<D>
- All Implemented Interfaces:
DatumReader<D>
- Direct Known Subclasses:
ProtobufDatumReader
,SpecificDatumReader
,ThriftDatumReader
DatumReader
for generic Java objects.-
Constructor Summary
ModifierConstructorDescriptionprotected
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.GenericDatumReader
(Schema writer, Schema reader, GenericData data) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addToArray
(Object array, long pos, Object e) Called by the default implementation ofreadArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)
to add a value.protected void
Called by the default implementation ofreadMap(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)
to add a key/value pair.protected Object
convert
(Object datum, Schema schema, LogicalType type, Conversion<?> conversion) Convert an underlying representation of a logical type (such as a ByteBuffer) to a higher level object (such as a BigDecimal).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) Deprecated.protected Object
createFixed
(Object old, Schema schema) Deprecated.As of Avro 1.6.0 this method has been moved toGenericData.createFixed(Object, Schema)
protected Object
createString
(String value) Called to create a string from a default value.protected Class
findStringClass
(Schema schema) Determines the class to used to represent a string Schema.getData()
Return theGenericData
implementation.Get the reader's schema.protected final ResolvingDecoder
getResolver
(Schema actual, Schema expected) Gets a resolving decoder for use by this GenericDatumReader.Return the writer's schema.protected Object
Called to create new array instances.protected Object
newInstanceFromString
(Class c, String s) protected Object
Called to create new array instances.protected Object
Deprecated.As of Avro 1.6.0 this method has been moved toGenericData.newRecord(Object, Schema)
protected Object
Called by the default implementation ofreadArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)
to retrieve a value from a reused instance.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
Called to read byte arrays.protected Object
Called to read byte arrays.protected Object
Called to read an enum value.protected void
readField
(Object record, Schema.Field field, Object oldDatum, ResolvingDecoder in, Object state) Called to read a single field of a record.protected Object
Called to read a fixed value.protected Object
Called to read integers.protected Object
readMap
(Object old, Schema expected, ResolvingDecoder in) Called to read a map instance.protected Object
readMapKey
(Object old, Schema expected, Decoder in) Called by the default implementation ofreadMap(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)
to read a key value.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 Object
readWithConversion
(Object old, Schema expected, LogicalType logicalType, Conversion<?> conversion, ResolvingDecoder in) protected Object
readWithoutConversion
(Object old, Schema expected, ResolvingDecoder in) void
setExpected
(Schema reader) Set the reader's schema.void
Set the writer's schema.static void
Skip an instance of a schema.
-
Constructor Details
-
GenericDatumReader
public GenericDatumReader() -
GenericDatumReader
Construct where the writer's and reader's schemas are the same. -
GenericDatumReader
Construct given writer's and reader's schema. -
GenericDatumReader
-
GenericDatumReader
-
-
Method Details
-
getData
Return theGenericData
implementation. -
getSchema
Return the writer's schema. -
setSchema
Description copied from interface:DatumReader
Set the writer's schema.- Specified by:
setSchema
in interfaceDatumReader<D>
-
getExpected
Get the reader's schema. -
setExpected
Set the reader's schema. -
getResolver
Gets a resolving decoder for use by this GenericDatumReader. Unstable API. Currently uses a thread local cache to prevent constructing the resolvers too often, because that is very expensive.- Throws:
IOException
-
read
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 interfaceDatumReader<D>
- Throws:
IOException
-
read
Called to read data.- Throws:
IOException
-
readWithConversion
protected Object readWithConversion(Object old, Schema expected, LogicalType logicalType, Conversion<?> conversion, ResolvingDecoder in) throws IOException - Throws:
IOException
-
readWithoutConversion
protected Object readWithoutConversion(Object old, Schema expected, ResolvingDecoder in) throws IOException - Throws:
IOException
-
convert
Convert an underlying representation of a logical type (such as a ByteBuffer) to a higher level object (such as a BigDecimal).- 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.
-
readRecord
Called to read a record instance. May be overridden for alternate record representations.- Throws:
IOException
-
readField
protected void readField(Object record, Schema.Field field, Object oldDatum, ResolvingDecoder in, Object state) throws IOException Called to read a single field of a record. May be overridden for more efficient or alternate implementations.- Throws:
IOException
-
readEnum
Called to read an enum value. May be overridden for alternate enum representations. By default, returns a GenericEnumSymbol.- Throws:
IOException
-
createEnum
Called to create an enum value. May be overridden for alternate enum representations. By default, returns a GenericEnumSymbol. -
readArray
Called to read an array instance. May be overridden for alternate array representations.- Throws:
IOException
-
peekArray
Called by the default implementation ofreadArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)
to retrieve a value from a reused instance. The default implementation is forGenericArray
. -
addToArray
Called by the default implementation ofreadArray(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)
to add a value. The default implementation is forCollection
. -
readMap
Called to read a map instance. May be overridden for alternate map representations.- Throws:
IOException
-
readMapKey
Called by the default implementation ofreadMap(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)
to read a key value. The default implementation returns delegates toreadString(Object, org.apache.avro.io.Decoder)
.- Throws:
IOException
-
addToMap
Called by the default implementation ofreadMap(java.lang.Object, org.apache.avro.Schema, org.apache.avro.io.ResolvingDecoder)
to add a key/value pair. The default implementation is forMap
. -
readFixed
Called to read a fixed value. May be overridden for alternate fixed representations. By default, returnsGenericFixed
.- Throws:
IOException
-
createFixed
Deprecated.As of Avro 1.6.0 this method has been moved toGenericData.createFixed(Object, Schema)
Called to create an fixed value. May be overridden for alternate fixed representations. By default, returnsGenericFixed
. -
createFixed
Deprecated.As of Avro 1.6.0 this method has been moved toGenericData.createFixed(Object, byte[], Schema)
Called to create an fixed value. May be overridden for alternate fixed representations. By default, returnsGenericFixed
. -
newRecord
Deprecated.As of Avro 1.6.0 this method has been moved toGenericData.newRecord(Object, 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 aGenericData.Record
. -
newArray
Called to create new array instances. Subclasses may override to use a different array implementation. By default, this returns aGenericData.Array
. -
newMap
Called to create new array instances. Subclasses may override to use a different map implementation. By default, this returns aHashMap
. -
readString
Called to read strings. Subclasses may override to use a different string representation. By default, this callsreadString(Object,Decoder)
.- Throws:
IOException
-
readString
Called to read strings. Subclasses may override to use a different string representation. By default, this callsDecoder.readString(Utf8)
.- Throws:
IOException
-
createString
Called to create a string from a default value. Subclasses may override to use a different string representation. By default, this callsUtf8(String)
. -
findStringClass
Determines the class to used to represent a string Schema. By default usesGenericData.STRING_PROP
to determine whetherUtf8
orString
is used. Subclasses may override for alternate representations. -
newInstanceFromString
-
readBytes
Called to read byte arrays. Subclasses may override to use a different byte array representation. By default, this callsDecoder.readBytes(ByteBuffer)
.- Throws:
IOException
-
readBytes
Called to read byte arrays. Subclasses may override to use a different byte array representation. By default, this callsDecoder.readBytes(ByteBuffer)
.- Throws:
IOException
-
readInt
Called to read integers. Subclasses may override to use a different integer representation. By default, this callsDecoder.readInt()
.- Throws:
IOException
-
createBytes
Called to create byte arrays from default values. Subclasses may override to use a different byte array representation. By default, this callsByteBuffer.wrap(byte[])
. -
skip
Skip an instance of a schema.- Throws:
IOException
-
GenericData.createFixed(Object, byte[], Schema)