code: @Override
      public AbstractIoBufferEx capacity(int newCapacity, IoBufferAllocatorEx<?> reallocator) {
          if (!recapacityAllowed) {
              throw new IllegalStateException(
                      "Derived buffers and their parent can't be expanded.");
          }
  
          // Allocate a new buffer and transfer all settings to it.
          if (newCapacity > capacity()) {
              // Expand:
              //// Save the state.
              int pos = position();
              int limit = limit();
              ByteOrder bo = order();
  
              //// Reallocate.
              ByteBuffer oldBuf = buf();
              ByteBuffer newBuf = reallocator.allocate(newCapacity, flags());
              oldBuf.clear();
              newBuf.put(oldBuf);
              buf(newBuf);
  
              //// Restore the state.
              buf().limit(limit);
              if (mark >= 0) {
                  buf().position(mark);
                  buf().mark();
              }
              buf().position(pos);
              buf().order(bo);
          }
  
          return this;
      }
docs: {@inheritDoc}