Ensure that the buffer has at least capacity to hold the target size
359243
@SuppressWarnings("unchecked")
    protected final void ensureCapacity(long targetSize) {
        long capacity = capacity();
        if (targetSize > capacity) {
            inflateSpine();
            for (int i=spineIndex+1; targetSize > capacity; i++) {
                if (i >= spine.length) {
                    int newSpineSize = spine.length * 2;
                    spine = Arrays.copyOf(spine, newSpineSize);
                    priorElementCount = Arrays.copyOf(priorElementCount, newSpineSize);
                }
                int nextChunkSize = chunkSize(i);
                spine[i] = (E[]) new Object[nextChunkSize];
                priorElementCount[i] = priorElementCount[i-1] + spine[i-1].length;
                capacity += nextChunkSize;
            }
        }
    }
934528
private void ensureCapacity(final int index, final int length)
    {
        if (index < 0)
        {
            throw new IndexOutOfBoundsException("index cannot be negative: index=" + index);
        }

        final long resultingPosition = index + (long)length;
        final int currentCapacity = capacity;
        if (resultingPosition > currentCapacity)
        {
            if (currentCapacity >= MAX_BUFFER_LENGTH)
            {
                throw new IndexOutOfBoundsException(
                    "index=" + index + " length=" + length + " maxCapacity=" + MAX_BUFFER_LENGTH);
            }

            final int newCapacity = calculateExpansion(currentCapacity, (int)resultingPosition);
            final ByteBuffer newBuffer = ByteBuffer.allocateDirect(newCapacity);

            getBytes(0, newBuffer, 0, capacity);

            address = address(newBuffer);
            capacity = newCapacity;
            byteBuffer = newBuffer;
        }
    }
481921
public void ensureSize(int bufSize, int pre, int post)
        throws IOException
    {
        // Do we have space?
        if (bufSize>_buf.length || pre>_preReserve || post>_postReserve)
        {
            // Make a bigger buffer if we are allowed.
            if (_fixed)
                throw new IllegalStateException("Fixed");

            byte[] old=_buf;
            _buf=ByteArrayPool.getByteArray(bufSize);

            if (_pos>_start)
                System.arraycopy(old,_start,_buf,pre,_pos-_start);
            if (!_resized)
                ByteArrayPool.returnByteArray(old);
            
            _end=_buf.length-post;
            _preReserve=pre;
            _start=pre;
            _pos=pre;
            _postReserve=post;
        }
    }
397930
private void ensureAvail(int n) {
    if (pos + n >= buf.length) {
      int newSize = Math.max(pos + n, buf.length * 2);
      buf = Arrays.copyOf(buf, newSize);
    }
  }
711983
private void ensureCapacity (int n)    {
        if (n <= 0) {
            return;
        }
        int max;
        if (data == null || data.length == 0) {
            max = 25;
        }
        else if (data.length >= n * 5) {
            return;
        }
        else {
            max = data.length;
        }
        while (max < n * 5) {
            max *= 2;
        }

        String newData[] = new String[max];
        if (length > 0) {
            System.arraycopy(data, 0, newData, 0, length*5);
        }
        data = newData;
    }
1009007
def resize_bytes(self, size):
        
        Buffer.resize_bytes(self, size)
        self._size = size // self.itemsize
839467
protected void ensureCapacity(int minNbRuns) {
    final int minCapacity = 2 * minNbRuns;
    if (valueslength.length < minCapacity) {
      int newCapacity = valueslength.length;
      while (newCapacity < minCapacity) {
        newCapacity = (newCapacity == 0) ? DEFAULT_INIT_SIZE
            : newCapacity < 64 ? newCapacity * 2
                : newCapacity < 1024 ? newCapacity * 3 / 2 : newCapacity * 5 / 4;
      }
      short[] nv = new short[newCapacity];
      copyValuesLength(valueslength, 0, nv, 0, nbrruns);
      valueslength = nv;
    }
  }
173669
private void setAndAllocateBuffer(int sizeToAllocate) {
        
        if(_buffer == null){
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){
                Tr.debug(tc, "setAndAllocateBuffer, Buffer is null, size to allocate is : " + sizeToAllocate);
            }
            _buffer = allocateBuffer(sizeToAllocate);
        }
        
        configurePreReadBuffer(sizeToAllocate);
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){  
          Tr.debug(tc, "setAndAllocateBuffer, Setting the buffer : " + _buffer );         
        }
        
        _tcpContext.getReadInterface().setBuffer(_buffer);
    }
