Exemplo n.º 1
0
  public static void main(String args[]) {
    File f = new File("resources/archive_hub_dump.nt");
    String name = f.getName();

    CommandLineParser parser = new BasicParser();
    CommandLine cmd;
    try {
      cmd = parser.parse(getCLIOptions(), args);
      if (cmd.hasOption("file")) {
        f = new File(cmd.getOptionValue("file"));
        if (!f.exists()) {
          System.err.println("File/Directory to compress not found.");
          System.exit(0);
        }
      }
      if (cmd.hasOption("name")) {
        name = cmd.getOptionValue("name");
      }
    } catch (ParseException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    HDTEvaluation hdtEval = new HDTEvaluation(name, f);

    try {
      hdtEval.run();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ParserException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  public static void main(String[] args) {
    int counter = 10000;
    Product product = null;

    Options options = new Options();
    options.addOption("p", "product", true, "Class name of the product to use for benchmark");
    options.addOption("n", true, "Number of repetitions");

    Parser parser = new PosixParser();
    try {
      CommandLine commandLine = parser.parse(options, args);
      if (commandLine.hasOption('p')) {
        product = (Product) Class.forName(commandLine.getOptionValue('p')).newInstance();
      }
      if (commandLine.hasOption('n')) {
        counter = Integer.parseInt(commandLine.getOptionValue('n'));
      }
    } catch (ParseException e) {
      e.printStackTrace();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }

    Harness harness = new Harness();
    // harness.addMetric(new SerializationSpeedMetric(1) {
    // public String toString() {
    // return "Initial run serialization";
    // }
    // });
    // harness.addMetric(new DeserializationSpeedMetric(1, false) {
    // public String toString() {
    // return "Initial run deserialization";
    // }
    // });
    harness.addMetric(new SerializationSpeedMetric(counter));
    harness.addMetric(new DeserializationSpeedMetric(counter, false));
    if (product == null) {
      harness.addProduct(new NoCache());
      harness.addProduct(new Cache122());
      harness.addProduct(new RealClassCache());
      harness.addProduct(new SerializedClassCache());
      harness.addProduct(new AliasedAttributeCache());
      harness.addProduct(new DefaultImplementationCache());
      harness.addProduct(new NoCache());
    } else {
      harness.addProduct(product);
    }
    harness.addTarget(new BasicTarget());
    harness.addTarget(new ExtendedTarget());
    harness.addTarget(new ReflectionTarget());
    harness.addTarget(new SerializableTarget());
    harness.run(new TextReporter(new PrintWriter(System.out, true)));
    System.out.println("Done.");
  }
Exemplo n.º 3
0
  // TODO add exception for invalid options
  private void loadCLO(String[] args) {
    Options options = new Options();

    String[][] clolist = {
      // {"variable/optionname", "description"},
      {"genConfig", "general configuration file location"},
      {"inWeightsLoc", "input weights configuration file location"},
      {"inDBLoc", "input database file location"},
      {"outWeightsLoc", "output weights configuration file location"},
      {"outDBLoc", "output database file location"},
      {"p3pLocation", "adding to DB: single policy file location"},
      {"p3pDirLocation", "adding to DB: multiple policy directory location"},
      {"newDB", "create new database in place of old one (doesn't check for existence of old one"},
      {"newPolicyLoc", "the policy object to process"},
      {"userResponse", "response to specified policy"},
      {"userIO", "user interface"},
      {"userInit", "initialization via user interface"},
      {"policyDB", "PolicyDatabase backend"},
      {"cbrV", "CBR to use"},
      {"blanketAccept", "automatically accept the user suggestion"},
      {"loglevel", "level of things save to the log- see java logging details"},
      {"policyDB", "PolicyDatabase backend"},
      {"NetworkRType", "Network Resource type"},
      {"NetworkROptions", "Network Resource options"},
      {"confidenceLevel", "Confidence threshold for consulting a networked resource"},
      {"useNet", "use networking options"},
      {"loglocation", "where to save the log file"},
      {"loglevel", "the java logging level to use. See online documentation for enums."}
    };

    for (String[] i : clolist) {
      options.addOption(i[0], true, i[1]);
    }

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
      cmd = parser.parse(options, args);
    } catch (ParseException e) {
      System.err.println("Error parsing commandline arguments.");
      e.printStackTrace();
      System.exit(3);
    }
    /*
    for(String i : args)
    {
    	System.err.println(i);
    }
    */
    for (String[] i : clolist) {
      if (cmd.hasOption(i[0])) {
        System.err.println("found option i: " + i);
        genProps.setProperty(i[0], cmd.getOptionValue(i[0]));
      }
    }
    System.err.println(genProps);
  }
Exemplo n.º 4
0
 /**
  * Initialization with Spring
  *
  * @throws Exception
  */
 @PostConstruct
 public void initialize() throws Exception {
   try {
     // Parse empty command line if MetricsServer has been launched
     // inside an another application (e.g. bigloupe web) without main
     if (cmd == null) commandLineParser(new String[] {});
   } catch (ParseException e) {
     e.printStackTrace();
   }
   startListener();
 }
  public static void main(String[] args) {
    Options options = KeyGenCLI.buildOptions();
    HelpFormatter helpFormatter = new HelpFormatter();
    CommandLineParser parser = new GnuParser();

    try {
      CommandLine commandLine = parser.parse(options, args);
      String service = commandLine.getOptionValue("service");
      String key = Crypto.generateAes128KeyWithSeed(service);

      if (key == null) {
        throw new Exception("Key was not generated!");
      }

      JSONObject keyObject = new JSONObject();
      keyObject.put("name", service);
      keyObject.put("data", key);

      System.out.println(String.format("Key: `%s`\n", key));

      System.out.println("Key object:");
      System.out.println(keyObject.toString());
    } catch (MissingOptionException e) {
      System.out.println("Missing required option(s)!");
      helpFormatter.printHelp(
          "\nKeyGenCLI",
          "This tool generates a unique key and prints the result.",
          options,
          "",
          true);
    } catch (UnrecognizedOptionException e) {
      System.out.println("Unrecognized option!");
      helpFormatter.printHelp(
          "\nKeyGenCLI",
          "This tool generates a unique key and prints the result.",
          options,
          "",
          true);
    } catch (ParseException e) {
      e.printStackTrace();
    } catch (JSONException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 6
0
  private void parseOptions(String[] args) {

    if (args.length == 0) {
      printHelp();
      System.exit(0);
    }

    try {
      line = parser.parse(getOptions(), args);

      if (line.hasOption("start") && line.hasOption("kill")) {
        throw new ParseException("Cannot simultaneously start and kill a cache");
      }

      // verify all required options are there
      if (line.hasOption("start")
          && (!line.hasOption("port") || !line.hasOption("name") || !line.hasOption("type"))) {
        throw new ParseException("Cannot start cache without port, name, and type params");
      }
    } catch (MissingOptionException e) {
      System.err.println(e.getMessage());
      printHelp();
      System.exit(-1);
    } catch (ParseException e) {
      e.printStackTrace();
      System.exit(-1);
    }

    if (line.hasOption("help")) {
      printHelp();
      System.exit(0);
    }

    if (line.hasOption("start")) {
      cacheName = line.getOptionValue("name");
      type = CacheType.valueOf(line.getOptionValue("type").toUpperCase());
      port = Integer.parseInt(line.getOptionValue("port"));

      if (type == null) {
        LOG.error("Invalid type.");
        printHelp();
        System.exit(-1);
      }
    }
  }
Exemplo n.º 7
0
  public static void main(String[] args) {
    Options options = new Options();
    options.addOption("v", true, "Input Vector folder"); // yearly vector data
    options.addOption("p", true, "Points folder"); // yearly mds (rotate) output
    options.addOption("d", true, "Destination folder");
    options.addOption("o", true, "Original stock file"); // global 10 year stock file
    options.addOption(
        "s",
        true,
        "Sector file"); // If Histogram true then set this as the folder to histogram output
    options.addOption("h", false, "Gen from histogram");
    options.addOption("e", true, "Extra classes file"); // a file containing fixed classes
    options.addOption("ci", true, "Cluster input file");
    options.addOption("co", true, "Cluster output file");

    CommandLineParser commandLineParser = new BasicParser();
    try {
      CommandLine cmd = commandLineParser.parse(options, args);
      String vectorFile = cmd.getOptionValue("v");
      String pointsFolder = cmd.getOptionValue("p");
      String distFolder = cmd.getOptionValue("d");
      String originalStocks = cmd.getOptionValue("o");
      String sectorFile = cmd.getOptionValue("s");
      boolean histogram = cmd.hasOption("h");
      String fixedClasses = cmd.getOptionValue("e");
      String clusterInputFile = cmd.getOptionValue("ci");
      String clusterOutputFile = cmd.getOptionValue("co");

      LabelApply program =
          new LabelApply(
              vectorFile,
              pointsFolder,
              distFolder,
              originalStocks,
              sectorFile,
              histogram,
              fixedClasses,
              clusterInputFile,
              clusterOutputFile);
      program.process();
    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 8
0
 public static void main(String[] args) {
   CommandLineParser parser = new PosixParser();
   try {
     CommandLine cmd = parser.parse(Main.getOptions(), args);
     int nodes = Integer.parseInt(cmd.getOptionValue(NODE_SHORT, "1000"));
     int count = Integer.parseInt(cmd.getOptionValue(BUDDY_COUNT_SHORT, "20"));
     int threads = Integer.parseInt(cmd.getOptionValue(THREAD_SHORT, "2500"));
     long executionTime = Long.parseLong(cmd.getOptionValue(EXECUTION_SHORT, "7776000000"));
     Main system = new Main();
     LOG.info(
         "Simulation system is being setup with "
             + nodes
             + " nodes, buddy count "
             + count
             + ", thread max count "
             + threads
             + " runs for "
             + executionTime);
     system.setup(nodes, count, threads, executionTime);
   } catch (ParseException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 9
0
  public boolean parse(String[] args) {
    HelpFormatter formatter = new HelpFormatter();

    // Try to parse options
    CommandLineParser parser = new PosixParser();

    if (args.length <= 0) {
      formatter.printHelp("pcaScatterPlot", cliOptions, true);
      System.exit(1);
    }
    try {
      CommandLine cmd = parser.parse(cliOptions, args, true);
      annotationsFile = cmd.getOptionValue("a");
      coordinateFile = cmd.getOptionValue("c");
      pca1 = cmd.getOptionValue("pca1");
      pca2 = cmd.getOptionValue("pca2");
      return true;
    } catch (ParseException e) {
      e.printStackTrace();
      formatter.printHelp("pcaJob", cliOptions, true);
      return false;
    }
  }
  /**
   * Main function for the ModuleManager framework. Creates an instance of ModuleManager and runs
   * it.
   *
   * <p>Arguments: The single argument that is needed is the path to a valid module manager manifest
   * file. This is specified using the --manifest arg. For additional documentation on running the
   * module manager please refer to the wiki in Common.REPOSITORY
   */
  public static void main(String[] args) {
    CommandLineParser cl = new GnuParser();
    CommandLine cmd;
    Options opts = generateCLOptions();
    try {
      cmd = cl.parse(opts, args);

      if (cmd.hasOption("help")) {
        printHelp(opts);
      } else {

        if (cmd.hasOption("manifest")) {
          ModuleManager.configure(cmd.getOptionValue("manifest"));
        } else {
          System.out.println(
              "A Module Manager Manifest is required to run the module manager"
                  + "Please specify with the --manifest switch");
          System.exit(1);
        }
        ModuleManager m;
        m = ModuleManager.getInstance();
        // publicizeRmiInterface(m, RMI_REGISTRY_PORT);
        m.run();
      }

    } catch (ParseException e) {
      printHelp(opts);
      logger.error("Incorrect command line arguments");
      e.printStackTrace();
    } catch (ManifestLoadException e) {
      logger.fatal("Could not load the module manager manifest");
      e.printStackTrace();
    } catch (ModuleLoadException e) {
      logger.fatal("Could not load the default module");
      e.printStackTrace();
    }
  }
  /* main method */
  public DefaultParam importCommandLine() {

    /* Assigning Parameter ID to an ascending number */
    putParameterID();

    /* Assigning parameter descriptions to each parameter ID */
    addParameterInfo();

    /* need a Object parser of PosixParser class for the function parse of CommandLine class */
    PosixParser parser = new PosixParser();

    /* print out help information */
    HelpParam help = new HelpParam(parameter, parameterMap);

    /* check each parameter for assignment */
    try {
      long input_limit = -1;
      int threads = Runtime.getRuntime().availableProcessors();

      /* Set Object cl of CommandLine class for Parameter storage */
      CommandLine cl = parser.parse(parameter, arguments, true);
      if (cl.hasOption(HELP)) {
        help.printStatisticerHelp();
        System.exit(0);
      }

      if (cl.hasOption(HELP2)) {
        help.printStatisticerHelp();
        System.exit(0);
      }

      if (cl.hasOption(VERSION)) {
        System.exit(0);
      }

      /* Checking all parameters */

      String value;

      if ((value = cl.getOptionValue(PARTITIONS)) != null) {
        param.partitions = Integer.decode(value);
      }

      if ((value = cl.getOptionValue(COLUMN)) != null) {
        param.columns = value;
        param.columnStart = Integer.decode(value.split("-")[0]);
        param.columnEnd = Integer.decode(value.split("-")[1]);
      } else {
        param.columnStart = Integer.decode(param.columns.split("-")[0]);
        param.columnEnd = Integer.decode(param.columns.split("-")[1]);
      }

      if (cl.hasOption(CACHE)) {
        param.cache = true;
      }

      if ((value = cl.getOptionValue(INPUT_VCF)) != null) {
        param.inputFqPath = value;
      } else if ((value = cl.getOptionValue(INPUT_TAB)) != null) {
        param.inputFqPath = value;
      } else {
        help.printStatisticerHelp();
        System.exit(0);
        //                throw new IOException("Input file not specified.\nUse -help for list of
        // options");
      }

      /* not applicable for HDFS and S3 */
      /* using TextFileBufferInput for such purpose */
      //			File inputFastq = new File(param.inputFqPath).getAbsoluteFile();
      //			if (!inputFastq.exists()){
      //				err.println("Input query file not found.");
      //				return;
      // i			}

      if ((value = cl.getOptionValue(OUTPUT_LINE)) != null) {
        param.outputPath = value;
      } else {
        help.printStatisticerHelp();
        info.readMessage("Output file not set with -outfile options");
        info.screenDump();
        System.exit(0);
      }

      File outfile = new File(param.outputPath).getAbsoluteFile();
      if (outfile.exists()) {
        info.readParagraphedMessages(
            "Output file : \n\t" + param.outputPath + "\nalready exists, will be overwrite.");
        info.screenDump();
        Runtime.getRuntime().exec("rm -rf " + param.outputPath);
      }

    } catch (IOException e) { // Don`t catch this, NaNaNaNa, U can`t touch this.
      info.readMessage("Parameter settings incorrect.");
      info.screenDump();
      e.printStackTrace();
      System.exit(0);
    } catch (RuntimeException e) {
      info.readMessage("Parameter settings incorrect.");
      info.screenDump();
      e.printStackTrace();
      System.exit(0);
    } catch (ParseException e) {
      info.readMessage("Parameter settings incorrect.");
      info.screenDump();
      e.printStackTrace();
      System.exit(0);
    }

    return param;
  }
  public static void main(String[] args) {
    try {

      // IMPORTANT HINT REGARDING STRING ENCODING
      // in Java all Strings have UTF-8 as default encoding
      // therefore: there are only a few references to UTF-8 encoding in this demo code
      // however, if values are retrieved from a database or another program language is used, then
      // one needs to
      // make sure that the UTF-8 encoding is correctly implemented

      // create CMD line option object
      Options options = new Options();

      // add CMD line options
      options.addOption(
          "o",
          "output-dir",
          true,
          "specify base output directory, if none is specified a new directory will be created in the current path");
      options.addOption(
          "n",
          "number-of-generated-receipts",
          true,
          "specify number of receipts to be randomly generated, 50 is default");
      options.addOption(
          "g",
          "signature-creation-device-cannot-fail",
          false,
          "deactivate glitches in signature-creation-device");
      options.addOption(
          "s",
          "no-signature-certificate-switch",
          false,
          "deactivate switching of signature certificates after 5 receipts");
      options.addOption(
          "t", "no-training-receipts", false, "deactivate random generation of training-receipts");

      /// parse CMD line options
      CommandLineParser parser = new DefaultParser();
      CommandLine cmd = parser.parse(options, args);

      boolean signatureCreationDeviceAlwaysWorks = cmd.hasOption("g");
      boolean deactivateSignatureCertificateSwitching = cmd.hasOption("s");
      boolean deactivateTrainingReceipts = cmd.hasOption("t");

      String outputParentDirectoryString = cmd.getOptionValue("o");
      if (outputParentDirectoryString == null) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm-ss");
        outputParentDirectoryString = "./CashBoxDemoOutput" + df.format(new Date());
      }
      File OUTPUT_PARENT_DIRECTORY = new File(outputParentDirectoryString);
      OUTPUT_PARENT_DIRECTORY.mkdirs();
      System.out.println("Setting workdir to " + OUTPUT_PARENT_DIRECTORY.getAbsolutePath());

      String numberOfReceiptsString = cmd.getOptionValue("n");
      int NUMBER_OF_RECEIPTS = DEFAULT_NUMBER_OF_GENERATED_RECEIPTS;
      if (numberOfReceiptsString != null) {
        NUMBER_OF_RECEIPTS = new Integer(numberOfReceiptsString);
      }

      // TODO add provider independent functionality
      // initialise cryptographic providers
      Security.addProvider(new BouncyCastleProvider());

      // prepare cashbox init parameters
      CashBoxParameters cashBoxParameters = new CashBoxParameters();

      // set parameter for signature certificate switching
      // if > 0 then switch signature certificate after so many signatures
      // this is important for demonstrating the handling of the DEP export format
      // when receipts where signed with multiple signature certificates
      if (deactivateSignatureCertificateSwitching) {
        cashBoxParameters.setChangeSignatureCertificateAfterSoManyReceipts(-1);
      } else {
        cashBoxParameters.setChangeSignatureCertificateAfterSoManyReceipts(10);
      }

      // generate and set random cash box ID ("Kassen-ID")
      // REF TO SPECIFICATION: Detailspezifikation/Abs 4
      String CASH_BOX_ID = "DEMO-CASH-BOX" + Math.round(Math.random() * 1000);
      cashBoxParameters.setCashBoxID(CASH_BOX_ID);

      // set cashbox suite
      // REF TO SPECIFICATION: Detailspezifikation/Abs 2
      // AT0 is used here for demonstration purposes, see Abs 2 for details on AT0
      cashBoxParameters.setRkSuite(RKSuite.R1_AT0);

      // set initial receipt identifier
      // in this demo cashbox integer values are used as receipt identifiers ("Belegnummer"),
      // however the specification does not
      // impose that limit. An arbitrary UTF-8 String could be used, the only requirement is that
      // the same combination of
      // the cashBox ID ("Kassen-ID") and the receipt identifier ("Belegnummer") is NEVER used for
      // more than one receipt
      // using the same multiple times compromises the security of the encrypted turnover value,
      // which might lead
      // to leaked turnover data.
      // REF TO SPECIFICATION: Detailspezifikation/Abs 4, Abs 8, Abs 9, Abs 10
      long initialReceiptIdentifier = Math.round(Math.random() * 1000000);
      cashBoxParameters.setInitialReceiptIdentifier(initialReceiptIdentifier);

      // set DEP module for storing and exporting receipts
      // REF TO SPECIFICATION: Detailspezifikation/Abs 3, 11
      cashBoxParameters.setDepModul(new SimpleMemoryDEPModule());

      // create random AES key for turnover encryption
      // REF TO SPECIFICATION: Detailspezifikation/Abs 4, Abs 8, Abs 9, Abs 10
      cashBoxParameters.setTurnoverKeyAESkey(CashBoxUtils.createAESKey());

      // set up signature module
      // the signature module is composed of an JWS module that create the JSON Web Signature (JWS)
      // and
      // a low level signature module for signing the hash values.
      // REF TO SPECIFICATION: Detailspezifikation/Abs 2, Abs 4, Abs 5, Abs 6

      // JWSModule jwsModule = new OrgBitbucketBcJwsModule();  //requires bouncycastle provider
      JWSModule jwsModule = new ManualJWSModule(); // allows for provider independent use cases
      // set damage flag, which simulates the failure of the signature creation device and the
      // correct handling
      // of this case, obviously this is only suitable for demonstration purposes
      jwsModule.setDamageIsPossible(!signatureCreationDeviceAlwaysWorks);
      jwsModule.setProbabilityOfDamagedSignatureDevice(PROPABILITY_DAMAGED_SIGNATURE_DEVICE);

      jwsModule.setSignatureModule(new DO_NOT_USE_IN_REAL_CASHBOX_DemoSoftwareSignatureModule());
      // jwsModule.setSignatureModule(new PKCS11SignatureModule());

      cashBoxParameters.setJwsModule(jwsModule);

      // set printer module
      // REF TO SPECIFICATION: Detailspezifikation/Abs 12, Abs 13, Abs 14, Abs 15
      PrinterModule printerModule = new SimplePDFPrinterModule();
      cashBoxParameters.setPrinterModule(printerModule);

      // init the cash box with the parameters
      DemoCashBox demoCashBox = new DemoCashBox(cashBoxParameters);

      // init done, start interaction with cashbox
      // create random receipt data that will be handled by the cashbox
      List<RawReceiptData> receipts =
          RandomReceiptGenerator.generateRandomReceipts(NUMBER_OF_RECEIPTS);

      // store first receipt (Startbeleg) in cashbox
      // all taxtype values are set to zero (per default in this demo)
      RawReceiptData firstReceipt = new RawReceiptData();
      demoCashBox.storeReceipt(firstReceipt, false, false);

      // now store the other receipts
      for (RawReceiptData rawReceiptData : receipts) {
        // store receipt within cashbox: (prepare data-to-be-signed, sign with JWS, store signed
        // receipt in DEP)

        // pre-defined chance for a training receipt (just for demo purposes)
        boolean isTrainingReceipt = false;
        if (Math.random() < PROPABILITY_TRAINING_RECEIPT && !deactivateTrainingReceipts) {
          isTrainingReceipt = true;
        }

        // pre-defined chance for a storno receipt
        boolean isStornoReceipt = false;
        if (Math.random() < PROPABILITY_OF_STORNO_RECEIPT) {
          isStornoReceipt = true;
        }
        demoCashBox.storeReceipt(rawReceiptData, isTrainingReceipt, isStornoReceipt);
      }

      // dump machine readable code of receipts (this "code" is used for the QR-codes)
      // REF TO SPECIFICATION: Detailspezifikation/Abs 12
      // dump to File
      File qrCoreRepExportFile = new File(OUTPUT_PARENT_DIRECTORY, "qr-code-rep.txt");
      List<ReceiptPackage> receiptPackages = demoCashBox.getStoredReceipts();
      PrintWriter writer = new PrintWriter(new FileWriter(qrCoreRepExportFile));
      System.out.println("------------QR-CODE-REP------------");
      for (ReceiptPackage receiptPackage : receiptPackages) {
        System.out.println(receiptPackage.getQRCodeRepresentation());
        writer.println(receiptPackage.getQRCodeRepresentation());
      }
      System.out.println("");
      writer.close();

      // dump OCR code of receipts
      // REF TO SPECIFICATION: Detailspezifikation/Abs 14
      // dump to File
      File ocrCoreRepExportFile = new File(OUTPUT_PARENT_DIRECTORY, "ocr-code-rep.txt");
      writer = new PrintWriter(new FileWriter(ocrCoreRepExportFile));
      System.out.println("------------OCR-CODE-REP------------");
      for (ReceiptPackage receiptPackage : receiptPackages) {
        System.out.println(receiptPackage.getOcrCodeRepresentation());
        writer.println(receiptPackage.getOcrCodeRepresentation());
      }
      System.out.println("");
      writer.close();

      // export DEP from cashbox
      // REF TO SPECIFICATION: Detailspezifikation/Abs 3
      DEPExportFormat depExportFormat = demoCashBox.exportDEP();

      // get JSON rep and dump export format to file/std output
      Gson gson = new GsonBuilder().setPrettyPrinting().create();
      String exportFormatJSONString = gson.toJson(depExportFormat);
      System.out.println("------------DEP-EXPORT-FORMAT------------");
      System.out.println(exportFormatJSONString);
      System.out.println("");

      // dump DEP export to file
      File depExportFile = new File(OUTPUT_PARENT_DIRECTORY, "dep-export.txt");
      FileOutputStream outputStream = new FileOutputStream(depExportFile);
      outputStream.write(exportFormatJSONString.getBytes());
      outputStream.close();

      // export receipts as PDF (QR-CODE)
      // REF TO SPECIFICATION: Detailspezifikation/Abs 12, Abs 13
      File qrCodeDumpDirectory = new File(OUTPUT_PARENT_DIRECTORY, "qr-code-dir-pdf");
      qrCodeDumpDirectory.mkdirs();
      List<byte[]> printedQRCodeReceipts =
          demoCashBox.printReceipt(receiptPackages, ReceiptPrintType.QR_CODE);
      CashBoxUtils.writeReceiptsToFiles(printedQRCodeReceipts, "QR-", qrCodeDumpDirectory);

      // export receipts as PDF (OCR)
      // REF TO SPECIFICATION: Detailspezifikation/Abs 14, Abs 15
      File ocrCodeDumpDirectory = new File(OUTPUT_PARENT_DIRECTORY, "ocr-code-dir-pdf");
      ocrCodeDumpDirectory.mkdirs();
      List<byte[]> printedOCRCodeReceipts =
          demoCashBox.printReceipt(receiptPackages, ReceiptPrintType.OCR);
      CashBoxUtils.writeReceiptsToFiles(printedOCRCodeReceipts, "OCR-", ocrCodeDumpDirectory);

      // store signature certificates (so that they can be used for verification purposes)
      // only for demonstration purposes
      List<String> signatureCertificates = new ArrayList<>();
      List<List<String>> certificateChains = new ArrayList<>();
      DEPBelegDump[] belegDumps = depExportFormat.getBelegPackage();
      for (DEPBelegDump depBelegDump : belegDumps) {
        signatureCertificates.add(depBelegDump.getSignatureCertificate());
        certificateChains.add(Arrays.asList(depBelegDump.getCertificateChain()));
      }
      File signatureCertificatesOutputFile =
          new File(OUTPUT_PARENT_DIRECTORY, "signatureCertificates.txt");
      String signatureCertificatesJSON = gson.toJson(signatureCertificates);
      BufferedOutputStream bufferedOutputStream =
          new BufferedOutputStream(new FileOutputStream(signatureCertificatesOutputFile));
      ByteArrayInputStream bIn = new ByteArrayInputStream(signatureCertificatesJSON.getBytes());
      IOUtils.copy(bIn, bufferedOutputStream);
      bufferedOutputStream.close();

      // store certificate chains (so that they can be used for verification purposes)
      // only for demonstration purposes
      File signatureCertificateChainsOutputFile =
          new File(OUTPUT_PARENT_DIRECTORY, "signatureCertificateChains.txt");
      String signatureCertificateChainsJSON = gson.toJson(certificateChains);
      bufferedOutputStream =
          new BufferedOutputStream(new FileOutputStream(signatureCertificateChainsOutputFile));
      bIn = new ByteArrayInputStream(signatureCertificateChainsJSON.getBytes());
      IOUtils.copy(bIn, bufferedOutputStream);
      bufferedOutputStream.close();

      // store AES key as BASE64 String (for demonstration purposes: to allow decryption of turnover
      // value)
      // ATTENTION, this is only for demonstration purposes, the AES key must be stored in a secure
      // area
      byte[] aesKey = cashBoxParameters.getTurnoverKeyAESkey().getEncoded();
      String aesKeyBase64 = CashBoxUtils.base64Encode(aesKey, false);
      writer = new PrintWriter(new File(OUTPUT_PARENT_DIRECTORY, "aesKeyBase64.txt"));
      writer.print(aesKeyBase64);
      writer.close();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ParseException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 13
0
  private static void commandLine(String[] args) throws WarCommandException {

    WarGameSettings settings = new WarGameSettings();
    ArrayList<String> selectedTeams = new ArrayList<>();

    WarbotOptions wo = new WarbotOptions();

    CommandLineParser parser = new DefaultParser();

    try {
      CommandLine line = parser.parse(wo, args);
      if (line.hasOption(WarbotOptions.HELP)) {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("warbot", wo);
        return;
      }
      if (line.hasOption(WarbotOptions.GAMEMODE)) {
        try {
          logger.info("Setting mode in : " + line.getOptionValue(WarbotOptions.GAMEMODE));
          WarGameMode gameMode = WarGameMode.valueOf(line.getOptionValue(WarbotOptions.GAMEMODE));
          settings.setGameMode(gameMode);
        } catch (IllegalArgumentException e) {
          throw new WarCommandException(
              "Unknown game mode : " + line.getOptionValue(WarbotOptions.GAMEMODE));
        }
      }
      if (line.hasOption("l")) {
        try {
          settings.setDefaultLogLevel(Level.parse(line.getOptionValue("l")));
        } catch (IllegalArgumentException e) {
          throw new WarCommandException("Invalid log level : " + line.getOptionValue("l"));
        }
      }

      if (line.hasOption("nb")) {

        String[] values = line.getOptionValues("nb");
        for (int i = 0; i < values.length; i += 2) {
          logger.info(values[i].toString() + ":" + values[i + 1].toString());
          try {
            WarAgentType wat = WarAgentType.valueOf(values[i]);
            int nb = Integer.parseInt(values[i + 1]);
            settings.setNbAgentOfType(wat, nb);
          } catch (IllegalArgumentException e) {
            throw new WarCommandException("Error when parsing " + values);
          }
        }
      }

      if (line.hasOption("t")) {
        String[] values = line.getOptionValues("t");
        for (int i = 0; i < values.length; ++i) {
          selectedTeams.add(values[i]);
        }
      }

    } catch (ParseException e) {
      e.printStackTrace();
    }
    new WarMain(settings, selectedTeams.toArray(new String[] {}));
  }
Exemplo n.º 14
0
  /**
   * Run a CLI programmatically.
   *
   * <p>It does not exit the JVM.
   *
   * <p>A CLI instance can be used only once.
   *
   * @param args options and arguments for the Oozie CLI.
   * @return '0' (success), '-1' (failure).
   */
  public synchronized int run(final String[] args) {

    CLIParser parser = new CLIParser("falcon", FALCON_HELP);

    parser.addCommand(ADMIN_CMD, "", "admin operations", createAdminOptions(), true);
    parser.addCommand(HELP_CMD, "", "display usage", new Options(), false);
    parser.addCommand(VERSION_CMD, "", "show client version", new Options(), false);
    parser.addCommand(
        ENTITY_CMD,
        "",
        "Entity operations like submit, suspend, resume, delete, status, definition, submitAndSchedule",
        entityOptions(),
        false);
    parser.addCommand(
        INSTANCE_CMD,
        "",
        "Process instances operations like running, status, kill, suspend, resume, rerun, logs",
        instanceOptions(),
        false);
    parser.addCommand(GRAPH_CMD, "", "graph operations", createGraphOptions(), true);

    try {
      CLIParser.Command command = parser.parse(args);
      int exitValue = 0;
      if (command.getName().equals(HELP_CMD)) {
        parser.showHelp();
      } else {
        CommandLine commandLine = command.getCommandLine();
        String falconUrl = getFalconEndpoint(commandLine);
        FalconClient client = new FalconClient(falconUrl, clientProperties);

        if (command.getName().equals(ADMIN_CMD)) {
          exitValue = adminCommand(commandLine, client, falconUrl);
        } else if (command.getName().equals(ENTITY_CMD)) {
          entityCommand(commandLine, client);
        } else if (command.getName().equals(INSTANCE_CMD)) {
          instanceCommand(commandLine, client);
        } else if (command.getName().equals(GRAPH_CMD)) {
          graphCommand(commandLine, client);
        }
      }

      return exitValue;
    } catch (ParseException ex) {
      ERR.get().println("Invalid sub-command: " + ex.getMessage());
      ERR.get().println();
      ERR.get().println(parser.shortHelp());
      ERR.get().println("Stacktrace:");
      ex.printStackTrace();
      return -1;
    } catch (ClientHandlerException ex) {
      ERR.get()
          .print(
              "Unable to connect to Falcon server, "
                  + "please check if the URL is correct and Falcon server is up and running\n");
      ERR.get().println("Stacktrace:");
      ex.printStackTrace();
      return -1;
    } catch (Exception ex) {
      ERR.get().println("Stacktrace:");
      ex.printStackTrace();
      return -1;
    }
  }
Exemplo n.º 15
0
  /** @param args */
  public static void main(String[] args) {
    String trainFile, editFile = null;

    float min = 0, max = 6;

    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    options.addOption("a", "c_lemma_min", true, "");
    options.addOption("b", "c_lemma_max", true, "");
    options.addOption("c", "c_pp_min", true, "");
    options.addOption("d", "c_pp_max", true, "");
    options.addOption("e", "c_hypernym_min", true, "");
    options.addOption("f", "c_hypernym_max", true, "");
    options.addOption("g", "train", true, "");
    options.addOption("h", "edit", true, "");
    options.addOption("i", "c_hyponym_min", true, "");
    options.addOption("j", "c_hyponym_max", true, "");
    options.addOption("k", "c_synonym_min", true, "");
    options.addOption("l", "c_synonym_max", true, "");
    options.addOption("m", "c_synset_min", true, "");
    options.addOption("n", "c_synset_max", true, "");
    options.addOption("o", "c_pos_min", true, "");
    options.addOption("p", "c_pos_max", true, "");

    CommandLine cmdline = null;
    try {
      cmdline = parser.parse(options, args);
    } catch (ParseException e1) {
      e1.printStackTrace();
    }
    float c_lemma_min =
        Float.parseFloat(cmdline.getOptionValue("c_lemma_min", Float.toString(min)));
    float c_lemma_max =
        Float.parseFloat(cmdline.getOptionValue("c_lemma_max", Float.toString(max)));
    float c_pp_min = Float.parseFloat(cmdline.getOptionValue("c_pp_min", Float.toString(min)));
    float c_pp_max = Float.parseFloat(cmdline.getOptionValue("c_pp_max", Float.toString(max)));
    float c_hypernym_min =
        Float.parseFloat(cmdline.getOptionValue("c_hypernym_min", Float.toString(min)));
    float c_hypernym_max =
        Float.parseFloat(cmdline.getOptionValue("c_hypernym_max", Float.toString(max)));
    float c_hyponym_min =
        Float.parseFloat(cmdline.getOptionValue("c_hyponym_min", Float.toString(min)));
    float c_hyponym_max =
        Float.parseFloat(cmdline.getOptionValue("c_hyponym_max", Float.toString(max)));
    float c_synonym_min =
        Float.parseFloat(cmdline.getOptionValue("c_synonym_min", Float.toString(min)));
    float c_synonym_max =
        Float.parseFloat(cmdline.getOptionValue("c_synonym_max", Float.toString(max)));
    float c_synset_min =
        Float.parseFloat(cmdline.getOptionValue("c_synset_min", Float.toString(min)));
    float c_synset_max =
        Float.parseFloat(cmdline.getOptionValue("c_synset_max", Float.toString(max)));
    float c_pos_min = Float.parseFloat(cmdline.getOptionValue("c_pos_min", Float.toString(min)));
    float c_pos_max = Float.parseFloat(cmdline.getOptionValue("c_pos_max", Float.toString(max)));
    float c_dep_min = Float.parseFloat(cmdline.getOptionValue("c_dep_min", Float.toString(min)));
    float c_dep_max = Float.parseFloat(cmdline.getOptionValue("c_dep_max", Float.toString(max)));
    trainFile =
        cmdline.getOptionValue("train", "alignment-data/msr/converted/parse/RTE2_dev_M.dat");
    editFile = cmdline.getOptionValue("edit", "/tmp/RTE2_dev_M");

    List<LblTree> aTreeList = new ArrayList<LblTree>(), bTreeList = new ArrayList<LblTree>();
    BufferedReader in;
    try {
      in = FileManager.getReader(trainFile);
      String line;

      while ((line = in.readLine()) != null) {

        // if (counter % 200 == 0)
        //	System.out.println(counter);
        String[] splits = line.split("\\t");
        DependencyTree[] trees = TextualEntailment.parseLine(splits);
        String aString = trees[0].toCompactString();
        LblTree aTree = LblTree.fromString(aString);
        aTree.setSentence(trees[0].getOrigSentence());

        String bString = trees[1].toCompactString();
        LblTree bTree = LblTree.fromString(bString);
        bTree.setSentence(trees[1].getOrigSentence());

        aTreeList.add(aTree);
        bTreeList.add(bTree);
      }
      in.close();
    } catch (IOException e1) {
      e1.printStackTrace();
    }
    float c_pos, c_dep, c_lemma, c_hypernym, c_hyponym, c_synonym, c_sameSynset, c_pp;
    for (c_lemma = c_lemma_min; c_lemma <= c_lemma_max; c_lemma++) {
      for (c_pp = c_pp_min; c_pp <= c_pp_max; c_pp++) {
        for (c_hypernym = c_hypernym_min; c_hypernym <= c_hypernym_max; c_hypernym++) {

          try {

            String editFileName =
                String.format(
                    "%s.--c_lemma-%.1f--c_pp-%.1f--c_hypernym-%.1f--.align.txt.gz",
                    editFile, c_lemma, c_pp, c_hypernym);
            BufferedWriter out = FileManager.getWriter(editFileName, true);
            for (c_hyponym = c_hyponym_min; c_hyponym <= c_hyponym_max; c_hyponym++) {
              for (c_synonym = c_synonym_min; c_synonym <= c_synonym_max; c_synonym++) {
                for (c_sameSynset = c_synset_min; c_sameSynset <= c_synset_max; c_sameSynset++) {
                  for (c_pos = c_pos_min; c_pos <= c_pos_max; c_pos++) {
                    for (c_dep = c_dep_min; c_dep <= c_dep_max; c_dep++) {
                      int counter = 1;
                      String editName =
                          String.format(
                              "=====%s.--c_lemma-%.1f--c_pp-%.1f--c_hypernym-%.1f--c_hyponym-%.1f--c_synonym-%.1f--c_sameSynset-%.1f--c_pos-%.1f--c_dep-%.1f--.align.txt\n",
                              editFile,
                              c_lemma,
                              c_pp,
                              c_hypernym,
                              c_hyponym,
                              c_synonym,
                              c_sameSynset,
                              c_pos,
                              c_dep);
                      String tabs =
                          String.format(
                              "-----%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\n",
                              c_lemma,
                              c_pp,
                              c_hypernym,
                              c_hyponym,
                              c_synonym,
                              c_sameSynset,
                              c_pos,
                              c_dep);

                      StringBuilder sb = new StringBuilder();
                      sb.append(editName);
                      sb.append(tabs);
                      for (int i = 0; i < aTreeList.size(); i++) {
                        counter = i + 1;
                        // EditDist a2b = new EditDist(true);
                        // set q2a = false since the first tree (hypothesis) is longer
                        EditDist a2b =
                            new EditDistGridSearch(
                                true,
                                false,
                                c_pos,
                                c_dep,
                                c_lemma,
                                c_hypernym,
                                c_hyponym,
                                c_synonym,
                                c_sameSynset,
                                c_pp);
                        a2b.treeDist(aTreeList.get(i), bTreeList.get(i));

                        a2b.printHumaneEditScript();

                        sb.append("# sentence pair " + counter);
                        sb.append("\n");
                        sb.append(SimpleTEDAligner.getMSRalignFormat(a2b));
                        sb.append("\n");
                      }
                      sb.append("++++++\n");
                      out.write(sb.toString());
                    }
                  }
                }
              }
            }

            out.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
    }
    // EditDistGridSearch.printStat();
    /*
    hypernym: 52
    hyponym: 72
    synonym: 1355
    entails: 0
    causing: 0
    memberOf: 6
    haveMember: 3
    substanceOf: 0
    haveSubstance: 0
    partsOf: 4
    haveParts: 5
    sameSynset: 1659

    lemma match: 9342
    pp match: 3176

    total length of tree1: 26451
    total length of tree2: 11024
    		 */
  }
Exemplo n.º 16
0
  public static void main(String[] args) {
    Options options = new Options();

    options.addOption("h", false, "Print this help");
    options.addOption("t", false, "Test mode. Doesn't write anything to the database.");
    options.addOption("v", false, "Verbose mode. Use if you like lots of tasty output.");

    Option metadataFileOption =
        OptionBuilder.withArgName("file")
            .hasArg()
            .withDescription("Process multiple reports using a StatsDB metadata table file")
            .create("m");
    options.addOption(metadataFileOption);

    Option inputFileOption =
        OptionBuilder.withArgName("file")
            .hasArg()
            .withDescription("Use given input report file")
            .create("f");
    options.addOption(inputFileOption);

    Option parserTypeOption =
        OptionBuilder.withArgName("fastqc,other")
            .hasArg()
            .withDescription("Use specified parser type")
            .create("p");
    options.addOption(parserTypeOption);

    Option runNameOption =
        OptionBuilder.withArgName("run")
            .hasArg()
            .withDescription("Associate the report with a given run name")
            .create("r");
    options.addOption(runNameOption);

    CommandLineParser parser = new BasicParser();
    try {
      CommandLine line = parser.parse(options, args);

      if (line.hasOption("h")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("statsdb.jar", options);
      }

      QcReportParser<File> qcParser = null;
      if (line.hasOption("p")) {
        String parserType = line.getOptionValue("p");
        if ("".equals(parserType) || "fastqc".equals(parserType)) {
          qcParser = new FastQCReportParser();
        } else if ("other".equals(parserType)) {
          log.error("Unsupported option 'other'. Please specify a parser type.");
          System.exit(1);
        }
      } else {
        log.info("No parser type specified. Using FASTQC as the default report type.");
        qcParser = new FastQCReportParser();
      }

      List<QCAnalysis> qcas = new ArrayList<>();

      if (line.hasOption("m")) {
        File inputfile = new File(line.getOptionValue("m"));
        if (!inputfile.exists()) {
          log.error("No input metadata file specified.");
          System.exit(1);
        } else {
          AnalysisMetadataParser amp = new AnalysisMetadataParser();
          List<QCAnalysis> pqcas = amp.parseMetadataFile(inputfile);
          for (QCAnalysis pqca : pqcas) {
            try {
              String path = pqca.getProperty("path_to_analysis");
              File reportFileToParse = new File(path);
              if (reportFileToParse.exists()) {
                qcParser.parseReport(reportFileToParse, pqca);
              }
            } catch (QCAnalysisException e) {
              log.error(
                  "Cannot use metadata file - no property 'path_to_analysis' available. For each report line, this "
                      + "should point to the file path where the report file is located.");
              System.exit(1);
            }
          }
          qcas.addAll(pqcas);
        }
      } else if (line.hasOption("f")) {
        File inputfile = new File(line.getOptionValue("f"));
        if (!inputfile.exists()) {
          log.error("No input report file specified.");
          System.exit(1);
        } else {
          QCAnalysis qca = new DefaultQCAnalysis();

          if (line.hasOption("r")) {
            qca.addProperty("run", line.getOptionValue("r"));
          } else {
            log.warn(
                "No run name specified. Parsed report metrics will only be queryable on raw read filename.");
          }
          qcParser.parseReport(inputfile, qca);
          qcas.add(qca);
        }
      } else {
        log.error("No input metadata or report file specified.");
        System.exit(1);
      }

      for (QCAnalysis qca : qcas) {
        if (line.hasOption("v")) {
          log.info("Parsed general values:");
          for (Map.Entry<String, String> p : qca.getGeneralValues().entrySet()) {
            log.info("\t\\_ " + p.getKey() + ":" + p.getValue());
          }

          log.info("Parsed partition values:");
          for (PartitionValue p : qca.getPartitionValues()) {
            log.info(
                "\t\\_ "
                    + p.getKey()
                    + ":"
                    + p.getValue()
                    + ":"
                    + p.getPosition()
                    + ":"
                    + p.getSize());
          }

          log.info("Parsed position values:");
          for (PositionValue p : qca.getPositionValues()) {
            log.info("\t\\_ " + p.getKey() + ":" + p.getValue() + ":" + p.getPosition());
          }
        }

        if (!line.hasOption("t")) {
          // write stuff to the database
          log.info("Writing analysis report to the database:");
          try {
            ApplicationContext context = new ClassPathXmlApplicationContext("db-config.xml");
            QCAnalysisStore store = (QCAnalysisStore) context.getBean("qcAnalysisStore");
            if (line.hasOption("v")) {
              store.setVerbose(true);
            }
            store.insertAnalysis(qca);
            log.info("SUCCESS");
          } catch (QCAnalysisException e) {
            log.error("FAIL: Cannot insert analysis into the database: " + e.getMessage());
            e.printStackTrace();
            System.exit(1);
          } catch (DataAccessException e) {
            log.error("FAIL: Error inserting analysis into the database: " + e.getMessage());
            e.printStackTrace();
            System.exit(1);
          }
        }
      }
    } catch (ParseException e) {
      log.error("Parsing failed.  Reason: " + e.getMessage());
      e.printStackTrace();
      System.exit(1);
    } catch (QCAnalysisException e) {
      log.error("Unable to parse QC report: " + e.getMessage());
      e.printStackTrace();
      System.exit(1);
    }
    System.exit(0);
  }
Exemplo n.º 17
0
  /**
   * @param args
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {

    CommandLineParser parser = new PosixParser();
    String warcDir = null;
    String workDir = null;
    String host = "localhost";

    Options options = new Options();
    options.addOption("h", "help", false, "Show this help message.");
    options.addOption(
        "i",
        "index-folder",
        true,
        "Specify a custom directory for caching the web archiving index files. Indexes are usually re-built every time you start WaybackPlayer, which might be cumbersome for large indexes. Use this option to specify a folder in which to cache the indexes.");
    options.addOption(
        "s", "server-name", true, "Specify a server name to use, defaults to 'localhost'");
    try {
      CommandLine line = parser.parse(options, args);
      String cli_args[] = line.getArgs();

      // Check there is an argument for the warcs folder:
      if (!(cli_args.length > 0)) {
        printUsage(options);
        return;
      }
      warcDir = cli_args[0];

      // Show help if required:
      if (line.hasOption("h")) {
        printUsage(options);
        return;
      }

      // Allow index folder to be overridden (and thus cached):
      if (line.hasOption("i")) {
        workDir = line.getOptionValue("i");
      }

      // Allow the host to be overridden:
      if (line.hasOption("s")) {
        host = line.getOptionValue("s");
      }

    } catch (ParseException e1) {
      e1.printStackTrace();
      return;
    }

    // Avoid requiring the JDK for Jetty JSP compilation.
    // See http://www.eclipse.org/jetty/documentation/current/configuring-jsp.html
    System.setProperty("org.apache.jasper.compiler.disablejsr199", "true");

    // An embedded server:
    Server server = new Server();

    // Default connector for playback:
    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(18080);
    connector.setHost(host);

    // Connector for Proxy mode:
    SelectChannelConnector connector2 = new SelectChannelConnector();
    connector2.setPort(18090);
    connector2.setHost(host);

    // Attach the two connectors:
    server.setConnectors(new Connector[] {connector, connector2});

    // Set a property so Wayback Spring can find the WARCs etc.
    System.setProperty("wayback.warc.dir", warcDir);

    // Set a propery so the host and ports are known:
    System.setProperty("wayback.host", host);
    System.setProperty("wayback.port", "" + 18080);
    System.setProperty("wayback.proxy.port", "" + 18090);

    // TODO Option to wipe it if it's there and looks like ours?
    File waywork = null;
    if (workDir == null) {
      waywork = File.createTempFile("wayback-play", "");
      waywork.delete();
      waywork.mkdir();
      System.setProperty("wayback.work.dir", waywork.getAbsolutePath());
      waywork.deleteOnExit();
    } else {
      waywork = new File(workDir);
      System.setProperty("wayback.work.dir", workDir);
    }
    System.err.println("Indexes held in: " + System.getProperty("wayback.work.dir"));

    // Prior to start up, generate CDX files and path-index.txt file and put them in
    // wayback.work.dir:
    File wdf = new File(warcDir);
    List<String> paths = new ArrayList<String>();
    for (File wf : wdf.listFiles()) {
      paths.add(wf.getName() + "\t" + wf.getAbsolutePath());
      System.out.println("LINE: " + wf.getAbsolutePath());
      // CDX generation:
      File cdxFile = new File(waywork, wf.getName() + ".cdx");
      if (!cdxFile.exists()) {
        System.out.println("Generating " + cdxFile.getPath() + " from " + wf.getPath() + "...");
        IndexWorker.main(new String[] {wf.getAbsolutePath(), cdxFile.getAbsolutePath()});
      } else {
        System.out.println(
            "The CDX " + cdxFile.getPath() + " for " + wf.getPath() + " already exists.");
      }
    }

    // For path-index.txt:
    Collections.sort(paths);
    PrintWriter writer = new PrintWriter(new File(waywork, "path-index.txt"), "UTF-8");
    for (String path : paths) {
      writer.println(path);
    }
    writer.close();

    // Set up the Wayback web app:
    WebAppContext wac = new WebAppContext();
    wac.setContextPath("/");
    // this is path to .war OR TO expanded, existing webapp; WILL FIND web.xml and parse it
    // wac.setWar("/Users/andy/Documents/workspace/waybacks/wayback-play/target/wayback-play");
    URL resourceUrl =
        ClassLoader.getSystemClassLoader().getResource("lib/warc-explorer-player.war");
    // Copy to tmp space:
    File tmpWar = File.createTempFile("wayback-player", ".war");
    tmpWar.deleteOnExit();
    IOUtils.copy(resourceUrl.openStream(), new FileOutputStream(tmpWar));
    // Fire it up:
    wac.setWar(tmpWar.getAbsolutePath());
    server.setHandler(wac);
    server.setStopAtShutdown(true);

    // Launch the server:
    try {
      server.start();
      server.join();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      //
      connector.close();
      try {
        server.stop();
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      if (waywork != null) {
        if (waywork.exists()) {
          waywork.delete();
        }
      }
    }

    System.err.println("Bye.");
  }