com.funambol.storage
Class ComplexSerializer

java.lang.Object
  extended by com.funambol.storage.ComplexSerializer

public class ComplexSerializer
extends java.lang.Object

A helper class useful to persist objects like Vectors and Hashtables into the device's store


Constructor Summary
ComplexSerializer()
           
 
Method Summary
static java.util.Hashtable deserializeHashTable(java.io.DataInputStream din)
          A helper method to deserialize a Hashtable
static java.lang.Object deserializeObject(java.io.DataInputStream din)
          A helper method to deserialize an Object.
static java.lang.Object[] deserializeObjectArray(java.io.DataInputStream in)
          Deserialize a given DataInputStream into a given array of objects.
static java.util.Vector deserializeVector(java.io.DataInputStream din)
          A helper method to deserialize a Vector
static java.util.Date readDateField(java.io.DataInputStream in)
          Read a UTF field to the given DataInputStream.
static java.lang.String readField(java.io.DataInputStream in)
          Read a UTF field to the given DataInputStream If the field exists write a "true", "False" otherwise
static void serializeHashTable(java.io.DataOutputStream dout, java.util.Hashtable ht)
          A helper method to serialize a Hashtable
static void serializeObject(java.io.DataOutputStream dout, java.lang.Object obj)
          A helper method to serialize an Object.
static void serializeObjectArray(java.io.DataOutputStream out, java.lang.Object[] obj)
          Serialize a given array of objects into a given DataOutputStream
static void serializeVector(java.io.DataOutputStream dout, java.util.Vector v)
          A helper method to serialize a Vector
static void writeDateField(java.io.DataOutputStream out, java.util.Date field)
          Write a Date field to the given DataOutputStream.
static void writeField(java.io.DataOutputStream out, java.lang.String field)
          Write a UTF field to the given DataOutputStream If the field is not null write a "true" before the field, just "False" otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComplexSerializer

public ComplexSerializer()
Method Detail

serializeObject

public static void serializeObject(java.io.DataOutputStream dout,
                                   java.lang.Object obj)
                            throws java.io.IOException
A helper method to serialize an Object.

It can serialize basic objects and the ones implementing the Serializable interface. TODO: implement more basic objects.

Parameters:
dout - The stream to write data to
obj - The Object to be serialized
Throws:
java.io.IOException

deserializeObject

public static java.lang.Object deserializeObject(java.io.DataInputStream din)
                                          throws java.io.IOException
A helper method to deserialize an Object.

It can deserialize basic objects and the ones implementing the Serializable interface. TODO: implement more basic objects.

Parameters:
din - The stream to write data from
Returns:
The Object deserialzed
Throws:
java.io.IOException

serializeHashTable

public static void serializeHashTable(java.io.DataOutputStream dout,
                                      java.util.Hashtable ht)
                               throws java.io.IOException
A helper method to serialize a Hashtable

Parameters:
dout - The stream to write data to
ht - The Hashtable to be serialized
Throws:
java.io.IOException

deserializeHashTable

public static java.util.Hashtable deserializeHashTable(java.io.DataInputStream din)
                                                throws java.io.IOException
A helper method to deserialize a Hashtable

Parameters:
din - The stream to write data from
Returns:
The Hashtable deserialzed
Throws:
java.io.IOException

serializeVector

public static void serializeVector(java.io.DataOutputStream dout,
                                   java.util.Vector v)
                            throws java.io.IOException
A helper method to serialize a Vector

Parameters:
dout - The stream to write data to
v - The Vector to be serialized
Throws:
java.io.IOException

deserializeVector

public static java.util.Vector deserializeVector(java.io.DataInputStream din)
                                          throws java.io.IOException
A helper method to deserialize a Vector

Parameters:
din - The stream to write data to
Returns:
The deserialized Vector
Throws:
java.io.IOException

writeField

public static void writeField(java.io.DataOutputStream out,
                              java.lang.String field)
                       throws java.io.IOException
Write a UTF field to the given DataOutputStream If the field is not null write a "true" before the field, just "False" otherwise. This method write true for Empty strings.

Parameters:
out - is the DataOutputStream to be written on
field - is the field to be written on the
Throws:
java.io.IOException -

Use this method to write a string that can be null at the moment of the serialization: null field will be written as boolean false into the OutputStream.

Read the written Stream using the com.funambol.common.ComplexSerializer.readField(DataOutputStream in) method.


readField

public static java.lang.String readField(java.io.DataInputStream in)
                                  throws java.io.IOException
Read a UTF field to the given DataInputStream If the field exists write a "true", "False" otherwise

Parameters:
in - is the DataInputStream to be read
Returns:
String if field exists, null otherwise

Use this method to read a string written with: com.funambol.common.ComplexSerializer.writeField(DataInputStream out, String field) method.

Throws:
java.io.IOException

serializeObjectArray

public static void serializeObjectArray(java.io.DataOutputStream out,
                                        java.lang.Object[] obj)
                                 throws java.io.IOException
Serialize a given array of objects into a given DataOutputStream

Parameters:
out - is the stream to be written
s - is the Serializable object array to be serialized
Throws:
java.io.IOException

deserializeObjectArray

public static java.lang.Object[] deserializeObjectArray(java.io.DataInputStream in)
                                                 throws java.io.IOException
Deserialize a given DataInputStream into a given array of objects.

Parameters:
out - is the stream to be written
s - is the Serializable object array to be serialized
Throws:
java.io.IOException

writeDateField

public static void writeDateField(java.io.DataOutputStream out,
                                  java.util.Date field)
                           throws java.io.IOException
Write a Date field to the given DataOutputStream.

Use this method to write a Date field that can be null: null field will be written as 0L into the OutputStream.

Read the written Stream using the com.funambol.common.ComplexSerializer.readDateField(DataOutputStream in) method.

Parameters:
out - is the DataOutputStream to be written on
Date - is the field to be written on the
Throws:
java.io.IOException - Note: the midnight of the 01/01/1970 will be considered null.


readDateField

public static java.util.Date readDateField(java.io.DataInputStream in)
                                    throws java.io.IOException
Read a UTF field to the given DataInputStream.

Use this method to read a string written with: com.funambol.common.ComplexSerializer.writeDateField(DataInputStream out, String field) method.

Parameters:
in - is the DataInputStream to be read
Returns:
Date value if field exists, null otherwise
Throws:
java.io.IOException


Copyright © 2001-2009 Funambol.