struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Weber <erikwe...@mindspring.com>
Subject Re: [OT] how to calculate the size of an object
Date Thu, 08 Jul 2004 17:14:36 GMT
public static long getSize(LDIFData data) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baos);
out.writeObject(data);
out.close();
return baos.toByteArray().length;
}
catch (Exception e) {
e.printStackTrace();
return -1;
}
}

John Moore wrote:

> Navjot Singh wrote:
>
>>
>> I use SAX parser to load an LDIF file into memory. Whatsoever data i 
>> read, i fill into an object.
>>
>> I need to know *the size of LDIFData object* at runtime. How to do that?
>>
>> Well the class structure is something like this
>>
>> public class LDIFData{
>> ArrayList cards; // collection of Card
>> String filename;
>> long lastLoadedTime;
>> }
>>
>> public class Card{
>> String name;
>> String email
>> String mobile;
>> }
>>
> Off the top of my head...
>
> Serialize it to a byte array output stream, see how many bytes you have
>
> John
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message