2

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.

1
  • Do you have any control over the file format? Commented Jul 23, 2010 at 14:26

3 Answers 3

2

Redesign the file. That's a terrible design.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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

1 Comment

That just puts the file in memory. ByteBuffer has the almost the same methods as the result of FileChannel.map().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.