This week's giveaways are in the MongoDB and Jobs Discussion forums. We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line! See this thread and this one for details.
I am quite new to file reading in Java, and I have read the tips and information on this forum as well as generally googling about it. Here's my problem in a nutshell.
I have an extremely large binary file (image, unknown format, but file format specs are available) ~ 380 MB. I am trying to open it and read it from a Java program a(will be creating a file reader). Now, I used BufferInputStream with a value of 40 MB (just a random number, I am not sure about any scientific limits) to read each 40 MB and process it, using loops. Now the problem is that the post-processing becomes steadily more and more complex with each new requirement from the client. I am not sure if doing all this post-processing inside the loop on each 40 MB is a good idea. The BufferInputStream reads from a FileInputStream. Will post the code in a bit.
Thank you in advance for pointing me in the right direction.
Joined: Mar 22, 2005
This sounds like a perfect application to write a grammar for a lexer that can interpret that file format. In my opinion that's the best way to deal with custom file formats that keep changing; writing (and maintaining) a hand-written parser is error-prone and usually results in hard-to-maintain code.
A while ago I wrote an article in the JavaRanch Journal that introduced creating lexers with the JFlex library. It used an ASCII file format as example, but it applies to binary formats as well.