The msg.setAutoExpand(true) causes the buffer to automatically change the capacity and limit. If you need the exact size, you have to take care of it yourself (i.e. determine the buffer size beforehand, allocate it and setAutoExpand(false) ).

Jeroen Brattinga

Sungwon Jung wrote:
Hello. I'm using MINA 1.1.2

I have a question about ByteBuffer.allocate();

Let me show you code.

--
ByteBuffer msg = ByteBuffer.allocate( 9, false );
msg.setAutoExpand( true );

msg.put( (byte)0x01 );          // 1 byte
msg.putShort( (short)0x01 );            // 2 byte
msg.put( (byte)0x01 );          // 1 byte
msg.put( (byte)0x01 );          // 1 byte
msg.putInt( 0 );                        // 4 byte
msg.put( (byte)0x01 );          // 1 byte
msg.put( (byte)0x01 );          // 1 byte
msg.put( (byte)0x01 );          // 1 byte
msg.put( (byte)0x01 );          // 1 byte

logger.debug( msg.limit() );            // output is 16

but, ByteBuffer msg = ByteBuffer.allocate( 8, false );

logger.debug( msg.limit() );            // output is 13


what's the reason?


Reply via email to