开发者

Java NIO - How to efficiently parse a file containing both ascii and binary data?

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 30M开发者_开发问答B.

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.


Redesign the file. That's a terrible design.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