private void convert(File source, NavigationFormat format, File target) throws IOException {
    NavigationFileParser parser = new NavigationFileParser();
    if (!parser.read(source)) {
      log.severe("Could not read source '" + source.getAbsolutePath() + "'");
      logFormatNames(NavigationFormats.getReadFormatsSortedByName());
      System.exit(20);
    }

    if (format.isSupportsMultipleRoutes()) {
      parser.write(parser.getAllRoutes(), (MultipleRoutesFormat) format, target);
    } else {
      int fileCount =
          NavigationFileParser.getNumberOfFilesToWriteFor(parser.getTheRoute(), format, false);
      File[] targets =
          Files.createTargetFiles(
              target, fileCount, format.getExtension(), format.getMaximumFileNameLength());
      for (File t : targets) {
        if (t.exists()) {
          log.severe("Target '" + t.getAbsolutePath() + "' already exists; stopping.");
          System.exit(13);
        }
      }
      parser.write(parser.getTheRoute(), format, false, false, targets);
    }
  }
  private void run(String[] args) {
    Version version = Version.parseVersionFromManifest();
    log.info(
        "Started RouteConverter "
            + version.getVersion()
            + " from "
            + version.getDate()
            + " on "
            + Platform.getOsName()
            + " with "
            + Platform.getJvm());
    if (args.length != 3) {
      log.info(
          "Usage: java -jar RouteConverterCmdLine.jar <source file> <target format> <target file>");
      logFormatNames(NavigationFormats.getWriteFormatsSortedByName());
      System.exit(5);
    }

    File source = new File(args[0]);
    if (!source.exists()) {
      log.severe("Source '" + source.getAbsolutePath() + "' does not exist; stopping.");
      System.exit(10);
    }

    BaseNavigationFormat format = findFormat(args[1]);
    if (format == null) {
      log.severe("Format '" + args[1] + "' does not exist; stopping.");
      logFormatNames(NavigationFormats.getWriteFormatsSortedByName());
      System.exit(12);
    }

    String baseName = Files.removeExtension(args[2]);
    File target = new File(baseName + format.getExtension());
    if (target.exists()) {
      log.severe("Target '" + target.getAbsolutePath() + "' already exists; stopping.");
      System.exit(13);
    }

    try {
      convert(source, format, target);
    } catch (IOException e) {
      log.severe("Error while converting: " + e.getMessage());
      System.exit(15);
    }

    System.exit(0);
  }