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.
The moose likes Java in General and the fly likes Reasding large binary file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Reasding large binary file" Watch "Reasding large binary file" New topic
Author

Reasding large binary file

harish kshatrea
Greenhorn

Joined: Nov 20, 2009
Posts: 14
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.

Cheers,
Harish.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35220
    
    7
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.


Android appsImageJ pluginsJava web charts
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32599
    
    4
Sounds a candidate for moving as too difficult a question for this forum.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Reasding large binary file
 
Similar Threads
Files vs Arrays?
Image Processing
Java Beginner's I/O Question
Best way to manipulate files
Looking for an order-of-magnitude speed-up