Package com.gpudb
Class Avro
- java.lang.Object
-
- com.gpudb.Avro
-
public final class Avro extends Object
Utility class containing static methods for encoding and decoding Avro binary objects.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tdecode(Object typeDescriptor, ByteBuffer encodedObject)Decodes an Avro binary object.static <T> List<T>decode(Object typeDescriptor, List<ByteBuffer> encodedObjects)Decodes a homogeneous list of Avro binary objects.static <T> List<T>decode(Object typeDescriptor, List<ByteBuffer> encodedObjects, int start, int count)Decodes a homogeneous portion of a list of Avro binary objects.static <T> List<T>decode(Object typeDescriptor, List<ByteBuffer> encodedObjects, int start, int count, int threadCount, ExecutorService executor)Decodes a homogeneous portion of a list of Avro binary objects, optionally using multiple threads, with or without a supplied executor.static <T> List<T>decode(Object typeDescriptor, List<ByteBuffer> encodedObjects, int threadCount, ExecutorService executor)Decodes a homogeneous list of Avro binary objects, optionally using multiple threads and/or a supplied executor.static <T extends org.apache.avro.generic.IndexedRecord>
Tdecode(T object, ByteBuffer encodedObject)Decodes an Avro binary object into a pre-created destination object.static <T> ByteBufferencode(TypeObjectMap<T> typeObjectMap, T object)Encodes a non-Avro-compatible object into Avro binary format using the specified type object map.static <T> ArrayList<ByteBuffer>encode(List<T> objects)Encodes a list of Avro-compatible objects into Avro binary format.static <T extends org.apache.avro.generic.IndexedRecord>
ByteBufferencode(T object)Encodes an Avro-compatible object into Avro binary format.
-
-
-
Method Detail
-
decode
public static <T extends org.apache.avro.generic.IndexedRecord> T decode(T object, ByteBuffer encodedObject) throws GPUdbExceptionDecodes an Avro binary object into a pre-created destination object.- Type Parameters:
T- the type of object being decoded- Parameters:
object- the destination objectencodedObject- the Avro binary object- Returns:
- the destination object (same as
objectparameter) - Throws:
GPUdbException- if a decoding error occurs
-
decode
public static <T> T decode(Object typeDescriptor, ByteBuffer encodedObject) throws GPUdbException
Decodes an Avro binary object.- Type Parameters:
T- the type of object being decoded- Parameters:
typeDescriptor- type descriptor for the type of object being decodedencodedObject- the Avro binary object- Returns:
- the decoded object
- Throws:
IllegalArgumentException- iftypeDescriptoris not aSchema,Type,TypeObjectMap, orClassthat implementsIndexedRecordGPUdbException- if a decoding error occursGPUdbRuntimeException- if unable to instantiate the class specified bytypeDescriptor
-
decode
public static <T> List<T> decode(Object typeDescriptor, List<ByteBuffer> encodedObjects, int start, int count) throws GPUdbException
Decodes a homogeneous portion of a list of Avro binary objects.- Type Parameters:
T- the type of objects being decoded- Parameters:
typeDescriptor- type descriptor for the type of objects being decodedencodedObjects- list of Avro binary objectsstart- index of first object withinencodedObjectsto decodecount- number of objects withinencodedObjectsto decode- Returns:
- list of decoded objects
- Throws:
IndexOutOfBoundsException- ifstartis less than zero,countis less than zero, orstartpluscountexceeds the length ofencodedObjectsIllegalArgumentException- iftypeDescriptoris not aSchema,Type,TypeObjectMap, orClassthat implementsIndexedRecordGPUdbException- if a decoding error occursGPUdbRuntimeException- if unable to instantiate the class specified bytypeDescriptor
-
decode
public static <T> List<T> decode(Object typeDescriptor, List<ByteBuffer> encodedObjects, int start, int count, int threadCount, ExecutorService executor) throws GPUdbException
Decodes a homogeneous portion of a list of Avro binary objects, optionally using multiple threads, with or without a supplied executor.- Type Parameters:
T- the type of objects being decoded- Parameters:
typeDescriptor- type descriptor for the type of objects being decodedencodedObjects- list of Avro binary objectsstart- index of first object withinencodedObjectsto decodecount- number of objects withinencodedObjectsto decodethreadCount- number of threads to use for decoding.executor- optional executor responsible for managing threads;nullto create threads on demand- Returns:
- list of decoded objects
- Throws:
IndexOutOfBoundsException- ifstartis less than zero,countis less than zero, orstartpluscountexceeds the length ofencodedObjectsIllegalArgumentException- ifthreadCountis less than one ortypeDescriptoris not aSchema,Type,TypeObjectMap, orClassthat implementsIndexedRecordGPUdbException- if a decoding error occursGPUdbRuntimeException- if unable to instantiate the class specified bytypeDescriptor
-
decode
public static <T> List<T> decode(Object typeDescriptor, List<ByteBuffer> encodedObjects) throws GPUdbException
Decodes a homogeneous list of Avro binary objects.- Type Parameters:
T- the type of objects being decoded- Parameters:
typeDescriptor- type descriptor for the type of objects being decodedencodedObjects- list of Avro binary objects- Returns:
- list of decoded objects
- Throws:
IllegalArgumentException- iftypeDescriptoris not aType, aTypeObjectMap, aSchema, or aClassthat implementsIndexedRecordGPUdbException- if a decoding error occursGPUdbRuntimeException- if unable to instantiate the class specified bytypeDescriptor
-
decode
public static <T> List<T> decode(Object typeDescriptor, List<ByteBuffer> encodedObjects, int threadCount, ExecutorService executor) throws GPUdbException
Decodes a homogeneous list of Avro binary objects, optionally using multiple threads and/or a supplied executor.- Type Parameters:
T- the type of objects being decoded- Parameters:
typeDescriptor- type descriptor for the type of objects being decodedencodedObjects- list of Avro binary objectsthreadCount- number of threads to use for decoding.executor- optional executor responsible for managing threads;nullto create threads on demand- Returns:
- list of decoded objects
- Throws:
IllegalArgumentException- ifthreadCountis less than one ortypeDescriptoris not aType, aTypeObjectMap, aSchema, or aClassthat implementsIndexedRecordGPUdbException- if a decoding error occursGPUdbRuntimeException- if unable to instantiate the class specified bytypeDescriptor
-
encode
public static <T extends org.apache.avro.generic.IndexedRecord> ByteBuffer encode(T object) throws GPUdbException
Encodes an Avro-compatible object into Avro binary format.- Type Parameters:
T- the type of object being encoded- Parameters:
object- the object to encode- Returns:
- the encoded object
- Throws:
GPUdbException- if an encoding error occurs
-
encode
public static <T> ByteBuffer encode(TypeObjectMap<T> typeObjectMap, T object) throws GPUdbException
Encodes a non-Avro-compatible object into Avro binary format using the specified type object map.- Type Parameters:
T- the type of object being encoded- Parameters:
typeObjectMap- the type object mapobject- the object to encode- Returns:
- the encoded object
- Throws:
GPUdbException- if an encoding error occurs
-
encode
public static <T> ArrayList<ByteBuffer> encode(List<T> objects) throws GPUdbException
Encodes a list of Avro-compatible objects into Avro binary format.- Type Parameters:
T- the type of objects being encoded- Parameters:
objects- list of objects to encode- Returns:
- list of encoded objects
- Throws:
GPUdbException- if an encoding error occurs
-
-