code: WrappedByteBuffer expandAt(int i, int expectedRemaining) {
          if ((i + expectedRemaining) <= _buf.limit()) {
              return this;
          } else {
              if ((i + expectedRemaining) <= _buf.capacity()) {
                  _buf.limit(i + expectedRemaining);
              } else {
                  // reallocate the underlying byte buffer and keep the original buffer
                  // intact. The resetting of the position is required because, one
                  // could be in the middle of a read of an existing buffer, when they
                  // decide to over write only few bytes but still keep the remaining
                  // part of the buffer unchanged.
                  int newCapacity = _buf.capacity()
                          + ((expectedRemaining > INITIAL_CAPACITY) ? expectedRemaining : INITIAL_CAPACITY);
                  java.nio.ByteBuffer newBuffer = java.nio.ByteBuffer.allocate(newCapacity);
                  _buf.flip();
                  newBuffer.put(_buf);
                  _buf = newBuffer;
              }
          }
  
          return this;
      }
docs: Expands the buffer to support the expected number of remaining bytes at the specified index.
  
  @param index the index
  @param expectedRemaining the expected number of remaining bytes
  
  @return the buffer