org.simantics.databoard.serialization
Class Serializer

java.lang.Object
  extended by org.simantics.databoard.serialization.Serializer
Direct Known Subclasses:
Serializer.CompositeSerializer, Serializer.NonRecursiveSerializer, Serializer.RecursiveSerializer

public abstract class Serializer
extends java.lang.Object


Nested Class Summary
static class Serializer.CompositeSerializer
          Serializer for composite data types
static class Serializer.NonRecursiveSerializer
          Serializer for non-recursive data types
static class Serializer.RecursiveSerializer
          Serializer for recursive data types
 
Constructor Summary
Serializer()
           
 
Method Summary
abstract  java.lang.Object deserialize(BinaryReadable in)
           
abstract  java.lang.Object deserialize(BinaryReadable in, java.util.List<java.lang.Object> identities)
          Deserialize an object from a readable.
 java.lang.Object deserialize(byte[] data)
          Deserialize an object in byte[] format.
 java.lang.Object deserialize(java.io.File file)
          Deserialize object from a file
 java.lang.Object deserialize(java.io.InputStream in)
          Deserialize the next object in an input stream.
abstract  java.lang.Integer getConstantSize()
          Get constant size of the data type in its binary serialized format
 java.io.InputStream getInputStream(java.lang.Object obj)
          Get object as readable Input Stream.
abstract  int getSize(java.lang.Object obj)
           
abstract  int getSize(java.lang.Object obj, gnu.trove.TObjectIntHashMap<java.lang.Object> identities)
           
 void postConstruction(SerializationFormat format)
          Finalize 2-phased construction.
abstract  void serialize(BinaryWriteable out, java.lang.Object obj)
           
abstract  void serialize(BinaryWriteable out, gnu.trove.TObjectIntHashMap<java.lang.Object> identities, java.lang.Object obj)
          Serialize obj to out.
 byte[] serialize(java.lang.Object obj)
          Serializes an object to a byte[].
 void serialize(java.lang.Object obj, java.io.File file)
          Serialize an object to a file
 void serialize(java.lang.Object obj, java.io.OutputStream out)
          Serializes an object to an output stream.
abstract  void skip(BinaryReadable in)
           
abstract  void skip(BinaryReadable in, java.util.List<java.lang.Object> identities)
          Skip over an object in a stream.
 void skip(java.io.InputStream in)
          Skip over an object in a stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Serializer

public Serializer()
Method Detail

postConstruction

public void postConstruction(SerializationFormat format)
                      throws SerializerConstructionException
Finalize 2-phased construction.

Throws:
java.lang.RuntimeException - thrown if construction fails
SerializerConstructionException

serialize

public abstract void serialize(BinaryWriteable out,
                               gnu.trove.TObjectIntHashMap<java.lang.Object> identities,
                               java.lang.Object obj)
                        throws SerializationException,
                               java.io.IOException,
                               BindingException
Serialize obj to out. The identities argument is a map of identities (in the binary block) and objects that have already been serialized. Once serialized, an object is added to the map. Typically an empty map is provided. If the type has no recursion, a null value can be provided.

Parameters:
out -
identities - Thread local empty map or null if there is no recursion
obj -
Throws:
IEncodingException
java.io.IOException
BindingException
SerializationException

serialize

public abstract void serialize(BinaryWriteable out,
                               java.lang.Object obj)
                        throws SerializationException,
                               java.io.IOException,
                               BindingException
Throws:
SerializationException
java.io.IOException
BindingException

deserialize

public abstract java.lang.Object deserialize(BinaryReadable in,
                                             java.util.List<java.lang.Object> identities)
                                      throws SerializationException,
                                             java.io.IOException,
                                             BindingException
Deserialize an object from a readable. The identities argument is a list of identities (in the binary block) of objects that have already been deserialized. Once deserialized they are added to the list. Typically an empty list is provided. If the type has no recursion, a null value can be provided.

