Java Utililty Methods ByteBuffer Expand

List of utility methods to do ByteBuffer Expand

  1. HOME
  2. Java
  3. B
  4. ByteBuffer Expand

Description

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

Method

ByteBuffer expand(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);
...
ByteBuffer expandBuffer(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();
...

AltStyle によって変換されたページ (->オリジナル) /