• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

serialization and sizeof (again :-)

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there!

i would like to send objects over sockets, but would like to be able to determine the size of the serialized object so i can provide an estimate of how long it would take to send. i understand that there is no "straight forward" way of determining the size of an object, but is there a way of finding how big the serialized object without having to write it to file, and then looking at how big the file is? - this would complicate matters as the objects may contain sensative data.

thanks,
tian
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would have to buffer it in memory as a sequence of bytes and use that as your metric of size.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See java.io.ByteArrayOutputStream - note that the resulting byte[] will also be handy for encrypting your sensitive object.
Bill
 
Tian Zhang
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks!

i half suspected as much
 
reply
    Bookmark Topic Watch Topic
  • New Topic