Increases the buffer's capacity by the given amount.

@param additionalCapacity
The amount by which the buffer's capacity should be increased.
353757
@SuppressWarnings("unchecked")
    public synchronized void expand(int additionalCapacity) {
        if (additionalCapacity <= 0) {
            throw new IllegalArgumentException();
        }

        int capacityBefore = buffer.length;
        synchronized (lock) { // D312598
            int capacityAfter = buffer.length;
            //Check that no one was expanding while we waited on this lock
            if (capacityAfter == capacityBefore) {
                final Object[] newBuffer = new Object[buffer.length + additionalCapacity];

                // PK53203 - put() acquires two locks in sequence.  First, it acquires
                // the insert lock to update putIndex.  Then, it drops the insert lock
                // and acquires the extract lock to update numberOfUsedSlots.  As a
                // result, there is a window where putIndex has been updated, but
                // numberOfUsedSlots has not.  Consequently, even though we have
                // acquired both locks in this method, we cannot rely on the values in
                // numberOfUsedSlots; we can only rely on putIndex and takeIndex.

                if (putIndex > takeIndex) {
                    // The contents of the buffer do not wrap round
                    // the end of the array. We can move its contents
                    // into the new expanded buffer in one go.

                    int used = putIndex - takeIndex;
                    System.arraycopy(buffer, takeIndex, newBuffer, 0, used);
                    putIndex = used;

                    // PK53203.1 - If putIndex == takeIndex, then the buffer is either
                    // completely full or completely empty.  If it is completely full, then
                    // we need to copy and adjust putIndex.  Otherwise, we need to set
                    // putIndex to 0.
                } else if (putIndex != takeIndex || buffer[takeIndex] != null) {
                    // The contents of the buffer wrap round the end
                    // of the array. We have to perform two copies to
                    // move its contents into the new buffer.

                    int used = buffer.length - takeIndex;
                    System.arraycopy(buffer, takeIndex, newBuffer, 0, used);
                    System.arraycopy(buffer, 0, newBuffer, used, putIndex);
                    putIndex += used;
                } else {
                    putIndex = 0;
                }

                // The contents of the buffer now begin at 0 - update the head pointer.

                takeIndex = 0;

                // The buffer's capacity has been increased so update the count of the
                // empty slots to reflect this.
                buffer = (T[]) newBuffer;
            }
        } // D312598
    }
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;
        }
    }
1146752
public void ensureCapacity(int minCapacity) {
    modCount++;
    int oldCapacity = data.length;
    if (minCapacity > oldCapacity) {
      Object oldData[] = data;
      int newCapacity = (oldCapacity * 3) / 2 + 1;
      if (newCapacity < minCapacity)
        newCapacity = minCapacity;
      // minCapacity is usually close to size, so this is a win:
      data = Arrays.copyOf(data, newCapacity);
    }
  }
185241
public void setAdditionalTreatments(java.util.Collection<WriteTreatmentResource> additionalTreatments) {
        if (additionalTreatments == null) {
            this.additionalTreatments = null;
            return;
        }

        this.additionalTreatments = new java.util.ArrayList<WriteTreatmentResource>(additionalTreatments);
    }
371353
@Override
    @SuppressWarnings("unchecked")
    protected void ensureCapacity(int capacity) {
        checkCapacity(capacity);
        ArrayHandle[] newArray = (ArrayHandle[]) Array.newInstance(ArrayHandle.class, capacity + 1);
        System.arraycopy(array, 1, newArray, 1, size);
        array = newArray;
    }
379147
public void setCapacity(int new_cap) {
    if (new_cap != getCapacity()) {
      byte[] new_data = new byte[new_cap];
      if (new_cap < size) {
        size = new_cap;
      }
      if (size != 0) {
        System.arraycopy(bytes, 0, new_data, 0, size);
      }
      bytes = new_data;
    }
  }
914276
public void append(final StringBuffer sb) {
        if (sb == null) {
            return;
        }
        provideCapacity(length + sb.length());
        sb.getChars(0, sb.length(), c, length);
        length += sb.length();
    }
424113
public void updateCapacityBytes(Map<String, Long> capacityBytesOnTiers) {
    mCapacityBytes = 0;
    mTotalBytesOnTiers = capacityBytesOnTiers;
    for (long t : mTotalBytesOnTiers.values()) {
      mCapacityBytes += t;
    }
  }
