Package adams.core

Class 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 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 store
        compress - 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.
        Overrides:
        equals in class Object
        Parameters:
        o - the object to compare to
        Returns:
        whether or not the objects are equal
      • hashCode

        public int hashCode()
        Returns a hashcode for this object.
        Overrides:
        hashCode in class Object
        Returns:
        the hashcode
      • 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 to
        o - 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 to
        o - 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
      • read

        public static Object read​(File file)
        Reads the object from the given file.
        Parameters:
        file - the file to read from
        Returns:
        if successful the object, otherwise null