code: static long calculateRequestLimit(
        COSInputPolicy inputPolicy,
        long targetPos,
        long length,
        long contentLength,
        long readahead) {
      long rangeLimit;
      switch (inputPolicy) {
        case Random:
          // positioned.
          // read either this block, or the here + readahead value.
          rangeLimit = (length < 0) ? contentLength
              : targetPos + Math.max(readahead, length);
          break;
  
        case Sequential:
          // sequential: plan for reading the entire object.
          rangeLimit = contentLength;
          break;
  
        case Normal:
        default:
          rangeLimit = contentLength;
      }
      // cannot read past the end of the object
      rangeLimit = Math.min(contentLength, rangeLimit);
      return rangeLimit;
    }
docs: Calculate the limit for a get request, based on input policy
  and state of object.
  @param inputPolicy input policy
  @param targetPos position of the read
  @param length length of bytes requested; if less than zero "unknown"
  @param contentLength total length of file
  @param readahead current readahead value
  @return the absolute value of the limit of the request