buffer problems

A

Andersen

I am asynchronously reading into a ByteBuffer, and I then pick things
out from the buffer. I have a problem with the ByteBuffer abstraction.
Lets say the size of the ByteBuffer is 1000 bytes, and I read 800 bytes
from a socket into the ByteBuffer. I then process it, and write the
first 500 into some other place (because the 500 bytes represent some
object). Now I have 300 bytes of data in the ByteBuffer starting at
position 500 and ending at position 800. Lets say I read on the socket
into the buffer again, and say 400 bytes are ready in the Socket, but if
I read the 400 bytes into the buffer, I overflow the buffer. Yet, I am
only using 300 bytes of the buffer.

Is there a solution to this problem?
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top