code: public ReadaheadRequest readaheadStream(
        String identifier,
        FileDescriptor fd,
        long curPos,
        long readaheadLength,
        long maxOffsetToRead,
        ReadaheadRequest lastReadahead) {
      
      Preconditions.checkArgument(curPos <= maxOffsetToRead,
          "Readahead position %s higher than maxOffsetToRead %s",
          curPos, maxOffsetToRead);
  
      if (readaheadLength <= 0) {
        return null;
      }
      
      long lastOffset = Long.MIN_VALUE;
      
      if (lastReadahead != null) {
        lastOffset = lastReadahead.getOffset();
      }
  
      // trigger each readahead when we have reached the halfway mark
      // in the previous readahead. This gives the system time
      // to satisfy the readahead before we start reading the data.
      long nextOffset = lastOffset + readaheadLength / 2; 
      if (curPos >= nextOffset) {
        // cancel any currently pending readahead, to avoid
        // piling things up in the queue. Each reader should have at most
        // one outstanding request in the queue.
        if (lastReadahead != null) {
          lastReadahead.cancel();
          lastReadahead = null;
        }
        
        long length = Math.min(readaheadLength,
            maxOffsetToRead - curPos);
  
        if (length <= 0) {
          // we've reached the end of the stream
          return null;
        }
        
        return submitReadahead(identifier, fd, curPos, length);
      } else {
        return lastReadahead;
      }
    }
docs: Issue a request to readahead on the given file descriptor.
  
  @param identifier a textual identifier that will be used in error
  messages (e.g. the file name)
  @param fd the file descriptor to read ahead
  @param curPos the current offset at which reads are being issued
  @param readaheadLength the configured length to read ahead
  @param maxOffsetToRead the maximum offset that will be readahead
  (useful if, for example, only some segment of the file is
  requested by the user). Pass {@link Long.MAX_VALUE} to allow
  readahead to the end of the file.
  @param lastReadahead the result returned by the previous invocation
  of this function on this file descriptor, or null if this is
  the first call
  @return an object representing this outstanding request, or null
  if no readahead was performed