code: 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;
          }
      }
docs: Ensure that the buffer internal capacity is at least targetCapacity
  @param targetCapacity the expected capacity