code: private void aggregateAppendOperation(CachedStreamSegmentAppendOperation operation, AggregatedAppendOperation aggregatedAppend) {
          long remainingLength = operation.getLength();
          if (operation.getStreamSegmentOffset() < aggregatedAppend.getLastStreamSegmentOffset()) {
              // The given operation begins before the AggregatedAppendOperation. This is likely due to it having been
              // partially written to Storage prior to some recovery event. We must make sure we only include the part that
              // has not yet been written.
              long delta = aggregatedAppend.getLastStreamSegmentOffset() - operation.getStreamSegmentOffset();
              remainingLength -= delta;
              log.debug("{}: Skipping {} bytes from the beginning of '{}' since it has already been partially written to Storage.", this.traceObjectId, delta, operation);
          }
  
          // We only include the attributes in the first AggregatedAppend of an Append (it makes no difference if we had
          // chosen to do so in the last one, as long as we are consistent).
          aggregatedAppend.includeAttributes(getExtendedAttributes(operation));
          while (remainingLength > 0) {
              // All append lengths are integers, so it's safe to cast here.
              int lengthToAdd = (int) Math.min(this.config.getMaxFlushSizeBytes() - aggregatedAppend.getLength(), remainingLength);
              aggregatedAppend.increaseLength(lengthToAdd);
              remainingLength -= lengthToAdd;
              if (remainingLength > 0) {
                  // We still have data to add, which means we filled up the current AggregatedAppend; make a new one.
                  aggregatedAppend = new AggregatedAppendOperation(this.metadata.getId(), aggregatedAppend.getLastStreamSegmentOffset(), operation.getSequenceNumber());
                  this.operations.add(aggregatedAppend);
              }
          }
      }
docs: Aggregates the given operation by recording the fact that it exists in the current Aggregated Append.
  An Aggregated Append cannot exceed a certain size, so if the given operation doesn't fit, it will need to
  span multiple AggregatedAppends.
  When aggregating, the SequenceNumber of the AggregatedAppend is the sequence number of the operation
  that occupies its first byte. As such, getLowestUncommittedSequenceNumber() will always return the SeqNo
  of that first operation that hasn't yet been fully flushed.
  
  @param operation        The operation to aggregate.
  @param aggregatedAppend The AggregatedAppend to add to.