Class AvroUtil
java.lang.Object
org.axonframework.conversion.avro.AvroUtil
Utilities for Avro manipulations.
- Since:
- 4.11.0
- Author:
- Simon Zambrovski, Jan Galinski
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intLength of encoded fingerprint long value.static final intHeader size of single-object-encoding as defined in Avro specification.static final intFormat version of single-objet-encoding as defined in Avro specification.static final org.apache.avro.generic.GenericDataConstant utilities for construction ofGenericRecordpreloaded by default Avro stack.static final intMagic marker bytes, indicating single-objet-encoding as defined in Avro specification. -
Method Summary
Modifier and TypeMethodDescriptionstatic List<org.apache.avro.SchemaCompatibility.Incompatibility> checkCompatibility(org.apache.avro.Schema readerSchema, org.apache.avro.Schema writerSchema) Checks compatibility between reader and writer schema.static ConversionExceptioncreateExceptionFailedToDeserialize(Class<?> readerType, org.apache.avro.Schema readerSchema, org.apache.avro.Schema writerSchema, Exception cause, boolean includeSchemasInStackTraces) Creates a conversion exception for reader type.static ConversionExceptioncreateExceptionFailedToDeserialize(Class<?> readerType, org.apache.avro.Schema readerSchema, org.apache.avro.Schema writerSchema, String message, boolean includeSchemasInStackTraces) Creates a conversion exception for reader type.static ConversionExceptioncreateExceptionNoSchemaFound(Class<?> readerType, long fingerprint) Creates exception if the schema for a given fingerprint could not be found.static longfingerprint(byte[] singleObjectEncodedBytes) Reads fingerprint from single object encoded byte array.static longfingerprint(org.apache.avro.Schema schema) Returns a fingerprint based on the givenschema.static org.apache.avro.generic.GenericDatafromSpecificData(org.apache.avro.specific.SpecificData specificData) Creates generic data from specific data.static org.apache.avro.SchemagetClassSchema(Class<org.apache.avro.specific.SpecificRecordBase> clazz) Retrieves schema from specific record base class.static org.apache.avro.SchemagetClassSchemaChecked(Class<org.apache.avro.specific.SpecificRecordBase> specificRecordBaseClass) Retrieves schema from specific record base class.static StringincompatibilityPrinter(org.apache.avro.SchemaCompatibility.Incompatibility incompatibility) Creates incompatibility string representation.static byte[]payload(byte[] singleObjectEncodedBytes) Reads payload from single object encoded byte array.
-
Field Details
-
MAGIC_BYTE
public static final int MAGIC_BYTEMagic marker bytes, indicating single-objet-encoding as defined in Avro specification.- See Also:
-
FORMAT_VERSION
public static final int FORMAT_VERSIONFormat version of single-objet-encoding as defined in Avro specification.- See Also:
-
AVRO_FINGERPRINT_LENGTH
public static final int AVRO_FINGERPRINT_LENGTHLength of encoded fingerprint long value.- See Also:
-
AVRO_HEADER_LENGTH
public static final int AVRO_HEADER_LENGTHHeader size of single-object-encoding as defined in Avro specification.- See Also:
-
genericData
public static final org.apache.avro.generic.GenericData genericDataConstant utilities for construction ofGenericRecordpreloaded by default Avro stack.
-
-
Method Details
-
fingerprint
public static long fingerprint(@Nonnull byte[] singleObjectEncodedBytes) Reads fingerprint from single object encoded byte array.- Parameters:
singleObjectEncodedBytes- The single object encoded byte array.- Returns:
- fingerprint of the schema.
- Throws:
org.apache.avro.AvroRuntimeException- if fingerprint can not be read from input bytes.
-
payload
public static byte[] payload(@Nonnull byte[] singleObjectEncodedBytes) Reads payload from single object encoded byte array.- Parameters:
singleObjectEncodedBytes- The single object encoded byte array.- Returns:
- payload bytes.
- Throws:
org.apache.avro.AvroRuntimeException- if payload bytes can not be read from input bytes.
-
fromSpecificData
public static org.apache.avro.generic.GenericData fromSpecificData(org.apache.avro.specific.SpecificData specificData) Creates generic data from specific data.- Parameters:
specificData- specific data.- Returns:
- generic data containing the same logical type conversions.
-
getClassSchemaChecked
@Nonnull public static org.apache.avro.Schema getClassSchemaChecked(@Nonnull Class<org.apache.avro.specific.SpecificRecordBase> specificRecordBaseClass) Retrieves schema from specific record base class.- Parameters:
specificRecordBaseClass- class extendingSpecificRecordBase- Returns:
- schema.
- Throws:
org.apache.avro.AvroRuntimeException- on any errors.
-
getClassSchema
@Nonnull public static org.apache.avro.Schema getClassSchema(@Nonnull Class<org.apache.avro.specific.SpecificRecordBase> clazz) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException Retrieves schema from specific record base class.- Parameters:
clazz- class extendingSpecificRecordBase- Returns:
- schema.
- Throws:
NoSuchMethodException- on wrong class structure.InvocationTargetException- on wrong class structure.IllegalAccessException- on wrong class structure.
-
fingerprint
public static long fingerprint(@Nonnull org.apache.avro.Schema schema) Returns a fingerprint based on the givenschema.- Parameters:
schema- ASchemato return the fingerprint for.- Returns:
- The fingerprint for the given
schema.
-
checkCompatibility
public static List<org.apache.avro.SchemaCompatibility.Incompatibility> checkCompatibility(@Nonnull org.apache.avro.Schema readerSchema, @Nonnull org.apache.avro.Schema writerSchema) Checks compatibility between reader and writer schema.- Parameters:
readerSchema- reader schema.writerSchema- writer schema.- Returns:
- list of incompatibilities if any, or empty list if schemas are compatible.
-
createExceptionFailedToDeserialize
@Nonnull public static ConversionException createExceptionFailedToDeserialize(@Nonnull Class<?> readerType, @Nonnull org.apache.avro.Schema readerSchema, @Nonnull org.apache.avro.Schema writerSchema, Exception cause, boolean includeSchemasInStackTraces) Creates a conversion exception for reader type.- Parameters:
readerType- object type to deserialize.readerSchema- reader schema.writerSchema- writer schema.cause- the cause of exception.includeSchemasInStackTraces- A flag controlling if the stacktrace should include reader and writer schema.- Returns:
- conversion exception.
-
createExceptionFailedToDeserialize
public static ConversionException createExceptionFailedToDeserialize(@Nonnull Class<?> readerType, @Nonnull org.apache.avro.Schema readerSchema, @Nonnull org.apache.avro.Schema writerSchema, String message, boolean includeSchemasInStackTraces) Creates a conversion exception for reader type.- Parameters:
readerType- The object type to deserialize.readerSchema- The reader schema.writerSchema- The writer schema.message- The message to report.includeSchemasInStackTraces- A flag controlling if the stacktrace should contain reader and writer schema.- Returns:
- conversion exception.
-
incompatibilityPrinter
public static String incompatibilityPrinter(@Nonnull org.apache.avro.SchemaCompatibility.Incompatibility incompatibility) Creates incompatibility string representation.- Parameters:
incompatibility- incompatibility to display.- Returns:
- string representation.
-
createExceptionNoSchemaFound
public static ConversionException createExceptionNoSchemaFound(@Nonnull Class<?> readerType, long fingerprint) Creates exception if the schema for a given fingerprint could not be found.- Parameters:
readerType- type of object to deserialize.fingerprint- fingerprint of writer schema.- Returns:
- exception to throw.
-