Code:
public static int getObjectSize
(
Serializable obj
)
{
byte[] ba = null;
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream( baos );
oos.writeObject( obj );
oos.close();
ba = baos.toByteArray();
baos.close();
}
catch ( IOException ioe )
{
ioe.printStackTrace();
return 0;
}
return ba.length;
}