fipaos.util
Class Serialize


public class Serialize

This class provides some simple Serialization primitives




Method Summary
 static Objectduplicate(Object in)
          Duplicates the given object using serialization - completely decouples
both copies.
 static ObjectfileToObject(File file)
          Attempts to read an Object from the given file (assume Object is serializable)
 static voidmain(String[] args)
           
 static voidobjectToFile(Serializable in, File out)
          Attempts to save the given Serializable object to the given file
 static byte[]toByteArray(Object o)
          Serialises the given object into a byte[]
 static ObjecttoObject(byte[] in)
          Reconstructs a serialised object from a byte[] to an Object

Method Detail

duplicate

public static Object duplicate(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

fileToObject

public static Object fileToObject(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(String[] args)

objectToFile

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

Attempts to save the given Serializable object to the given file


toByteArray

public static byte[] toByteArray(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 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