code: public static RandomAccessFastaIndex index(Path file, int indexStep, boolean save, LongProcessReporter reporter) {
          Path indexFile = file.resolveSibling(file.getFileName() + INDEX_SUFFIX);
  
          if (Files.exists(indexFile))
              try (FileInputStream fis = new FileInputStream(indexFile.toFile())) {
                  RandomAccessFastaIndex index = RandomAccessFastaIndex.read(new BufferedInputStream(fis));
                  if (index.getIndexStep() != indexStep)
                      throw new IllegalArgumentException("Mismatched index step in " + indexFile + ". Remove the file to recreate the index.");
                  return index;
              } catch (IOException e) {
                  throw new RuntimeException(e);
              }
  
          try (LongProcess lp = reporter.start("Indexing " + file.getFileName());
               FileChannel fc = FileChannel.open(file, StandardOpenOption.READ)) {
              // Requesting file size to correctly report status
              long size = Files.size(file);
  
              // Allocating buffer
              ByteBuffer buffer = ByteBuffer.allocate(65536);
              // Extracting backing byte array
              byte[] bufferArray = buffer.array();
              // Creating builder
              StreamIndexBuilder builder = new StreamIndexBuilder(indexStep);
  
              // Indexing file
              int read;
              long done = 0;
              while ((read = fc.read((ByteBuffer) buffer.clear())) > 0) {
                  builder.processBuffer(bufferArray, 0, read);
                  lp.reportStatus(1.0 * (done += read) / size);
              }
  
              // Build index
              RandomAccessFastaIndex index = builder.build();
  
              if (save)
                  try (FileOutputStream fos = new FileOutputStream(indexFile.toFile())) {
                      index.write(new BufferedOutputStream(fos));
                  }
  
              return index;
          } catch (IOException ioe) {
              throw new RuntimeException(ioe);
          }
      }
docs: Index fasta file or loads previously created index
  
  @param file      file to index
  @param indexStep index step
  @param save      whether to save index to {input_file_name}.mifdx file
  @param reporter  reporter
  @return index