Java Utililty Methods ByteBuffer Expand

List of utility methods to do ByteBuffer Expand

Description

The list of methods to do ByteBuffer Expand are organized into topic(s).

Method

ByteBufferexpand(ByteBuffer bb, int minSize, int maxSize)
Ensure that specified buffer has at least enough capacity to accommodate 'minSize' additional bytes, but not more than 'maxSize' additional bytes.
if (maxSize != -1 && maxSize < minSize) {
    throw new IllegalArgumentException("maxSize < minSize");
if (bb == null) {
    int size = Math.max(minSize, INITIAL_CAPACITY);
    if (maxSize != -1 && size > maxSize)
        size = maxSize;
    return ByteBuffer.allocate(size);
...
ByteBufferexpandBuffer(ByteBuffer existingBuffer, int additionalRequired)
expand Buffer
int pos = existingBuffer.position();
if ((pos + additionalRequired) > existingBuffer.limit()) {
    if ((pos + additionalRequired) < existingBuffer.capacity()) {
        existingBuffer.limit(pos + additionalRequired);
    } else {
        int newCapacity = existingBuffer.capacity() + additionalRequired;
        java.nio.ByteBuffer newBuffer = java.nio.ByteBuffer.allocate(newCapacity);
        existingBuffer.flip();
...