code: 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;
      }
    }
docs: Change the capacity of the backing storage.
  The data is preserved.
  @param new_cap The new capacity in bytes.