jodd.util
Class ObjectUtil

java.lang.Object
  extended by jodd.util.ObjectUtil

public class ObjectUtil
extends java.lang.Object

Various object utilities.


Constructor Summary
ObjectUtil()
           
 
Method Summary
static java.lang.Object byteArrayToObject(byte[] data)
          De-serialize an object from byte array.
static java.lang.Object clone(java.lang.Object source)
          Clone an object by invoking it's clone() method, even if it is not overridden.
static java.lang.Object cloneViaSerialization(java.io.Serializable obj)
          Create object copy using serialization mechanism.
static boolean equals(java.lang.Object obj1, java.lang.Object obj2)
          Safely compares two objects just like equals() would, except it allows any of the 2 objects to be null.
static boolean equalsEx(java.lang.Object obj1, java.lang.Object obj2)
          Compares two objects or two object arrays.
static boolean equalsType(java.lang.Object object, java.lang.Object thiz)
          Non-symmetric utility for comparing the types of two objects.
static byte[] objectToByteArray(java.lang.Object obj)
          Serialize an object to byte array.
static java.lang.Object readObject(java.io.File source)
          Reads serialized object from the file.
static java.lang.Object readObject(java.lang.String source)
           
static java.lang.Object readObjectAsXml(java.io.File source)
          Reads serialized object from the XML file.
static java.lang.Object readObjectAsXml(java.lang.String source)
           
static void writeObject(java.io.File dest, java.lang.Object object)
          Writes serializable object to a file.
static void writeObject(java.lang.String dest, java.lang.Object object)
           
static void writeObjectAsXml(java.io.File dest, java.lang.Object object)
          Writes serializable object to a XML file.
static void writeObjectAsXml(java.lang.String dest, java.lang.Object object)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectUtil

public ObjectUtil()
Method Detail

equals

public static boolean equals(java.lang.Object obj1,
                             java.lang.Object obj2)
Safely compares two objects just like equals() would, except it allows any of the 2 objects to be null.

Returns:
true if arguments are equal, otherwise false

equalsEx

public static boolean equalsEx(java.lang.Object obj1,
                               java.lang.Object obj2)
Compares two objects or two object arrays. Useful for Object.equals(Object).

See Also:
equals(Object, Object)

equalsType

public static boolean equalsType(java.lang.Object object,
                                 java.lang.Object thiz)
Non-symmetric utility for comparing the types of two objects. Might be useful for Object.equals(Object) if instanceof is not used.

Parameters:
object - equals() argument
thiz - current class that overrides equals()

clone

public static java.lang.Object clone(java.lang.Object source)
                              throws java.lang.CloneNotSupportedException
Clone an object by invoking it's clone() method, even if it is not overridden.

Throws:
java.lang.CloneNotSupportedException

cloneViaSerialization

public static java.lang.Object cloneViaSerialization(java.io.Serializable obj)
                                              throws java.io.IOException,
                                                     java.lang.ClassNotFoundException
Create object copy using serialization mechanism.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

writeObject

public static void writeObject(java.lang.String dest,
                               java.lang.Object object)
                        throws java.io.IOException
Throws:
java.io.IOException
See Also:
writeObject(java.io.File, Object)

writeObject

public static void writeObject(java.io.File dest,
                               java.lang.Object object)
                        throws java.io.IOException
Writes serializable object to a file. Existing file will be overwritten.

Throws:
java.io.IOException

writeObjectAsXml

public static void writeObjectAsXml(java.io.File dest,
                                    java.lang.Object object)
                             throws java.io.IOException
Writes serializable object to a XML file. Existing file will be overwritten.

Throws:
java.io.IOException

writeObjectAsXml

public static void writeObjectAsXml(java.lang.String dest,
                                    java.lang.Object object)
                             throws java.io.IOException
Throws:
java.io.IOException
See Also:
writeObjectAsXml(java.io.File, Object)

readObject

public static java.lang.Object readObject(java.lang.String source)
                                   throws java.io.IOException,
                                          java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException
See Also:
readObject(java.io.File)

readObject

public static java.lang.Object readObject(java.io.File source)
                                   throws java.io.IOException,
                                          java.lang.ClassNotFoundException
Reads serialized object from the file.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

readObjectAsXml

public static java.lang.Object readObjectAsXml(java.io.File source)
                                        throws java.io.IOException
Reads serialized object from the XML file.

Throws:
java.io.IOException

readObjectAsXml

public static java.lang.Object readObjectAsXml(java.lang.String source)
                                        throws java.io.IOException
Throws:
java.io.IOException
See Also:
readObjectAsXml(java.io.File)

objectToByteArray

public static byte[] objectToByteArray(java.lang.Object obj)
                                throws java.io.IOException
Serialize an object to byte array.

Throws:
java.io.IOException

byteArrayToObject

public static java.lang.Object byteArrayToObject(byte[] data)
                                          throws java.io.IOException,
                                                 java.lang.ClassNotFoundException
De-serialize an object from byte array.

Throws:
java.io.IOException
java.lang.ClassNotFoundException


Copyright ©2008 Jodd Team