5 Replies Latest reply: Dec 17, 2006 4:53 PM by EJP RSS

    nio: how do i extract objects from a ByteBuffer buffer?

    807607
      Hi,
      i write some code with pipes and i use the following to read messages (Msg objects) from a source channel -my question applies of course to SocketChannels too:
            Pipe.SourceChannel source =(Pipe.SourceChannel)fromChannel;
            
            while (true)
            {
              bbufferRcv.clear();
              try {
                  int r=source.read(bbufferRcv);
                  if (r<=0) break;
              }
              catch (IOException e) {
      
              }               
            }         
      In the receiving buffer -given that in the worst case a maximum size Msg object fits- bytes from more than one Msg objects can be stored. The above loop stops when no more incoming bytes exist; it could be however that 2 consecutive Msg objects have been read. How can i distinguish these 2 objects?

      Thanks