* @throws Exception
*/
public static byte[] writeObjectToBytes(Serializable toWrite)
throws Exception
{
ByteBufferOutputStream fos = new ByteBufferOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(fos);
try
{
oos.writeObject(toWrite);
}
finally
{
oos.close();
fos.close();
}
return fos.getBytes();
}