This class provides a few wrap(...) methods that wraps any NIO buffers and byte arrays.
Writing variable-length data using NIO ByteBuffers is not really easy, and it is because its size is fixed. {@link IoBuffer} introducesautoExpand property. If autoExpand property is true, you never get {@link BufferOverflowException} or{@link IndexOutOfBoundsException} (except when index is negative). Itautomatically expands its capacity and limit value. For example:
String greeting = messageBundle.getMessage("hello"); IoBuffer buf = IoBuffer.allocate(16); // Turn on autoExpand (it is off by default) buf.setAutoExpand(true); buf.putString(greeting, utf8encoder);The underlying {@link ByteBuffer} is reallocated by {@link IoBuffer} behindthe scene if the encoded data is larger than 16 bytes in the example above. Its capacity will double, and its limit will increase to the last position the string is written.
You might also want to decrease the capacity of the buffer when most of the allocated memory area is not being used. {@link IoBuffer} providesautoShrink property to take care of this issue. If autoShrink is turned on, {@link IoBuffer} halves the capacity of thebuffer when {@link #compact()} is invoked and only 1/4 or less of the currentcapacity is being used.
You can also {@link #shrink()} method manually to shrink the capacity of thebuffer.
The underlying {@link ByteBuffer} is reallocated by {@link IoBuffer} behindthe scene, and therefore {@link #buf()} will return a different{@link ByteBuffer} instance once capacity changes. Please also note{@link #compact()} or {@link #shrink()} will not decrease the capacity if thenew capacity is less than the {@link #minimumCapacity()} of the buffer.
Derived buffers are the buffers which were created by {@link #duplicate()}, {@link #slice()}, or {@link #asReadOnlyBuffer()}. They are useful especially when you broadcast the same messages to multiple {@link IoSession}s. Please note that the buffer derived from and its derived buffers are not both auto-expandable neither auto-shrinkable. Trying to call {@link #setAutoExpand(boolean)} or {@link #setAutoShrink(boolean)} withtrue parameter will raise an {@link IllegalStateException}.
{@link IoBufferAllocator} interface lets you override the default buffermanagement behavior. There are two allocators provided out-of-the-box:
This class provides a few wrap(...) methods that wraps any NIO buffers and byte arrays.
Writing variable-length data using NIO ByteBuffers is not really easy, and it is because its size is fixed. {@link IoBuffer} introducesautoExpand property. If autoExpand property is true, you never get {@link BufferOverflowException} or{@link IndexOutOfBoundsException} (except when index is negative). Itautomatically expands its capacity and limit value. For example:
String greeting = messageBundle.getMessage("hello"); IoBuffer buf = IoBuffer.allocate(16); // Turn on autoExpand (it is off by default) buf.setAutoExpand(true); buf.putString(greeting, utf8encoder);The underlying {@link ByteBuffer} is reallocated by {@link IoBuffer} behindthe scene if the encoded data is larger than 16 bytes in the example above. Its capacity will double, and its limit will increase to the last position the string is written.
You might also want to decrease the capacity of the buffer when most of the allocated memory area is not being used. {@link IoBuffer} providesautoShrink property to take care of this issue. If autoShrink is turned on, {@link IoBuffer} halves the capacity of thebuffer when {@link #compact()} is invoked and only 1/4 or less of the currentcapacity is being used.
You can also {@link #shrink()} method manually to shrink the capacity of thebuffer.
The underlying {@link ByteBuffer} is reallocated by {@link IoBuffer} behindthe scene, and therefore {@link #buf()} will return a different{@link ByteBuffer} instance once capacity changes. Please also note{@link #compact()} or {@link #shrink()} will not decrease the capacity if thenew capacity is less than the {@link #minimumCapacity()} of the buffer.
Derived buffers are the buffers which were created by {@link #duplicate()}, {@link #slice()}, or {@link #asReadOnlyBuffer()}. They are useful especially when you broadcast the same messages to multiple {@link IoSession}s. Please note that the buffer derived from and its derived buffers are not both auto-expandable neither auto-shrinkable. Trying to call {@link #setAutoExpand(boolean)} or {@link #setAutoShrink(boolean)} withtrue parameter will raise an {@link IllegalStateException}.
{@link IoBufferAllocator} interface lets you override the default buffermanagement behavior. There are two allocators provided out-of-the-box:
flush()
. This is necessary to support concurrent reads and writes. There are also current read and write buffers for character-based read/write operations. Note that you cannot mix character reads with byte reads and character writes with byte writes. For example, it is illegal to call write(' ')
and then writeByte(32)
without an explicit {@code flush()}call between the invocations. This class is safe for a concurrent reader and writer. That is, one thread can read while another writes. Multiple readers and multiple writers are not supported. IMPORTANT: It is necessary to call flush()
to ensure that data written to the IOBuffer is available for reading. A maximum IOBuffer size limit can be set by invoking the {@link #setSizeLimit} method. When the limit isexceeded, the contents of the IOBuffer are consumed via a call to the {@link ConsumeCallback#handleConsume(IOBuffer,boolean)}callback. This provides a mechanism to dispense with the contents of the IOBuffer in an application-dependent way. By default, the size limit is set to -1, which allows the IOBuffer to grow without bound.
@see com.google.opengse.iobuffer.IOBufferInputStream
@see com.google.opengse.iobuffer.IOBufferOutputStream
@see com.google.opengse.iobuffer.IOBufferReader
@see com.google.opengse.iobuffer.IOBufferWriter
@author Spencer Kimball
@author Peter Mattis
This class provides a few wrap(...) methods that wraps any NIO buffers and byte arrays.
Writing variable-length data using NIO ByteBuffers is not really easy, and it is because its size is fixed. {@link IoBuffer} introduces autoExpand property. If autoExpand property is true, you never get {@link BufferOverflowException} or{@link IndexOutOfBoundsException} (except when index is negative).It automatically expands its capacity and limit value. For example:
String greeting = messageBundle.getMessage( "hello" ); IoBuffer buf = IoBuffer.allocate( 16 ); // Turn on autoExpand (it is off by default) buf.setAutoExpand( true ); buf.putString( greeting, utf8encoder );The underlying {@link ByteBuffer} is reallocated by {@link IoBuffer} behindthe scene if the encoded data is larger than 16 bytes in the example above. Its capacity will double, and its limit will increase to the last position the string is written.
You might also want to decrease the capacity of the buffer when most of the allocated memory area is not being used. {@link IoBuffer} providesautoShrink property to take care of this issue. If autoShrink is turned on, {@link IoBuffer} halves the capacityof the buffer when {@link #compact()} is invoked and only 1/4 or less ofthe current capacity is being used.
You can also {@link #shrink()} method manually to shrink the capacity ofthe buffer.
The underlying {@link ByteBuffer} is reallocated by {@link IoBuffer} behindthe scene, and therefore {@link #buf()} will return a different{@link ByteBuffer} instance once capacity changes. Please also note{@link #compact()} or {@link #shrink()} will not decrease the capacity ifthe new capacity is less than the {@link #minimumCapacity()} of the buffer.
Derived buffers are the buffers which were created by {@link #duplicate()}, {@link #slice()}, or {@link #asReadOnlyBuffer()}. They are useful especially when you broadcast the same messages to multiple {@link IoSession}s. Please note that the buffer derived from and its derived buffers are not both auto-expandable neither auto-shrinkable. Trying to call {@link #setAutoExpand(boolean)} or {@link #setAutoShrink(boolean)}with true parameter will raise an {@link IllegalStateException}.
{@link IoBufferAllocator} interface lets you override the default buffermanagement behavior. There are two allocators provided out-of-the-box:
This class provides a few wrap(...) methods that wraps any NIO buffers and byte arrays.
Writing variable-length data using NIO ByteBuffers is not really easy, and it is because its size is fixed. {@link IoBuffer} introduces autoExpand property. If autoExpand property is true, you never get {@link BufferOverflowException} or{@link IndexOutOfBoundsException} (except when index is negative).It automatically expands its capacity and limit value. For example:
String greeting = messageBundle.getMessage( "hello" ); IoBuffer buf = IoBuffer.allocate( 16 ); // Turn on autoExpand (it is off by default) buf.setAutoExpand( true ); buf.putString( greeting, utf8encoder );The underlying {@link ByteBuffer} is reallocated by {@link IoBuffer} behindthe scene if the encoded data is larger than 16 bytes in the example above. Its capacity will double, and its limit will increase to the last position the string is written.
You might also want to decrease the capacity of the buffer when most of the allocated memory area is not being used. {@link IoBuffer} providesautoShrink property to take care of this issue. If autoShrink is turned on, {@link IoBuffer} halves the capacityof the buffer when {@link #compact()} is invoked and only 1/4 or less ofthe current capacity is being used.
You can also {@link #shrink()} method manually to shrink the capacity ofthe buffer.
The underlying {@link ByteBuffer} is reallocated by {@link IoBuffer} behindthe scene, and therefore {@link #buf()} will return a different{@link ByteBuffer} instance once capacity changes. Please also note{@link #compact()} or {@link #shrink()} will not decrease the capacity ifthe new capacity is less than the {@link #minimumCapacity()} of the buffer.
Derived buffers are the buffers which were created by {@link #duplicate()}, {@link #slice()}, or {@link #asReadOnlyBuffer()}. They are useful especially when you broadcast the same messages to multiple {@link IoSession}s. Please note that the buffer derived from and its derived buffers are not both auto-expandable neither auto-shrinkable. Trying to call {@link #setAutoExpand(boolean)} or {@link #setAutoShrink(boolean)}with true parameter will raise an {@link IllegalStateException}.
{@link IoBufferAllocator} interface lets you override the default buffermanagement behavior. There are two allocators provided out-of-the-box:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|