975302
private void expand(int i) {
        /* Can the buffer handle @i more bytes, if not expand it */
        if (count + i <= buf.length) {
            return;
        }
        byte[] newbuf = mPool.getBuf((count + i) * 2);
        System.arraycopy(buf, 0, newbuf, 0, count);
        mPool.returnBuf(buf);
        buf = newbuf;
    }
680477
public void add(byte b) throws BufferIsFullException {
        if (isFull()) {
            throw new BufferIsFullException("Buffer is full and has reached maximum capacity (" + capacity() + ")");
        }

        // buffer is not full
        this.buffer[this.currentWritePosition] = b;
        this.currentWritePosition = (this.currentWritePosition + 1) % this.buffer.length;
        this.currentBufferSize += 1;
    }
1363771
@Check(CheckType.NORMAL)
	public void checkMultipleCapacityUses(SarlCapacityUses uses) {
		if (!isIgnored(REDUNDANT_CAPACITY_USE)) {
			final XtendTypeDeclaration declaringType = uses.getDeclaringType();
			if (declaringType != null) {
				final Set<String> previousCapacityUses = doGetPreviousCapacities(uses,
						declaringType.getMembers().iterator());
				int index = 0;
				for (final JvmTypeReference capacity : uses.getCapacities()) {
					if (previousCapacityUses.contains(capacity.getIdentifier())) {
						addIssue(MessageFormat.format(
								Messages.SARLValidator_79,
								capacity.getSimpleName()),
								uses,
								SARL_CAPACITY_USES__CAPACITIES,
								index,
								REDUNDANT_CAPACITY_USE,
								capacity.getSimpleName());
					} else {
						previousCapacityUses.add(capacity.getIdentifier());
					}
					++index;
				}
			}
		}
	}
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;
        }
    }
737504
protected void resize (int newCapacity) {
		@SuppressWarnings("unchecked")
		T[] newItems = (T[])ArrayReflection.newInstance(items.getClass().getComponentType(), newCapacity);
		if (tail > head) {
			System.arraycopy(items, head, newItems, 0, size);
		} else if (size > 0) { // NOTE: when head == tail the buffer can be empty or full
			System.arraycopy(items, head, newItems, 0, items.length - head);
			System.arraycopy(items, 0, newItems, items.length - head, tail);
		}
		head = 0;
		tail = size;
		items = newItems;
	}
348416
private void ensureCapacity(int minCapacity) {
		long currentCapacity = data.length;

		if (minCapacity <= currentCapacity) {
			return;
		}

		// increase capacity by at least ~50%
		long expandedCapacity = Math.max(minCapacity, currentCapacity + (currentCapacity >> 1));
		int newCapacity = (int) Math.min(MAX_ARRAY_SIZE, expandedCapacity);

		if (newCapacity < minCapacity) {
			// throw exception as unbounded arrays are not expected to fill
			throw new RuntimeException("Requested array size " + minCapacity + " exceeds limit of " + MAX_ARRAY_SIZE);
		}

		data = Arrays.copyOf(data, newCapacity);
	}
285377
private void grow(int minCapacity) {
		int oldCapacity = segment.size();
		int newCapacity = oldCapacity + (oldCapacity >> 1);
		if (newCapacity - minCapacity < 0) {
			newCapacity = minCapacity;
		}
		segment = MemorySegmentFactory.wrap(Arrays.copyOf(segment.getArray(), newCapacity));
		afterGrow();
	}
1096195
private void ensureCapacity(int wordsRequired)
  {
    if (words.length >= wordsRequired) {
      return;
    }
    int newLength = Math.max(words.length << 1, wordsRequired);
    words = Arrays.copyOf(words, newLength);
  }
90830
private void growToSize (int minCapacity) {
		if (minCapacity < 0) // overflow
			throw new GdxRuntimeException("Capacity upper limit exceeded.");
		int oldCapacity = queue.length;
		// Double size if small; else grow by 50%
		int newCapacity = (int)((oldCapacity < 64) ? ((oldCapacity + 1) * CAPACITY_RATIO_HI) : (oldCapacity * CAPACITY_RATIO_LOW));
		if (newCapacity < 0) // overflow
			newCapacity = Integer.MAX_VALUE;
		if (newCapacity < minCapacity) newCapacity = minCapacity;
		Object[] newQueue = new Object[newCapacity];
		System.arraycopy(queue, 0, newQueue, 0, size);
		queue = newQueue;
	}