[nio] Mutliple Messages in ByteBuffer

M

Michael B Allen

Would anyone happen to know how java.nio handles the following scenario?

I read data from a SocketChannel into a ByteBuffer. Let's say that for
whatever reason the read fills the ByteBuffer to capacity. Now the buffer
has 1 whole message plus 10 bytes of another entirely different unrelated
message. I have no problem decoding the first message but then I'm left
with 10 bytes at the end of the ByteBuffer with no room to read the
remainder of the current message. Is there some way to move those bytes to
the beginning so I can read from the channel again and start decoding the
next message?

How is this scenario supposed to be handled with NIO?

What are your general impressions of NIO? I have read vague claims that it
has bugs.

Thanks,
Mike
 
E

Esmond Pitt

Michael said:
Is there some way to move those bytes to
the beginning so I can read from the channel again and start decoding the
next message?

Buffer.compact()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top