Use ObjectOutputStream to write an object to ByteArrayOutputstream and check the length of the resulting byte array.
Obviously, your Map.Entry will need to implement Serializable.
public int getSizeInBytes(Serializable someObject) { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream objectOut = new ObjectOutputStream(byteOut); objectOut.writeObject(someObject); objectOut.flush(); return byteOut.toByteArray().length; } public int getSizeBits(Serializable someObject) { return getSizeInBytes(someObject) * 8; }
lance-java Dec 08 '13 at 20:46 2013-12-08 20:46
source share