Package org.apache.ofbiz.base.util
Class UtilObject
java.lang.Object
org.apache.ofbiz.base.util.UtilObject
UtilObject
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
doHashCode
(Object o1) static long
getByteCount
(Object obj) Returns the size of a serializable object.static byte[]
Serialize an object to a byte arraystatic 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 Object
getObjectException
(byte[] bytes) Deserializes a byte array back to an object.static <A,
R> R getObjectFromFactory
(Class<? extends Factory<R, A>> factoryInterface, A obj)
-
Method Details
-
getBytes
Serialize an object to a byte array -
getByteCount
Returns the size of a serializable object. Non-serializable objects will throw anIOException
.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:
IOException
-
getObject
Deserialize a byte array back to an object; if there is an error, it is logged, and null is returned. -
getObjectException
public static Object getObjectException(byte[] bytes) throws ClassCastException, ClassNotFoundException, IOException Deserializes a byte array back to an object.- Parameters:
bytes
- the array of bytes- Returns:
- the deserialized object.
- Throws:
ClassNotFoundException
- when the class can not be deserialized.IOException
- when a general Input/Output error happen.ClassCastException
-
doHashCode
-
getObjectFromFactory
public static <A,R> R getObjectFromFactory(Class<? extends Factory<R, A>> factoryInterface, A obj) throws ClassNotFoundException- Throws:
ClassNotFoundException
-