• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Read Byte Array alternatively

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a file containing byte array in which the data is stored in this format: "HEADER + MESSAGE + HEADER + MESSAGE".

Now I want to read only "MESSAGES" from this file (as I have given format as above) by ignoring "HEADERs".

Again the size of "HEADERS" is not fixed, it can be of any size. But that I can manage. I want an idea through which I can extract only "MESSAGES" from this file.

Let me know if this explanation to the problem is enough or want more information.

Can any give a brief idea about it ?

Regards,
Pratik
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to read everything, of course, and just keep the messages.
 
Pratik Surti
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ernest Friedman-Hill wrote:You have to read everything, of course, and just keep the messages.



I am able to read everything from the file containing byte array but i have to skip "HEADERS" from it. Do you mean to say to use skip() method of FileInputStream ?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the headers and the messages both vary in length, then your program will need to examine the headers to determine where they end, and likewise examine the messages to determine where the next header starts. Your program can't skip anything, really -- but if you don't need the headers, you don't need to store them anywhere.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'd have to know how much to skip, which would mean reading everything.

Without the actual file format it's difficult to help, but it seems like it's a pretty simple parsing problem.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic