@Override
  public int run(InputStream stdin, PrintStream out, PrintStream err, List<String> args) throws Exception {
    if (args.size() < 2) {
      printInfo(err);
      return 1;
    }
    int index = 0;
    String input = args.get(index);
    String option = "all";
    if ("-o".equals(input)) {
      option = args.get(1);
      index += 2;
    }
    if (!OPTIONS.contains(option) || (args.size() - index < 1)) {
      printInfo(err);
      return 1;
    }
    input = args.get(index++);
    if (!REPORT.equals(option)) {
      if (args.size() - index < 1) {
        printInfo(err);
        return 1;
      }
    }
    if (ALL.equals(option)) {
      return recoverAll(input, args.get(index), out, err);
    } else if (PRIOR.equals(option)) {
      return recoverPrior(input, args.get(index), out, err);
    } else if (AFTER.equals(option)) {
      return recoverAfter(input, args.get(index), out, err);
    } else if (REPORT.equals(option)) {
      return reportOnly(input, out, err);
    } else {
      return 1;
    }
  }
@Test
  void repairPriorCorruptRecord() throws Exception {
    String output = run(new DataFileRepairTool(), "-o", "prior", corruptRecordFile.getPath(), repairedFile.getPath());
    assertTrue(output.contains("Number of blocks: 3 Number of corrupt blocks: 1"), output);
    assertTrue(output.contains("Number of records: 8 Number of corrupt records: 2"), output);
    checkFileContains(repairedFile, "apple", "banana", "celery", "date");
  }