code: private void consolidateIfNeeded() {
          // Consolidate if the number of components will exceed the allowed maximum by the current
          // operation.
          int size = componentCount;
          if (size > maxNumComponents) {
              final int capacity = components[size - 1].endOffset;
  
              ByteBuf consolidated = allocBuffer(capacity);
              lastAccessed = null;
  
              // We're not using foreach to avoid creating an iterator.
              for (int i = 0; i < size; i ++) {
                  components[i].transferTo(consolidated);
              }
  
              components[0] = new Component(consolidated, 0, 0, capacity, consolidated);
              removeCompRange(1, size);
          }
      }
docs: This should only be called as last operation from a method as this may adjust the underlying
  array of components and so affect the index etc.