Class AvroUtil

java.lang.Object
org.axonframework.conversion.avro.AvroUtil

public class AvroUtil extends Object
Utilities for Avro manipulations.
Since:
4.11.0
Author:
Simon Zambrovski, Jan Galinski
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Length of encoded fingerprint long value.
    static final int
    Header size of single-object-encoding as defined in Avro specification.
    static final int
    Format version of single-objet-encoding as defined in Avro specification.
    static final org.apache.avro.generic.GenericData
    Constant utilities for construction of GenericRecord preloaded by default Avro stack.
    static final int
    Magic marker bytes, indicating single-objet-encoding as defined in Avro specification.
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<org.apache.avro.SchemaCompatibility.Incompatibility>
    checkCompatibility(org.apache.avro.Schema readerSchema, org.apache.avro.Schema writerSchema)
    Checks compatibility between reader and writer schema.
    createExceptionFailedToDeserialize(Class<?> readerType, org.apache.avro.Schema readerSchema, org.apache.avro.Schema writerSchema, Exception cause, boolean includeSchemasInStackTraces)
    Creates a conversion exception for reader type.
    createExceptionFailedToDeserialize(Class<?> readerType, org.apache.avro.Schema readerSchema, org.apache.avro.Schema writerSchema, String message, boolean includeSchemasInStackTraces)
    Creates a conversion exception for reader type.
    createExceptionNoSchemaFound(Class<?> readerType, long fingerprint)
    Creates exception if the schema for a given fingerprint could not be found.
    static long
    fingerprint(byte[] singleObjectEncodedBytes)
    Reads fingerprint from single object encoded byte array.
    static long
    fingerprint(org.apache.avro.Schema schema)
    Returns a fingerprint based on the given schema.
    static org.apache.avro.generic.GenericData
    fromSpecificData(org.apache.avro.specific.SpecificData specificData)
    Creates generic data from specific data.
    static org.apache.avro.Schema
    getClassSchema(Class<org.apache.avro.specific.SpecificRecordBase> clazz)
    Retrieves schema from specific record base class.
    static org.apache.avro.Schema
    getClassSchemaChecked(Class<org.apache.avro.specific.SpecificRecordBase> specificRecordBaseClass)
    Retrieves schema from specific record base class.
    static String
    incompatibilityPrinter(org.apache.avro.SchemaCompatibility.Incompatibility incompatibility)
    Creates incompatibility string representation.
    static byte[]
    payload(byte[] singleObjectEncodedBytes)
    Reads payload from single object encoded byte array.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAGIC_BYTE

      public static final int MAGIC_BYTE
      Magic marker bytes, indicating single-objet-encoding as defined in Avro specification.
      See Also:
    • FORMAT_VERSION

      public static final int FORMAT_VERSION
      Format version of single-objet-encoding as defined in Avro specification.
      See Also:
    • AVRO_FINGERPRINT_LENGTH

      public static final int AVRO_FINGERPRINT_LENGTH
      Length of encoded fingerprint long value.
      See Also:
    • AVRO_HEADER_LENGTH

      public static final int AVRO_HEADER_LENGTH
      Header size of single-object-encoding as defined in Avro specification.
      See Also:
    • genericData

      public static final org.apache.avro.generic.GenericData genericData
      Constant utilities for construction of GenericRecord preloaded 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 extending SpecificRecordBase
      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 extending SpecificRecordBase
      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 given schema.
      Parameters:
      schema - A Schema to 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.