{@link ChannelBuffer} buffer = ...;for (int i = 0; i < buffer.capacity(); i ++) { byte b = buffer.getByte(i); System.out.println((char) b); }
+-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | | | (CONTENT) | | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity
// Iterates the readable bytes of a buffer. {@link ChannelBuffer} buffer = ...;while (buffer.readable()) { System.out.println(buffer.readByte()); }
// Fills the writable bytes of a buffer with random integers. {@link ChannelBuffer} buffer = ...;while (buffer.writableBytes() >= 4) { buffer.writeInt(random.nextInt()); }
BEFORE discardReadBytes() +-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity AFTER discardReadBytes() +------------------+--------------------------------------+ | readable bytes | writable bytes (got more space) | +------------------+--------------------------------------+ | | | readerIndex (0) <= writerIndex (decreased) <= capacityPlease note that there is no guarantee about the content of writable bytes after calling {@link #discardReadBytes()}. The writable bytes will not be moved in most cases and could even be filled with completely different data depending on the underlying buffer implementation.
BEFORE clear() +-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity AFTER clear() +---------------------------------------------------------+ | writable bytes (got more space) | +---------------------------------------------------------+ | | 0 = readerIndex = writerIndex <= capacity
{@link ChannelBuffer} buffer = ...;for (int i = 0; i < buffer.capacity(); i ++) { byte b = buffer.getByte(i); System.out.println((char) b); }
+-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | | | (CONTENT) | | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity
If there's not enough content left, {@link IndexOutOfBoundsException} israised. The default value of newly allocated, wrapped or copied buffer's {@link #readerIndex() readerIndex} is {@code 0}.
// Iterates the readable bytes of a buffer. {@link ChannelBuffer} buffer = ...;while (buffer.readable()) { System.out.println(buffer.readByte()); }
If there's not enough writable bytes left, {@link IndexOutOfBoundsException}is raised. The default value of newly allocated buffer's {@link #writerIndex() writerIndex} is {@code 0}. The default value of wrapped or copied buffer's {@link #writerIndex() writerIndex} is the{@link #capacity() capacity} of the buffer.
// Fills the writable bytes of a buffer with random integers. {@link ChannelBuffer} buffer = ...;while (buffer.writableBytes() >= 4) { buffer.writeInt(random.nextInt()); }
BEFORE discardReadBytes() +-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity AFTER discardReadBytes() +------------------+--------------------------------------+ | readable bytes | writable bytes (got more space) | +------------------+--------------------------------------+ | | | readerIndex (0) <= writerIndex (decreased) <= capacityPlease note that there is no guarantee about the content of writable bytes after calling {@link #discardReadBytes()}. The writable bytes will not be moved in most cases and could even be filled with completely different data depending on the underlying buffer implementation.
BEFORE clear() +-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity AFTER clear() +---------------------------------------------------------+ | writable bytes (got more space) | +---------------------------------------------------------+ | | 0 = readerIndex = writerIndex <= capacity
If you are decoding variable length data such as NUL-terminated string, you will find {@link #bytesBefore(byte)} also useful.
In case a completely fresh copy of an existing buffer is required, please call {@link #copy()} method instead.
ChannelBuffer buffer = ...; for (int i = 0; i < buffer.capacity(); i ++) { byte b = array.getByte(i); System.out.println((char) b); }
+-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable space | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity
If there's no more readable bytes left, {@link IndexOutOfBoundsException}is raised. The default value of newly allocated, wrapped or copied buffer's {@link #readerIndex() readerIndex} is {@code 0}.
// Iterates the readable bytes of a buffer. ChannelBuffer buffer = ...; while (buffer.isReadable()) { System.out.println(buffer.readByte()); }
If there's no more writable space left, {@link IndexOutOfBoundsException}is raised. The default value of newly allocated buffer's {@link #writerIndex() writerIndex} is {@code 0}. The default value of wrapped or copied buffer's {@link #writerIndex() writerIndex} is the{@link #capacity() capacity} of the buffer.
// Fills the writable space of a buffer with random integers. ChannelBuffer buffer = ...; while (buffer.writableBytes() >= 4) { buffer.writeInt(random.nextInt()); }
BEFORE discardReadBytes() +-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable space | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity AFTER discardReadBytes() +------------------+--------------------------------------+ | readable bytes | writable space (got more space) | +------------------+--------------------------------------+ | | | readerIndex (0) <= writerIndex (decreased) <= capacity
ChannelBuffer buffer = ...; for (int i = 0; i < buffer.capacity(); i ++) { byte b = array.getByte(i); System.out.println((char) b); }
+-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | | | (CONTENT) | | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity
If there's not enough content left, {@link IndexOutOfBoundsException} israised. The default value of newly allocated, wrapped or copied buffer's {@link #readerIndex() readerIndex} is {@code 0}.
// Iterates the readable bytes of a buffer. ChannelBuffer buffer = ...; while (buffer.readable()) { System.out.println(buffer.readByte()); }
If there's not enough writable bytes left, {@link IndexOutOfBoundsException}is raised. The default value of newly allocated buffer's {@link #writerIndex() writerIndex} is {@code 0}. The default value of wrapped or copied buffer's {@link #writerIndex() writerIndex} is the{@link #capacity() capacity} of the buffer.
// Fills the writable bytes of a buffer with random integers. ChannelBuffer buffer = ...; while (buffer.writableBytes() >= 4) { buffer.writeInt(random.nextInt()); }
BEFORE discardReadBytes() +-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity AFTER discardReadBytes() +------------------+--------------------------------------+ | readable bytes | writable bytes (got more space) | +------------------+--------------------------------------+ | | | readerIndex (0) <= writerIndex (decreased) <= capacity
BEFORE clear() +-------------------+------------------+------------------+ | discardable bytes | readable bytes | writable bytes | +-------------------+------------------+------------------+ | | | | 0 <= readerIndex <= writerIndex <= capacity AFTER clear() +---------------------------------------------------------+ | writable bytes (got more space) | +---------------------------------------------------------+ | | 0 = readerIndex = writerIndex <= capacity
In case a completely fresh copy of an existing buffer is required, please call {@link #copy()} method instead.
|
|
|
|
|
|
|
|
|
|
|
|