fipaos.util
Class Serialize

java.lang.Object
  |
  +--fipaos.util.Serialize

public class Serialize
extends java.lang.Object

This class provides some simple Serialization primitives


Constructor Summary
Serialize()
           
 
Method Summary
static java.lang.Object duplicate(java.lang.Object in)
          Duplicates the given object using serialization - completely decouples both copies.
static java.lang.Object fileToObject(java.io.File file)
          Attempts to read an Object from the given file (assume Object is serializable)
static void main(java.lang.String[] args)
           
static void objectToFile(java.io.Serializable in, java.io.File out)
          Attempts to save the given Serializable object to the given file
static byte[] toByteArray(java.lang.Object o)
          Serialises the given object into a byte[]
static java.lang.Object toObject(byte[] in)
          Reconstructs a serialised object from a byte[] to an Object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Serialize

public Serialize()
Method Detail

toByteArray

public static byte[] toByteArray(java.lang.Object o)
Serialises the given object into a byte[]
Parameters:
o - Object to serialise
Returns:
Byte[] containing the serialised object, or null if the object couldn't be serialised

toObject

public static java.lang.Object toObject(byte[] in)
Reconstructs a serialised object from a byte[] to an Object
Parameters:
in - The byte[] containing a serialised object
Returns:
The Object contained in the byte array, or null if it couldn't be de-serialized

duplicate

public static java.lang.Object duplicate(java.lang.Object in)

Duplicates the given object using serialization - completely decouples both copies.

WARNING: This is potentially an order of magnitude slower than manually cloning an object

Parameters:
in - Object to duplicate
Returns:
Duplicate object, or null if an error occured

objectToFile

public static void objectToFile(java.io.Serializable in,
                                java.io.File out)
                         throws java.io.IOException

Attempts to save the given Serializable object to the given file


fileToObject

public static java.lang.Object fileToObject(java.io.File file)
                                     throws java.io.IOException,
                                            java.lang.ClassNotFoundException
Attempts to read an Object from the given file (assume Object is serializable)

main

public static void main(java.lang.String[] args)