code: private void expandIfNecessary(int size) {
      if (bytes.length >= size) {
        // no need to expand
        return;
      }
      // either double, or expand to fit size
      int newlength = Math.max(2 * bytes.length, size);
      bytes = Arrays.copyOf(bytes, newlength);
    }
docs: Expand the underlying byte array to fit size bytes.