Interface IElementSerializer

All Known Implementing Classes:
CompressingSerializer, EncryptingSerializer, StandardSerializer

public interface IElementSerializer
Defines the behavior for cache element serializers. This layer of abstraction allows us to plug in different serialization mechanisms, such as a compressing standard serializer.
  • Method Details

    • serialize

      <T> byte[] serialize(T obj) throws IOException
      Turns an object into a byte array.
      Type Parameters:
      T - the type of the object
      Parameters:
      obj - the object to serialize
      Returns:
      byte[] a byte array containing the serialized object
      Throws:
      IOException - if serialization fails
    • deSerialize

      <T> T deSerialize(byte[] bytes, ClassLoader loader) throws IOException, ClassNotFoundException
      Turns a byte array into an object.
      Parameters:
      bytes - data bytes
      loader - class loader to use
      Returns:
      Object
      Throws:
      IOException - if de-serialization fails
      ClassNotFoundException - thrown if we don't know the object.
    • serializeTo

      default <T> int serializeTo(T obj, OutputStream os) throws IOException
      Convenience method to write serialized object into a stream. The stream data will be prepended with a four-byte length prefix.
      Type Parameters:
      T - the type of the object
      Parameters:
      obj - the object to serialize
      os - the output stream
      Returns:
      the number of bytes written
      Throws:
      IOException - if serialization or writing fails
      Since:
      3.1
    • serializeTo

      default <T> int serializeTo(T obj, WritableByteChannel oc) throws IOException
      Convenience method to write serialized object into a channel. The stream data will be prepended with a four-byte length prefix.
      Type Parameters:
      T - the type of the object
      Parameters:
      obj - the object to serialize
      oc - the output channel
      Returns:
      the number of bytes written
      Throws:
      IOException - if serialization or writing fails
      Since:
      3.1
    • serializeTo

      default <T> int serializeTo(T obj, AsynchronousByteChannel oc, int writeTimeoutMs) throws IOException
      Convenience method to write serialized object into an asynchronous channel. The stream data will be prepended with a four-byte length prefix.
      Type Parameters:
      T - the type of the object
      Parameters:
      obj - the object to serialize
      oc - the output channel
      writeTimeoutMs - the write timeout im milliseconds
      Returns:
      the number of bytes written
      Throws:
      IOException - if serialization or writing fails
      Since:
      3.1
    • deSerializeFrom

      Convenience method to read serialized object from a stream. The method expects to find a four-byte length prefix in the stream data.
      Type Parameters:
      T - the type of the object
      Parameters:
      is - the input stream
      loader - class loader to use
      Throws:
      IOException - if serialization or reading fails
      ClassNotFoundException - thrown if we don't know the object.
      Since:
      3.1
    • deSerializeFrom

      Convenience method to read serialized object from a channel. The method expects to find a four-byte length prefix in the stream data.
      Type Parameters:
      T - the type of the object
      Parameters:
      ic - the input channel
      loader - class loader to use
      Throws:
      IOException - if serialization or reading fails
      ClassNotFoundException - thrown if we don't know the object.
      Since:
      3.1
    • deSerializeFrom

      default <T> T deSerializeFrom(AsynchronousByteChannel ic, int readTimeoutMs, ClassLoader loader) throws IOException, ClassNotFoundException
      Convenience method to read serialized object from an asynchronous channel. The method expects to find a four-byte length prefix in the stream data.
      Type Parameters:
      T - the type of the object
      Parameters:
      ic - the input channel
      readTimeoutMs - the read timeout in milliseconds
      loader - class loader to use
      Throws:
      IOException - if serialization or reading fails
      ClassNotFoundException - thrown if we don't know the object.
      Since:
      3.1