code: private int computeReadLength(long currentFetchOffset) {
          Preconditions.checkState(endOffset >= currentFetchOffset,
                  "Current offset up to to which events are fetched should be less than the configured end offset");
          int currentReadLength = Math.max(minReadLength, buffer.capacityAvailable());
          if (UNBOUNDED_END_OFFSET == endOffset) { //endOffset is UNBOUNDED_END_OFFSET if the endOffset is not set.
              return currentReadLength;
          }
          long numberOfBytesRemaining = endOffset - currentFetchOffset;
          return Math.toIntExact(Math.min(currentReadLength, numberOfBytesRemaining));
      }
docs: Compute the read length based on the current fetch offset and the configured end offset.