views:

125

answers:

1

Here's my problem: one big gzipped file; millions of messages.

Each message consists of:

***************** *************** ****************** 
* 2-byte LENGTH * * 1-byte TYPE * * N-byte PAYLOAD * , where N = (LENGTH-1).
***************** *************** ******************

Depending on the TYPE, I need to read a few bytes from an offset in the PAYLOAD and choose to accept or reject the message.

I know how to do this sort of thing using java.io.DataInputStream, but this seems like a perfect application of java.nio.ByteBuffer (see here!). However, I need some help setting it up.

So, how do I use ByteBuffer to read messages from my gzipped file?

Update

I guess what I'd like to see is a skeletal implementation of code that could get me on the right track to using ByteBuffer effectively. Thanks!

+1  A: 

Sorry to not answer your question, but I'm not sure there's any benefit to using ByteBuffer over DataInputStream here. You'll probably want to put your stream through GZIPInputStream to inflate the data.

GZIPInputStream gzipInput = new GZIPInputStream(yourInputStream);
DataInputStream dataInput = new DataInputStream(gzipInput);

With ByteBuffer you'd probably just be wrapping the bytes read from your input stream, with no advantage.

Nick