code: public void ensureHasSpace(int numBytesToAdd) {
      if (numBytesToAdd < 0) {
        throw new IllegalArgumentException("Number of bytes can't be negative");
      }
      int capacityLeft = getCapacityLeft();
      if (capacityLeft < numBytesToAdd) {
        grow(numBytesToAdd - capacityLeft, true);
      }
    }
docs: Checks if there is enough space in the buffer to write N additional bytes. Will grow the buffer
  if necessary. It takes current position in the buffer into account.
  
  @param numBytesToAdd the number of bytes you want to add to the buffer