Using Java ByteBuffer to Read Millions of Messages

Here is my problem: one big gzipped file; millions of posts.

Each message consists of:

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

Depending on TYPEme, I need to read a few bytes from the offset in PAYLOADand choose to accept or reject the message.

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

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

Update

I guess what I would like to see is a skeletal implementation of the code that could help me on the right track use ByteBuffer efficiently. Thank!

+3
2

, , , ByteBuffer DataInputStream. , GZIPInputStream, .

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

ByteBuffer , , , , - .

+2

, , , ​​ Mina Netty? .

Mina http://mina.apache.org/

Netty http://www.jboss.org/netty

, Mina Red5, , .

-1

Source: https://habr.com/ru/post/1756367/


All Articles