tags:

views:

50

answers:

3

I have some data files looking something like this:

text
header
"lots of binary data hear"
/header
more text
header
"more binary data"
/header
....

Most of the files are around 1-5MB in size. It's very unlikely that I will have to deal with any files larger than approximately 30MB.

I'm fairly new to Java NIO and the API looks a bit like a jungle to me. Could anyone give me any pointers to how I should go about parsing a file like this?

Would it be possible to have multiple threads consuming data from different parts of the file? The file will just be open for reading.

A: 

you can FileChannel.map(), and read it like an array.

irreputable
That just puts the file in memory. ByteBuffer has the almost the same methods as the result of FileChannel.map().
Kathy Van Stone
+1  A: 

Redesign the file. That's a terrible design.

EJP
I'm afraid that the format is in the hands of God.
Kimble
+1  A: 

Question is how would you know if you're reading text or binary data. If there is a clear demarcation of the text and binary regions (like a marker, or a defined block size), then I suspect Preon would be able to help you out. Preon does have support for reading both text and binary data in a useful way. And since I'm pretty sure your binary data represents something else, you might also be able to decode the binary bits into a more useful data structure than just an array.

Wilfred Springer