List of utility methods to do ByteBuffer Expand
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(); ... |