0
@Override
public void messageReceived(NextFilter nextFilter, IoSession session, Object message) throws Exception
{
}

I need to read the message as a byte stream. But it does not guarantee to have the full message is received. I need to discard the messages which contains less than 16 bytes. When ever the whole length of bytes reached 16 I need to decode and use them. And in any case if it called with 17 bytes, then I need to process only 16 and leave the other one for the next cycle. Is reset() and mark() help me on this. Is there any way that I can ask mina to buffer that. Or do I have to use my own buffer ?

dinesh707
  • 12,106
  • 22
  • 84
  • 134

1 Answers1

0
  1. less than 16, you can set the postion of the IoBuffer to discard the buffer.
  2. equals 16, it's true, so you can decode it.
  3. great than 16, you can cut out previous 16 bytes to decode, and save the remain bytes into current session
wei zheng
  • 1
  • 1
  • so for 1.) IoBuffer buffer = (IoBuffer) message; and if its less than 16, what should i really call? what exact method. 2) OK. 3.) how can i save remaining into session? are you suggesting a growing byte[] attached to ioSession ? , thankx for the reply – dinesh707 Oct 29 '13 at 09:15
  • 1、you can call the method buffer.position(buffer.limit()), if not, the mina framework will recall the method messageReceived. – wei zheng Oct 29 '13 at 09:34
  • 2、yes, you can save remain bytes in a byte[] or a new IoBuffer include the remain bytes or any other struct as long as can save the data, then when your program receive next data, you should check the session first – wei zheng Oct 29 '13 at 09:37
  • 2、save the remianing bytes, you can call the method of session.setAttribute(key, value) – wei zheng Oct 29 '13 at 09:48