org.apache.commons.lang
Class SerializationUtils

java.lang.Object
  |
  +--org.apache.commons.lang.SerializationUtils

public class SerializationUtils
extends java.lang.Object

Methods that assist with the serialization process, or perform additional functionality based on serialization.

Version:
$Id: SerializationUtils.java,v 1.2 2002/08/31 11:09:45 scolebourne Exp $
Author:
Nissim Karpenstein, Janek Bogucki, Daniel Rall, Stephen Colebourne

Constructor Summary
private SerializationUtils()
          Constructor for SerializationUtils is private
 
Method Summary
static java.lang.Object clone(java.io.Serializable object)
          Deep clone an object using serialization.
static java.lang.Object deserialize(byte[] objectData)
          Deserializes a single object from an array of bytes.
static java.lang.Object deserialize(java.io.InputStream inputStream)
          Deserializes an object from the specified stream.
static byte[] serialize(java.io.Serializable obj)
          Serializes an object to a byte array for storage/serialization.
static void serialize(java.io.Serializable obj, java.io.OutputStream outputStream)
          Serializes an object to the specified stream.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Constructor Detail

SerializationUtils

private SerializationUtils()
Constructor for SerializationUtils is private
Method Detail

clone

public static java.lang.Object clone(java.io.Serializable object)
Deep clone an object using serialization.

This is many times slower than writing clone methods by hand on all objects in your object graph. However, for complex object graphs, or for those that don't support deep cloning this can be a simple alternative implementation. Of course all the objects must be Serializable.

Parameters:
object - the Serializable object to clone
Returns:
the cloned object
Throws:
SerializationException - (runtime) if the serialization fails

serialize

public static void serialize(java.io.Serializable obj,
                             java.io.OutputStream outputStream)
Serializes an object to the specified stream. The stream will be closed once the object is written. This avoids the need for a finally clause, and maybe also exception handling, in the application code.
Parameters:
obj - the object to serialize to bytes
outputStream - the stream to write to
Throws:
SerializationException - (runtime) if the serialization fails

serialize

public static byte[] serialize(java.io.Serializable obj)
Serializes an object to a byte array for storage/serialization.
Parameters:
obj - the object to serialize to bytes
Returns:
a byte[] with the converted Serializable
Throws:
SerializationException - (runtime) if the serialization fails

deserialize

public static java.lang.Object deserialize(java.io.InputStream inputStream)
Deserializes an object from the specified stream. The stream will be closed once the object is written. This avoids the need for a finally clause, and maybe also exception handling, in the application code.
Parameters:
inputStream - the serialized object input stream
Returns:
the deserialized object
Throws:
SerializationException - (runtime) if the serialization fails

deserialize

public static java.lang.Object deserialize(byte[] objectData)
Deserializes a single object from an array of bytes.
Parameters:
objectData - the serialized object
Returns:
the deserialized object
Throws:
SerializationException - (runtime) if the serialization fails


Copyright (c) 2001-2002 - Apache Software Foundation