directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Trustin Lee <>
Subject [mina] Changes on ByteBuffer
Date Tue, 19 Apr 2005 15:04:01 GMT

I realized implementing complex codecs using NIO ByteBuffers is not
really easy task and the main reason is that its size is fixed.  So I
added autoExpand property to MINA ByteBuffer.  If autoExpand is true,
you never get BufferOverflowException or IndexOutOfBoundsException
(except when index is negative).  It automatically expands its
capacity and limit value.  This is useful especially when you create
data whose length is dynamic:

String greeting = messageBundle.getMessage( "hello" );
ByteBuffer buf = ByteBuffer.allocate( 16 );
buf.setAutoExpand( true );
buf.putString( greeting, utf8encoder );

NIO ByteBuffer is reallocated by MINA ByteBuffer behind the scene if
the encoded data is larger than 16 bytes.  Its limit and capacity will
increase by two times.

There were also some changes due to introduction of auto expand property:

* duplicate(), slice(), asReadOnlyBuffer() is disappeared; I don't see
any easy way to implement this functionality, and it is not used in
most cases especially when all buffers are pooled.
* autoExpand property replaces fork( int capacity ) method.
* String getter/putter have been revamped.

I hope you like all this improvements.

what we call human nature is actually human habit

View raw message