Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Convert Object to byte array and array size should be 40

 
Srikanth Nakka
Greenhorn
Posts: 26
Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



i want to convert above class to byte array and array size should be 40

please help me on how to convert class to byte array and size should be 40

 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't without losing data. A long needs 8 data, a char and a short 2. Therefore, you need 8 + 8 + 2*2 + 2 + 2 + 8*2 + 8*2 + 8*2 + 2 = 74 bytes. Even if you use only one byte per char (which is possible for ASCII characters) you still need 48 bytes.
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might be able to shrink those class members down via huffman encoding, that way you will lose nothing.

Your subject implies to me that you are looking to split up the serialized object into a byte array? If that is the case, I have to ask why? If I am misreading, can you clarify what you are looking to do and why please?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic