net.sf.staccatocommons.io.serialization
Interface SerializationManager

All Known Subinterfaces:
CharSerializationManager
All Known Implementing Classes:
AbstractByteSerializationManager, AbstractCharSerializationManager, ObjectStreamByteSerializationManager, XStreamXmlSerializationManager

public interface SerializationManager

A SerializationManager is an object capable of both converting an object into an OutputStream and recovering it from an InputStream

This interface does not make any assumption regarding the strategy and format in which the object is serialized, it may be in plain text, like JSON, or in some kind of binary format. That should be specified by subinterfaces and/or implementors.

The only constraint a SerializationManager must meet regarding the stream format is that serialize(Object, OutputStream) and deserialize(InputStream) methods must be compatible, that means that it must grant that if an input object is serialized and then deserialized using the same instance of this manager, the output object must have the same relevant estate that the original one. For every objects that follow Value contract - either they implement that interface or not - the following invariant must be satisfied by any implementor:

 Value valueObject = (...);
 SerializationManager sm = (...);
 ByteArrayOutputStream out = new ByteArrayOutputStream();
 sm.serialize(valueObject, out);
 ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
 assert(valueObject.equals(sm.deserialize(in)));
 

SerializationManager are not required to be able to serialize and deserialize every possible object, and implementors may impose additional restrictions to the kind of objects that are serilizable.

Author:
fbulgarelli

Method Summary
<T> T
deserialize(File input)
           
<T> T
deserialize(InputStream inputStream)
          This method does not close the inputStream
 void serialize(Object target, File output)
           
 void serialize(Object target, OutputStream outputStream)
          Writes the given target object to the given outputStream.
 

Method Detail

serialize

void serialize(Object target,
               OutputStream outputStream)
               throws org.apache.commons.lang.SerializationException
Writes the given target object to the given outputStream. This method does not close the outputStream

Parameters:
target -
outputStream -
Throws:
org.apache.commons.lang.SerializationException

deserialize

<T> T deserialize(InputStream inputStream)
              throws org.apache.commons.lang.SerializationException
This method does not close the inputStream

Type Parameters:
T -
Parameters:
inputStream -
Returns:
Throws:
org.apache.commons.lang.SerializationException
{@link - ClassCastException}

deserialize

<T> T deserialize(File input)

serialize

void serialize(Object target,
               File output)


Get Staccatocommons at SourceForge.net. Fast, secure and Free Open Source software downloads