Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Byte Array returned from ByteArrayOutputStream.

Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I have an object which i want to serialize to a file, for which i am using ByteArrayOutputStream and ObjectOutputStream along with FileChannel to write it.

I want to write a Header Object (POJO implementing Serializable interface) at the TOP of the file before writting anything (Serialized Objects) to this file. and want to update the same header object when all other objects are being written to the file.

For this i am trying to use a specific Byte Block.
But when i get the byte[] from ByteArrayOutputStream it creates a new byte array with the size of the object in bytes.

eg. i have a header object which is almost 197 bytes in size (just a rough estimate with some testing) and i want to write this header object at TOP by allocating 300 bytes to it. so that i can start writting all other objects after 300 bytes in file.

code snippet is as follows:

1. How we can write any object in serialized form with specific byte size?
2. How can we update that object again with new data, before closing the file or on some condition?

Can someone please guide me , how this can be done, so that before reading file contents, i can actually go to the top and read header object in the begining to get file information.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic