I have one or more ByteBuffers containing parts of a single message. Now I want to read this message but I do not want to copy N ByteBuffer into a single one. My parser expects a single ByteBuffer with the complete message, but my message is divided into N ByteBuffers.
Is there a way to combine these N ByteBuffers into a single one without byte copying? I imagined some kind of smart implementation of the ByteBuffer abstract class that is backed up by these ByteBuffer under the hood and just adjust the pointers and delegates to the correct ByteBuffer.
In case you are curious why I need that, check the protocol below from BM&F/Bovespa. They break a message into chunks and they can come out-of-order in different packets, in other words, the same message sequence can come in multiple packets, each one with a message chunk. I can't write sequentially to the same ByteBuffer because these chunks can be out of order. :(
Am I missing something smarter here? It looks like there is no way to write sequentially to the same ByteBuffer given this chunk protocol below. :(