TUM CCSM Commons

edu.tum.cs.commons.io
Class SerializationUtils

java.lang.Object
  extended by edu.tum.cs.commons.io.SerializationUtils

public class SerializationUtils
extends java.lang.Object

Utility methods for serialization.

Version:
$Rev: 29381 $
Author:
hummelb, $Author: deissenb $
Rating:
GREEN Hash: CE4B1240AC4E61F91653F44688B311C5

Constructor Summary
SerializationUtils()
           
 
Method Summary
static
<T extends java.io.Serializable>
T
cloneBySerialization(T t, java.lang.ClassLoader classLoader)
          Returns a copy of the given object obtained by serialization and deserialization in memory.
static java.io.Serializable deserializeFromByteArray(byte[] bytes)
          Deserializes an object from byte array using the default class loader used in ObjectInputStream, i.e. if there is a method on the current call stack whose class was loaded via a custom class loader, this class loader is used.
static java.io.Serializable deserializeFromByteArray(byte[] bytes, java.lang.ClassLoader classLoader)
          Deserializes an object from byte array using a custom/given class loader.
static int extractInt(byte[] bytes, int position)
          Extracts an int value from the given array position (4 bytes in big endian).
static void insertInt(int i, byte[] bytes, int position)
          Inserts an int value to the given position in the byte array.
static byte[] serializeToByteArray(java.io.Serializable object)
          Serializes an object to byte array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SerializationUtils

public SerializationUtils()
Method Detail

serializeToByteArray

public static byte[] serializeToByteArray(java.io.Serializable object)
                                   throws java.io.IOException
Serializes an object to byte array

Throws:
java.io.IOException

deserializeFromByteArray

public static java.io.Serializable deserializeFromByteArray(byte[] bytes)
                                                     throws java.io.IOException,
                                                            java.lang.ClassNotFoundException
Deserializes an object from byte array using the default class loader used in ObjectInputStream, i.e. if there is a method on the current call stack whose class was loaded via a custom class loader, this class loader is used. Otherwise the default class loader is used. Also see the documentation of ObjectInputStreams resolveClass() method.

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

deserializeFromByteArray

public static java.io.Serializable deserializeFromByteArray(byte[] bytes,
                                                            java.lang.ClassLoader classLoader)
                                                     throws java.io.IOException,
                                                            java.lang.ClassNotFoundException
Deserializes an object from byte array using a custom/given class loader.

Parameters:
classLoader - the class loader used. If this is null, the default behavior of ObjectInputStream is used, i.e. if there is a method on the current call stack whose class was loaded via a custom class loader, this class loader is used. Otherwise the default class loader is used. Also see the documentation of ObjectInputStreams resolveClass() method.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

cloneBySerialization

public static <T extends java.io.Serializable> T cloneBySerialization(T t,
                                                                      java.lang.ClassLoader classLoader)
Returns a copy of the given object obtained by serialization and deserialization in memory.

Parameters:
classLoader - the class loader used. If this is null, the default behavior of ObjectInputStream is used, i.e. if there is a method on the current call stack whose class was loaded via a custom class loader, this class loader is used. Otherwise the default class loader is used. Also see the documentation of ObjectInputStreams resolveClass() method.

insertInt

public static void insertInt(int i,
                             byte[] bytes,
                             int position)
Inserts an int value to the given position in the byte array. The storage will require 4 bytes in big endian byte order.


extractInt

public static int extractInt(byte[] bytes,
                             int position)
Extracts an int value from the given array position (4 bytes in big endian). This is the counter part to insertInt(int, byte[], int) .


TUM CCSM Commons

TUM CCSM Commons - 2.7