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 Summary
Modifier and TypeMethodDescription<T> T
deSerialize
(byte[] bytes, ClassLoader loader) Turns a byte array into an object.default <T> T
deSerializeFrom
(InputStream is, ClassLoader loader) Convenience method to read serialized object from a stream.default <T> T
deSerializeFrom
(AsynchronousByteChannel ic, int readTimeoutMs, ClassLoader loader) Convenience method to read serialized object from an asynchronous channel.default <T> T
deSerializeFrom
(ReadableByteChannel ic, ClassLoader loader) Convenience method to read serialized object from a channel.<T> byte[]
serialize
(T obj) Turns an object into a byte array.default <T> int
serializeTo
(T obj, OutputStream os) Convenience method to write serialized object into a stream.default <T> int
serializeTo
(T obj, AsynchronousByteChannel oc, int writeTimeoutMs) Convenience method to write serialized object into an asynchronous channel.default <T> int
serializeTo
(T obj, WritableByteChannel oc) Convenience method to write serialized object into a channel.
-
Method Details
-
serialize
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
Turns a byte array into an object.- Parameters:
bytes
- data bytesloader
- class loader to use- Returns:
- Object
- Throws:
IOException
- if de-serialization failsClassNotFoundException
- thrown if we don't know the object.
-
serializeTo
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 serializeos
- the output stream- Returns:
- the number of bytes written
- Throws:
IOException
- if serialization or writing fails- Since:
- 3.1
-
serializeTo
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 serializeoc
- 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 serializeoc
- the output channelwriteTimeoutMs
- the write timeout im milliseconds- Returns:
- the number of bytes written
- Throws:
IOException
- if serialization or writing fails- Since:
- 3.1
-
deSerializeFrom
default <T> T deSerializeFrom(InputStream is, ClassLoader loader) throws IOException, ClassNotFoundException 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 streamloader
- class loader to use- Throws:
IOException
- if serialization or reading failsClassNotFoundException
- thrown if we don't know the object.- Since:
- 3.1
-
deSerializeFrom
default <T> T deSerializeFrom(ReadableByteChannel ic, ClassLoader loader) throws IOException, ClassNotFoundException 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 channelloader
- class loader to use- Throws:
IOException
- if serialization or reading failsClassNotFoundException
- 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 channelreadTimeoutMs
- the read timeout in millisecondsloader
- class loader to use- Throws:
IOException
- if serialization or reading failsClassNotFoundException
- thrown if we don't know the object.- Since:
- 3.1
-