public void run() {

    log.info("Starting file scan");
    Schema schema = SizePathAvro.getClassSchema();
    String indexName = "fileSize";

    AvroSortingIndexWriter<SizePathAvro> indexWriter;
    try {
      indexWriter =
          new AvroSortingIndexWriter<SizePathAvro>(
              schema, sortFile, indexName, maxObjects, comparator);
    } catch (IOException e) {
      log.log(Level.SEVERE, "Error!", e);
      return;
    }

    FileScannerJob j = new FileScannerJob(log, startDir, indexWriter);
    j.run();

    // wait for jobs to finish
    FileScannerJob.waitForJobs();

    try {
      indexWriter.flush();
      indexWriter.close();
    } catch (IOException e) {
      log.log(Level.SEVERE, "Error!", e);
      return;
    }

    log.info("Sorting index. Please wait...");
    try {
      AvroIndexMerger<SizePathAvro> externalSorter =
          new AvroIndexMerger<SizePathAvro>(
              SizePathAvro.class, sortFile, indexName, maxObjects, comparator, true);
      externalSorter.run();
    } catch (IOException e) {
      log.log(Level.SEVERE, "Error!", e);
    }
  }
 public int compare(SizePathAvro o1, SizePathAvro o2) {
   return o2.getFileSize().compareTo(o1.getFileSize());
 }