605497
public final void ensureCapacity( int targetCapacity )
    {
        if (targetCapacity > capacity)
        {
            int newLength = Math.max(capacity << 1, targetCapacity);
            byte[] copy = new byte[newLength];
            System.arraycopy(buf, 0, copy, 0, capacity);
            buf = copy;
            capacity = newLength;
        }
    }
1262512
private void ensureCapacity(int newSize) {
        int oldSize;
        if ((oldSize = branchingEnumerators.length) < newSize) {
            branchingEnumerators = Arrays.copyOfRange(branchingEnumerators, 0, newSize);
            for (int i = oldSize; i < newSize; ++i)
                branchingEnumerators[i] = new BranchingEnumerator<>(reference, guide);
        }
    }
198526
@SuppressWarnings("unchecked")
    private void ensureCapacity(int capacity) {
        checkCapacity(capacity);
        Elem<V>[] newArray = (Elem<V>[]) Array.newInstance(Elem.class, capacity + 2);
        if (newArray.length >= array.length) {
            System.arraycopy(array, 0, newArray, 0, array.length);
            for (int i = array.length; i < newArray.length; i++) {
                newArray[i] = new Elem<V>(SUP_KEY, null);
            }
        } else {
            System.arraycopy(array, 0, newArray, 0, newArray.length);
        }
        array = newArray;
    }
349433
protected void ensureBufferSpace(int expectedAdditions) {
    final int bufferLen = buffer.length;
    final int elementsCount = size();

    if (elementsCount + expectedAdditions >= bufferLen) {
      final int emptySlot = 1; // deque invariant: always an empty slot.
      final int newSize = resizer.grow(bufferLen, elementsCount + emptySlot, expectedAdditions);
      assert newSize >= (elementsCount + expectedAdditions + emptySlot) : "Resizer failed to"
          + " return sensible new size: " + newSize + " <= " + (elementsCount + expectedAdditions);

      try {
        final KType[] newBuffer = Intrinsics.<KType> newArray(newSize);
        if (bufferLen > 0) {
          toArray(newBuffer);
          tail = elementsCount;
          head = 0;
        }
        this.buffer = newBuffer;
      } catch (OutOfMemoryError e) {
        throw new BufferAllocationException(
            "Not enough memory to allocate new buffers: %,d -> %,d", 
            e, bufferLen, newSize);
      }
    }
  }
756520
public Buffer capacity(long capacity) {
    if (capacity > maxCapacity) {
      throw new IllegalArgumentException("capacity cannot be greater than maximum capacity");
    } else if (capacity < this.capacity) {
      throw new IllegalArgumentException("capacity cannot be decreased");
    } else if (capacity != this.capacity) {
      // It's possible that the bytes could already meet the requirements of the capacity.
      if (offset(capacity) > bytes.size()) {
        bytes.resize(Memory.Util.toPow2(offset(capacity)));
      }
      this.capacity = capacity;
    }
    return this;
  }
1299284
public void ensureCapacity(int n)
        throws IOException
    {
        // Do we have space?
        if (n>capacity())
        {
            // Make a bigger buffer if we are allowed.
            if (_fixed)
                throw new IllegalStateException("Fixed");
                
            int new_size = ((n+_preReserve+_postReserve+4095)/4096)*4096;
            
            byte[] old = _buf;
            _buf = new byte[new_size];
            if (_pos>_start)
                System.arraycopy(old,_start,_buf,_start,_pos-_start);
            if (!_resized)
                ByteArrayPool.returnByteArray(old);
                
            _end=_buf.length-_postReserve;
            _resized=true;
        }
    }
955379
private static byte[] ensureCapacity(byte[] buf, int needed) {
        if (buf.length <= needed) {
            byte[] old = buf;
            buf = new byte[Integer.highestOneBit(needed) << 1];
            System.arraycopy(old, 0, buf, 0, old.length);
        }
        return buf;
    }
1205672
public void ensureSize(int maxPartitionOrder) {
        if (capacityByOrder >= maxPartitionOrder) return;
        parameters = new int[(1 << maxPartitionOrder)];
        rawBits = new int[(1 << maxPartitionOrder)]; 
        capacityByOrder = maxPartitionOrder;
    }
975494
void resize(int size, byte value)
    {
        if (size > _capacity)
        {
            resizeBuf(size);
        }
        while (_size < size)
        {
            _buf[_size++] = value;
        }
    }