[nio] Mutliple Messages in ByteBuffer

Discussion in 'Java' started by Michael B Allen, Dec 13, 2004.

  1. 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
     
    Michael B Allen, Dec 13, 2004
    #1
    1. Advertising

  2. Michael B Allen

    Esmond Pitt Guest

    Michael B Allen wrote:
    >
    > 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()
     
    Esmond Pitt, Dec 13, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Silvis
    Replies:
    1
    Views:
    789
    Paul Lutus
    Sep 16, 2004
  2. Remon van Vliet

    nio ByteBuffer filling

    Remon van Vliet, May 19, 2005, in forum: Java
    Replies:
    3
    Views:
    2,232
    John C. Bollinger
    May 19, 2005
  3. Replies:
    2
    Views:
    1,466
  4. Replies:
    5
    Views:
    4,173
  5. Replies:
    0
    Views:
    431
Loading...

Share This Page