I’m currently using a ByteBuffer to store a chain of primitives before sending it all over the wire.
I’m using data.order(ByteOrder.LITTLE_ENDIAN); because that’s how data should be sent.
Is there a ByteBuffer equivalent that supports putShort()… using little endian, AND can be expanded?
I could write a wrapper that checks limit() and position(), creating a new and bigger ByteBuffer when necessary, but I can’t believe there’s no other existing class that can do that.
It appears that Apache Mina has what you want: http://mina.apache.org/report/1.1/apidocs/org/apache/mina/common/ByteBuffer.html
I know that Mina is used in many production messaging systems, so it’s probably a better choice than the other results that Google returned. And as you seem to be writing network code, you may find additional pieces of Mina useful.
However, I think it would be far simpler to allocate a much-larger-than-needed JDK buffer, with a simple check to ensure that you don’t overrun it. In the case where you do overrun, write the first buffer then allocate a replacement.