Class UtilObject


  • public final class UtilObject
    extends java.lang.Object
    UtilObject
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> int compareToHelper​(java.lang.Comparable<T> o1, T o2)  
      static int doHashCode​(java.lang.Object o1)  
      static boolean equalsHelper​(java.lang.Object o1, java.lang.Object o2)  
      static long getByteCount​(java.lang.Object obj)
      Returns the size of a serializable object.
      static byte[] getBytes​(java.lang.Object obj)
      Serialize an object to a byte array
      static java.lang.Object getObject​(byte[] bytes)
      Deserialize a byte array back to an object; if there is an error, it is logged, and null is returned.
      static java.lang.Object getObjectException​(byte[] bytes)
      Deserializes a byte array back to an object.
      static <A,​R>
      R
      getObjectFromFactory​(java.lang.Class<? extends Factory<R,​A>> factoryInterface, A obj)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getBytes

        public static byte[] getBytes​(java.lang.Object obj)
        Serialize an object to a byte array
      • getByteCount

        public static long getByteCount​(java.lang.Object obj)
                                 throws java.io.IOException
        Returns the size of a serializable object. Non-serializable objects will throw an IOException.

        It is important to note that the returned value is length of the byte stream after the object has been serialized. The returned value does not represent the amount of memory the object uses. There is no accurate way to determine the size of an object in memory.

        Parameters:
        obj -
        Returns:
        the number of bytes in the serialized object
        Throws:
        java.io.IOException
      • getObject

        public static java.lang.Object getObject​(byte[] bytes)
        Deserialize a byte array back to an object; if there is an error, it is logged, and null is returned.
      • getObjectException

        public static java.lang.Object getObjectException​(byte[] bytes)
                                                   throws java.lang.ClassCastException,
                                                          java.lang.ClassNotFoundException,
                                                          java.io.IOException
        Deserializes a byte array back to an object.
        Parameters:
        bytes - the array of bytes
        Returns:
        the deserialized object.
        Throws:
        java.lang.ClassNotFoundException - when the class can not be deserialized.
        java.io.IOException - when a general Input/Output error happen.
        java.lang.ClassCastException
      • equalsHelper

        public static boolean equalsHelper​(java.lang.Object o1,
                                           java.lang.Object o2)
      • compareToHelper

        public static <T> int compareToHelper​(java.lang.Comparable<T> o1,
                                              T o2)
      • doHashCode

        public static int doHashCode​(java.lang.Object o1)
      • getObjectFromFactory

        public static <A,​R> R getObjectFromFactory​(java.lang.Class<? extends Factory<R,​A>> factoryInterface,
                                                         A obj)
                                                  throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException