Interface Codec

All Superinterfaces:
Decoder
All Known Implementing Classes:
JsonCodec, JsonLzfCodec

public interface Codec extends Decoder
A Codec specifies methods to serialise data from a Java object to byte format, and deserialise data from byte format back into a specified Java class.
  • Method Summary

    Modifier and Type
    Method
    Description
    default <T> T
    deserialise(byte[] data, Class<T> clazz)
     
    <T> T
    deserialise(byte[] data, Class<T> clazz, DecodeMethod method)
    Deserialise the given data into the specified class.
    default <T> T
    deserialise(InputStream stream, Class<T> clazz)
    Deserialise the given data into the specified class using the default decode method.
    <T> T
    deserialise(InputStream stream, Class<T> clazz, DecodeMethod method)
    Deserialise the given data into the specified class using the default decode method.
    <T> byte[]
    serialise(T object)
    Serialise the given object into a byte data form.
  • Method Details

    • deserialise

      default <T> T deserialise(byte[] data, Class<T> clazz) throws CodecException
      Throws:
      CodecException
    • deserialise

      <T> T deserialise(byte[] data, Class<T> clazz, DecodeMethod method) throws CodecException
      Deserialise the given data into the specified class.
      Type Parameters:
      T - the class the serialised data represents
      Parameters:
      data - the serialised data
      clazz - the class the serialised data represents
      method - specifies whether to use strict or lenient decoding during deserialisation
      Returns:
      an instance of the class specified represented by the data
      Throws:
      CodecException - if the data could not be deserialised
    • deserialise

      default <T> T deserialise(InputStream stream, Class<T> clazz) throws CodecException
      Deserialise the given data into the specified class using the default decode method.
      Specified by:
      deserialise in interface Decoder
      Type Parameters:
      T - the class the serialised data represents
      Parameters:
      stream - the serialised data as a stream
      clazz - the class the serialised data represents
      Returns:
      an instance of the class specified represented by the data
      Throws:
      CodecException - if the data could not be deserialised
    • deserialise

      <T> T deserialise(InputStream stream, Class<T> clazz, DecodeMethod method) throws CodecException
      Deserialise the given data into the specified class using the default decode method.
      Type Parameters:
      T - the class the serialised data represents
      Parameters:
      stream - the serialised data as a stream
      clazz - the class the serialised data represents
      method - specifies whether to use strict or lenient decoding during deserialisation
      Returns:
      an instance of the class specified represented by the data
      Throws:
      CodecException - if the data could not be deserialised
    • serialise

      <T> byte[] serialise(T object) throws CodecException
      Serialise the given object into a byte data form.
      Type Parameters:
      T - the class of the object to serialise
      Parameters:
      object - the object to serialise
      Returns:
      the serialised data of the given object
      Throws:
      CodecException - if the object could not be serialised