Ensures there is enough space in the buffer for the given number of additional bytes.
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;
    }
562129
public void put(byte[] source)
    {
        // If the buffer is small.
        if (mBuffer.capacity() < (mLength + source.length))
        {
            expandBuffer(mLength + source.length + ADDITIONAL_BUFFER_SIZE);
        }

        mBuffer.put(source);
        mLength += source.length;
    }
879630
public Buffer capacity(int 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((int) Math.min(Memory.Util.toPow2(offset(capacity)), Integer.MAX_VALUE));
      }
      this.capacity = capacity;
    }
    return this;
  }
292873
public void ensureCapacity (int additionalCapacity) {
		int sizeNeeded = size + additionalCapacity;
		if (sizeNeeded >= threshold) resize(ObjectMap.nextPowerOfTwo((int)(sizeNeeded / loadFactor)));
	}
481229
def append(self, data):
    """"""
    data_length = len(data)
    if self._size + data_length > self._flush_size:
      self.flush()

    if not self._exclusive and data_length > _FILE_POOL_MAX_SIZE:
      raise errors.Error(
          "Too big input %s (%s)."  % (data_length, _FILE_POOL_MAX_SIZE))
    else:
      self._buffer.append(data)
      self._size += data_length

    if self._size > self._flush_size:
      self.flush()
834208
public void ensureCapacity(int capacity) {
        if (capacity > data.length) {
            int newCap = Math.max(data.length << 1, capacity);
            int[] tmp = new int[newCap];
            System.arraycopy(data, 0, tmp, 0, data.length);
            data = tmp;
        }
    }
134780
private int ensureBuffer(int offset, int length) throws IOException {
		final int lastPos = offset + length - 1;
		final int desiredSize = ((lastPos / BUFFER_SIZE) + 1) * BUFFER_SIZE;
		final int currentSize = this.buffer.length;

		if (desiredSize > currentSize) {
			final byte[] readBuffer = new byte[desiredSize - currentSize];
			final int count = this.in.read(readBuffer);

			if (count > 0) {
				final byte[] newBuffer = new byte[currentSize + count];
				System.arraycopy(this.buffer, 0, newBuffer, 0, currentSize);
				System.arraycopy(readBuffer, 0, newBuffer, currentSize, count);
				this.buffer = newBuffer;
			}
			return (lastPos < this.buffer.length) ? length : length - (lastPos - this.buffer.length + 1);
		}
		return length;
	}
572893
public WrappedByteBuffer put(byte[] v, int offset, int length) {
        _autoExpand(length);
        for (int i = 0; i < length; i++) {
            _buf.put(v[offset + i]);
        }
        return this;
    }
972766
protected void ensureCapacityUnsafe(int addBytes) {
		int newCapacity = writerIndex() + addBytes;
		if (newCapacity > capacity()) {
			byte[] tmp = new byte[newCapacity * 3 / 2];
			System.arraycopy(array, 0, tmp, 0, writerIndex());
			array = tmp;
		}
		// int size = writableBytes();
		// if (minWritableBytes <= size) {
		// return;
		// }
		// int addSize = minWritableBytes - size;
		// array = Arrays.copyOf(array, array.length + addSize);
	}
791063
private void verifyBufferSize(int sz)
	{
		if (sz > buf.length)
		{
			byte[] old = buf;
			buf = new byte[Math.max(sz, 2 * buf.length)];
			System.arraycopy(old, 0, buf, 0, old.length);
			old = null;
		}
	}
693208
private void ensureCapacity(int requestedCapacity) {

        if (requestedCapacity > getCapacity()) {
            int newCapacity = getCapacity();
            while (requestedCapacity > newCapacity) {
                newCapacity = (newCapacity * 3) / 2;
            }
            reallocateBuffer(newCapacity);
        }
    }
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;
        }
    }
650397
private void checkWrite(int size) {
    // If the buffer does not have enough bytes remaining, attempt to discard some of the read bytes.
    // It is possible that the buffer could discard 0 bytes, so we ensure the buffer is writable after
    // discarding some read bytes, and if not discard all read bytes.
    if (buffer.writerIndex() + size > buffer.maxCapacity()) {
      buffer.discardSomeReadBytes();
      if (buffer.writerIndex() + size > buffer.maxCapacity()) {
        buffer.discardReadBytes();
      }
    }
  }
175234
void increase() {
        // double the size
        length <<= 1;
        // There is no need to preserve what was in the memory before.
        ByteBuffer buffer = Buffer.allocateDirectWithNativeOrder(calculateBufferCapacity(length));
        Buffer.free(memory);
        memory = buffer;
        memoryAddress = Buffer.memoryAddress(buffer);
    }
1009007
def resize_bytes(self, size):
        
        Buffer.resize_bytes(self, size)
        self._size = size // self.itemsize
568085
public static ByteBuffer allocate(int capacity) {
        ByteBuffer buf = ByteBuffer.allocate(capacity);
        buf.limit(0);
        return buf;
    }
972343
function PrependLength(buffer, len) {
  let lenBuf = new Buffer(4);
  lenBuf.writeUInt32LE(len, 0);
  return Buffer.concat([lenBuf, buffer], buffer.length + 4);
}