Package adams.core
Class SerializedObject
- java.lang.Object
-
- adams.core.SerializedObject
-
- All Implemented Interfaces:
Serializable
public class SerializedObject extends Object implements Serializable
Class for storing an object in serialized form in memory. It can be used to make deep copies of objects, and also allows compression to conserve memory.- Version:
- $Revision$
- Author:
- Richard Kirkby ([email protected])
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SerializedObject(Serializable o)Creates a new serialized object (without compression).SerializedObject(Serializable o, boolean compress)Creates a new serialized object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)Checks to see whether this object is equal to another.ObjectgetObject()Returns a serialized object.inthashCode()Returns a hashcode for this object.static Objectread(File file)Reads the object from the given file.static Objectread(String filename)Reads the object from the given file.intsize()Returns the size of bytes stored.static booleanwrite(File file, Serializable o)Writes the object to the given file.static booleanwrite(String filename, Serializable o)Writes the object to the given file.
-
-
-
Constructor Detail
-
SerializedObject
public SerializedObject(Serializable o) throws Exception
Creates a new serialized object (without compression).- Parameters:
o- the object to store- Throws:
Exception- if the object couldn't be serialized
-
SerializedObject
public SerializedObject(Serializable o, boolean compress) throws Exception
Creates a new serialized object.- Parameters:
o- the object to storecompress- whether or not to use compression- Throws:
Exception- if the object couldn't be serialized
-
-
Method Detail
-
equals
public boolean equals(Object o)
Checks to see whether this object is equal to another.
-
hashCode
public int hashCode()
Returns a hashcode for this object.
-
getObject
public Object getObject()
Returns a serialized object.- Returns:
- the restored object
-
size
public int size()
Returns the size of bytes stored.- Returns:
- the number of bytes
-
write
public static boolean write(String filename, Serializable o)
Writes the object to the given file.- Parameters:
filename- the file to write too- the object to write- Returns:
- true if successfully written
-
write
public static boolean write(File file, Serializable o)
Writes the object to the given file.- Parameters:
file- the file to write too- the object to write- Returns:
- true if successfully written
-
read
public static Object read(String filename)
Reads the object from the given file.- Parameters:
filename- the file to read from- Returns:
- if successful the object, otherwise null
-
-