retain(int of, int cb)
Starting with the byte at offset of, retain cb bytes in this WriteBuffer, such that the byte at offset of is shifted to offset 0, the byte at offset of + 1 is shifted to offset 1, and so on up to the byte at offset of + cb - 1, which is shifted to offset cb - 1.

setLength

Reconfigure the length of the buffer. The length must not be longer than the available capacity.

Parameters:

cb - the new length of the buffer

retain

public void retain(int of,
int cb)

Starting with the byte at offset of, retain cb bytes in this WriteBuffer, such that the byte at offset of is shifted to offset 0, the byte at offset of + 1 is shifted to offset 1, and so on up to the byte at offset of + cb - 1, which is shifted to offset cb - 1. After this method, the length of the buffer as indicated by the WriteBuffer.length() method will be equal to cb.

If cb is zero, then this method will have the same effect as clear. If of is zero, then this method will have the effect of truncating the data in the buffer, but no bytes will be shifted within the buffer.

The effect on the capacity of the buffer is implementation-specific; some implementations are expected to retain the same capacity while others are expected to shrink accordingly.

of - the offset of the first byte within the WriteBuffer that will be retained

cb - the number of bytes to retain

getCapacity

public int getCapacity()

Determine the number of bytes that the buffer can hold without resizing itself. In other words, a WriteBuffer has getCapacity() - WriteBuffer.length() bytes that can be written to it without overflowing the current underlying buffer allocation. Since the buffer is an abstract concept, the actual mechanism for the underlying buffer is not known, but it could be a Java NIO buffer, or a byte array, etc.

Note that if the maximum size returned by WriteBuffer.getMaximumCapacity() is greater than the current size returned by this method, then the WriteBuffer will automatically resize itself to allocate more space when the amount of data written to it passes the current size.

getBufferOutput

Get a BufferOutput object to write data to this buffer starting at a particular offset.

Note that each call to this method will return a new BufferOutput object, with the possible exception being that a zero-length non-resizing WriteBuffer could always return the same instance (since it is not writable).

getUnsafeReadBuffer

Get a ReadBuffer object to read data from this buffer. This method is not guaranteed to return a snapshot of this buffer's data, nor is it guaranteed to return a live view of this buffer, which means that subsequent changes to this WriteBuffer may or may not affect the contents and / or the length of the returned ReadBuffer.

getUnsafeWriteBuffer

Create a "shallow clone" of the ByteBufferWriteBuffer that uses the same underlying memory but through a different (a duplicate) ByteBuffer. This method is primarily intended to allow multiple threads to be able to write to the same block of NIO memory, by creating shallow clones of the ByteBufferWriteBuffer, one for each thread, since the ByteBuffer itself is not thread safe.

Returns:

a ByteBufferWriteBuffer that shares the same underlying memory, but does not share the same NIO ByteBuffer