package org.jboss.mx.util;
import org.jboss.mx.server.ObjectInputStreamWithClassLoader;
import java.io.*;
public class SerializationHelper
{
public static Object deserialize(byte[] byteArray)
throws IOException, ClassNotFoundException
{
return deserialize(byteArray,Thread.currentThread().getContextClassLoader());
}
public static Object deserialize(byte[] byteArray, ClassLoader cl)
throws IOException, ClassNotFoundException
{
if (byteArray == null)
{
return null;
}
if (byteArray.length == 0)
{
return null;
}
try
{
if (cl==null)
{
cl = SerializationHelper.class.getClassLoader();
}
ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(byteArray);
ObjectInputStream objectinputstream = new ObjectInputStreamWithClassLoader(bytearrayinputstream,cl);
Object obj = objectinputstream.readObject();
return obj;
}
catch (OptionalDataException optionaldataexception)
{
throw new IOException(optionaldataexception.getMessage());
}
}
public static byte[] serialize(Object obj)
throws IOException
{
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
ObjectOutputStream objectoutputstream = new ObjectOutputStream(bytearrayoutputstream);
objectoutputstream.writeObject(obj);
return bytearrayoutputstream.toByteArray();
}
}