FileDocCategorySizeDatePackage
SerializationHelper.javaAPI DocGlassfish v2 API5740Tue May 22 16:54:34 BST 2007oracle.toplink.essentials.internal.helper

SerializationHelper

public class SerializationHelper extends Object

Provide common functionalities for serialization of object.

This class throws exceptions for invalid null inputs. Each method documents its behaviour in more detail.

author
Steven Vo
since
OracleAS 10.0.3

Fields Summary
Constructors Summary
Methods Summary
public static java.lang.Objectclone(java.io.Serializable object)

Deep clone a Serializable object using serialization.

param
the serializable object
return
the deep cloned object
throws
IOException, ClassNotFoundException

        return deserialize(serialize(object));
    
public static java.lang.Objectdeserialize(java.io.InputStream inputStream)
Deserialze an object from an InputStream

param
inputStream the serialized object input stream, must not be null
return
the deserialized object
throws
IOException, ClassNotFoundException

        if (inputStream == null) {
            throw new IllegalArgumentException("The inputStream argument cannot be null");
        }
        ObjectInputStream inStream = null;
        try {
            // stream closed in the finally
            inStream = new ObjectInputStream(inputStream);
            return inStream.readObject();

        } finally {
            try {
                if (inStream != null) {
                    inStream.close();
                }
            } catch (IOException ex) {
                // ignore
            }
        }
    
public static java.lang.Objectdeserialize(byte[] objectBytes)
Deserialize an object from a byte array

param
objectBytes the serialized object, can not be null
return
the deserialized object
throws
IOException, ClassNotFoundException

        if (objectBytes == null) {
            throw ValidationException.invalidNullMethodArguments();
        }
        ByteArrayInputStream inStream = new ByteArrayInputStream(objectBytes);
        return deserialize(inStream);
    
public static voidserialize(java.io.Serializable obj, java.io.OutputStream outputStream)
Serialize the object to an OutputStream

param
obj the object to serialize to bytes
param
outputStream the stream to write to, can not be null
throws
IOException

        if (outputStream == null) {
            throw ValidationException.invalidNullMethodArguments();
        }
        ObjectOutputStream outStream = null;

        try {
            // stream closed in the finally
            outStream = new ObjectOutputStream(outputStream);
            outStream.writeObject(obj);
        } finally {
            try {
                if (outStream != null) {
                    outStream.close();
                }
            } catch (IOException ex) {
                // ignore;
            }
        }
    
public static byte[]serialize(java.io.Serializable obj)
Serialize the object to a byte array

param
obj the object to serialize to bytes
return
a byte[] of the obj
throws
IOException

        ByteArrayOutputStream outStream = new ByteArrayOutputStream(512);
        serialize(obj, outStream);
        return outStream.toByteArray();