protected void checkSizeAndGrow(int extra) {
    long capacityNeeded = curBuf.position() + (long) extra;
    if (capacityNeeded > curBuf.limit()) {
      // guarantee it's possible to fit
      if (capacityNeeded > MAX_ARRAY_SIZE) {
        throw new BufferOverflowException();
      }
      // double until hit the cap
      long nextCapacity = Math.min(curBuf.capacity() * 2L, MAX_ARRAY_SIZE);
      // but make sure there is enough if twice the existing capacity is still too small
      nextCapacity = Math.max(nextCapacity, capacityNeeded);
      ByteBuffer newBuf = allocate((int) nextCapacity, curBuf.isDirect());
      curBuf.flip();
      ByteBufferUtils.copyFromBufferToBuffer(curBuf, newBuf);
      curBuf = newBuf;
    }
  }
This flips the underlying BB so be sure to use it _last_!
hbase-common/src/main/java/org/apache/hadoop/hbase/io/ByteBufferOutputStream.java