Parameters:
in -
identities - empty identities array or null if there is no recursion
Returns:
the instance
Throws:
SerializationException
java.io.IOException
BindingException - Could not bind the data into an object

deserialize

public abstract java.lang.Object deserialize(BinaryReadable in)
                                      throws SerializationException,
                                             java.io.IOException,
                                             BindingException
Throws:
SerializationException
java.io.IOException
BindingException

deserialize

public java.lang.Object deserialize(java.io.InputStream in)
                             throws SerializationException,
                                    java.io.IOException,
                                    BindingException
Deserialize the next object in an input stream. Note, if multiple objects are deserialized from the same stream, it is more efficient to instantiate InputStreamReadable and identities only once.

Parameters:
in -
Returns:
The object deserialized into a Java Object
Throws:
SerializationException
java.io.IOException
BindingException

deserialize

public java.lang.Object deserialize(java.io.File file)
                             throws SerializationException,
                                    java.io.IOException,
                                    BindingException
Deserialize object from a file

Parameters:
file -
Returns:
the object
Throws:
SerializationException
java.io.IOException
BindingException

deserialize

public java.lang.Object deserialize(byte[] data)
                             throws SerializationException,
                                    java.io.IOException,
                                    BindingException
Deserialize an object in byte[] format.

Parameters:
data -
Returns:
the instance
Throws:
SerializationException
java.io.IOException
BindingException

skip

public abstract void skip(BinaryReadable in,
                          java.util.List<java.lang.Object> identities)
                   throws SerializationException,
                          java.io.IOException
Skip over an object in a stream. This method deserializes the object without producing a result or reading thru all bytes.

Parameters:
in -
identities -
Throws:
SerializationException
java.io.IOException
BindingException

skip

public abstract void skip(BinaryReadable in)
                   throws SerializationException,
                          java.io.IOException
Throws:
SerializationException
java.io.IOException

skip

public void skip(java.io.InputStream in)
          throws SerializationException,
                 java.io.IOException,
                 BindingException
Skip over an object in a stream. This method deserializes the object without producing a result or reading thru all bytes.

Parameters:
in -
Throws:
SerializationException
java.io.IOException
BindingException

getConstantSize

public abstract java.lang.Integer getConstantSize()
Get constant size of the data type in its binary serialized format

Returns:
size in bytes or null if not fixed

getSize

public abstract int getSize(java.lang.Object obj,
                            gnu.trove.TObjectIntHashMap<java.lang.Object> identities)
                     throws SerializationException,
                            BindingException
Parameters:
obj -
identities - thread local empty hash map
Returns:
number of bytes required to serialize obj
Throws:
SerializationException
BindingException

getSize

public abstract int getSize(java.lang.Object obj)
                     throws SerializationException,
                            BindingException
Throws:
SerializationException
BindingException

serialize

public byte[] serialize(java.lang.Object obj)
                 throws SerializationException,
                        BindingException
Serializes an object to a byte[].

Parameters:
obj -
Returns:
byte array containing the obj in its serialized format.
Throws:
SerializationException
java.io.IOException
BindingException

serialize

public void serialize(java.lang.Object obj,
                      java.io.OutputStream out)
               throws SerializationException,
                      java.io.IOException,
                      BindingException
Serializes an object to an output stream. Note, if multiple objects are serialized to the same stream, it is more efficient to instantiate OutputStreamWriteable and identities only once.

Parameters:
obj -
out -
Throws:
SerializationException
java.io.IOException
BindingException

serialize

public void serialize(java.lang.Object obj,
                      java.io.File file)
               throws SerializationException,
                      BindingException
Serialize an object to a file

Parameters:
obj -
file -
Throws:
SerializationException
java.io.IOException
BindingException

getInputStream

public java.io.InputStream getInputStream(java.lang.Object obj)
                                   throws SerializationException,
                                          BindingException
Get object as readable Input Stream.

Parameters:
obj -
Returns:
input stream
Throws:
SerializationException
BindingException