List of usage examples for org.apache.commons.cli Option Option
public Option(String opt, String description) throws IllegalArgumentException
From source file:it.iit.genomics.cru.genomics.misc.apps.Vcf2tabApp.java
public static void main(String[] args) throws IOException, ParseException { Options options = new Options(); Option helpOpt = new Option("help", "print this message."); options.addOption(helpOpt);//from w w w . j a va2 s . co m Option option1 = new Option("f", "filename", true, "VCF file to load"); option1.setRequired(true); options.addOption(option1); option1 = new Option("o", "outputfile", true, "outputfilene"); option1.setRequired(true); options.addOption(option1); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { // parse the command line arguments cmd = parser.parse(options, args, true); } catch (ParseException exp) { displayUsage("vcf2tab", options); System.exit(1); } if (cmd.hasOption("help")) { displayUsage("vcf2tab", options); System.exit(0); } String filename = cmd.getOptionValue("f"); String outputfilename = cmd.getOptionValue("o"); Vcf2tab loader = new Vcf2tab(); loader.file2tab(filename, outputfilename); //(args[0]); }
From source file:com.hurence.logisland.runner.SparkJobLauncher.java
/** * main entry point//from w w w .j a va 2 s . c om * * @param args */ public static void main(String[] args) { logger.info("starting StreamProcessingRunner"); ////////////////////////////////////////// // Commande lien management Parser parser = new GnuParser(); Options options = new Options(); String helpMsg = "Print this message."; Option help = new Option("help", helpMsg); options.addOption(help); OptionBuilder.withArgName(AGENT); OptionBuilder.withLongOpt("agent-quorum"); OptionBuilder.isRequired(); OptionBuilder.hasArg(); OptionBuilder.withDescription("logisland agent quorum like host1:8081,host2:8081"); Option agent = OptionBuilder.create(AGENT); options.addOption(agent); OptionBuilder.withArgName(JOB); OptionBuilder.withLongOpt("job-name"); OptionBuilder.isRequired(); OptionBuilder.hasArg(); OptionBuilder.withDescription("logisland agent quorum like host1:8081,host2:8081"); Option job = OptionBuilder.create(JOB); options.addOption(job); String logisland = " \n" + " ???????? ????? ?? ??\n" + " \n" + " ???? ?? \n" + "?? ?\n" + "??????? ?????? ?????? ?????????????????? ???? ?????????? v0.10.0-SNAPSHOT\n\n\n"; System.out.println(logisland); Optional<EngineContext> engineInstance = Optional.empty(); try { // parse the command line arguments CommandLine line = parser.parse(options, args); String agentQuorum = line.getOptionValue(AGENT); String jobName = line.getOptionValue(JOB); // instanciate engine and all the processor from the config engineInstance = new RestComponentFactory(agentQuorum).getEngineContext(jobName); assert engineInstance.isPresent(); assert engineInstance.get().isValid(); logger.info("starting Logisland session version {}", engineInstance.get()); } catch (Exception e) { logger.error("unable to launch runner : {}", e.toString()); } try { // start the engine EngineContext engineContext = engineInstance.get(); engineInstance.get().getEngine().start(engineContext); } catch (Exception e) { logger.error("something went bad while running the job : {}", e); System.exit(-1); } }
From source file:com.hurence.logisland.runner.StreamProcessingRunner.java
/** * main entry point/*from w w w . j a v a 2 s . c o m*/ * * @param args */ public static void main(String[] args) { logger.info("starting StreamProcessingRunner"); ////////////////////////////////////////// // Commande lien management Parser parser = new GnuParser(); Options options = new Options(); String helpMsg = "Print this message."; Option help = new Option("help", helpMsg); options.addOption(help); OptionBuilder.withArgName("conf"); OptionBuilder.withLongOpt("config-file"); OptionBuilder.isRequired(); OptionBuilder.hasArg(); OptionBuilder.withDescription("config file path"); Option conf = OptionBuilder.create("conf"); options.addOption(conf); Optional<EngineContext> engineInstance = Optional.empty(); try { System.out.println(BannerLoader.loadBanner()); // parse the command line arguments CommandLine line = parser.parse(options, args); String configFile = line.getOptionValue("conf"); // load the YAML config LogislandConfiguration sessionConf = ConfigReader.loadConfig(configFile); // instantiate engine and all the processor from the config engineInstance = ComponentFactory.getEngineContext(sessionConf.getEngine()); if (!engineInstance.isPresent()) { throw new IllegalArgumentException("engineInstance could not be instantiated"); } if (!engineInstance.get().isValid()) { throw new IllegalArgumentException("engineInstance is not valid with input configuration !"); } logger.info("starting Logisland session version {}", sessionConf.getVersion()); logger.info(sessionConf.getDocumentation()); } catch (Exception e) { logger.error("unable to launch runner", e); System.exit(-1); } String engineName = engineInstance.get().getEngine().getIdentifier(); try { // start the engine EngineContext engineContext = engineInstance.get(); logger.info("start engine {}", engineName); engineInstance.get().getEngine().start(engineContext); logger.info("awaitTermination for engine {}", engineName); engineContext.getEngine().awaitTermination(engineContext); System.exit(0); } catch (Exception e) { logger.error("something went bad while running the job {} : {}", engineName, e); System.exit(-1); } }
From source file:de.dknapps.pswgendesktop.main.PswGenDesktop.java
/** * Hier werden die Kommandozeilenparameter analysiert und die Anwendung gestartet. *///www .j a va 2 s .c om public static void main(String[] args) throws IOException { Options options = new Options(); Option help = new Option("help", "print this message"); @SuppressWarnings("static-access") Option services = OptionBuilder.withArgName("file").hasArg() .withDescription("use given file to store services").create("services"); @SuppressWarnings("static-access") Option upgrade = OptionBuilder.withArgName("passphrase").hasArg() .withDescription("converts and re-encrypts services to new format if not too old") .create("upgrade"); options.addOption(help); options.addOption(services); options.addOption(upgrade); CommandLineParser parser = new GnuParser(); // GnuParser => mehrbuchstabige Optionen CommandLine line = null; try { line = parser.parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); // line bleibt null, dann kommt die Hilfe } if (line == null || line.hasOption("help")) { // Hilfe ausgeben => nur das tun HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("pswgen", options); } else if (line.hasOption("upgrade")) { // Datei umformatieren => nur das tun String servicesFilename = line.getOptionValue("services", CoreConstants.SERVICES_FILENAME); String passphrase = line.getOptionValue("upgrade"); PswGenCtl ctl = new PswGenCtl(servicesFilename); ctl.upgradeServiceInfoList(passphrase); } else { String servicesFilename = line.getOptionValue("services", CoreConstants.SERVICES_FILENAME); PswGenCtl ctl = new PswGenCtl(servicesFilename); ctl.start(); // Anwendung starten, PswGenCtl terminiert die VM } }
From source file:net.jingx.main.Main.java
/** * @param args/*from ww w.j av a 2 s.c o m*/ * @throws IOException */ public static void main(String[] args) { CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption(CLI_SECRET, true, "generate secret key (input is the configuration key from google)"); options.addOption(CLI_PASSCODE, true, "generate passcode (input is the secret key)"); options.addOption(new Option(CLI_HELP, "print this message")); try { CommandLine line = parser.parse(options, args); if (line.hasOption(CLI_SECRET)) { String confKey = line.getOptionValue(CLI_SECRET); String secret = generateSecret(confKey); System.out.println("Your secret to generate pins: " + secret); } else if (line.hasOption(CLI_PASSCODE)) { String secret = line.getOptionValue(CLI_PASSCODE); String pin = computePin(secret, null); System.out.println(pin); } else if (line.hasOption(CLI_HELP)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("GAuthCli", options); } else { EventQueue.invokeLater(new Runnable() { public void run() { try { MainGui window = new MainGui(); window.doSetVisible(); } catch (Exception e) { e.printStackTrace(); } } }); return; } System.out.println("Press any key to exit"); System.in.read(); } catch (Exception e) { System.out.println("Unexpected exception:" + e.getMessage()); } System.exit(0); }
From source file:com.github.chrbayer84.keybits.KeyBits.java
/** * @param args/*w ww.j av a 2 s .c om*/ */ public static void main(String[] args) throws Exception { int number_of_addresses = 1; int depth = 1; String usage = "java -jar KeyBits.jar [options]"; // create parameters which can be chosen Option help = new Option("h", "print this message"); Option verbose = new Option("v", "verbose"); Option exprt = new Option("e", "export public key to blockchain"); Option imprt = OptionBuilder.withArgName("string").hasArg() .withDescription("import public key from blockchain").create("i"); Option blockchain_address = OptionBuilder.withArgName("string").hasArg().withDescription("bitcoin address") .create("a"); Option create_wallet = OptionBuilder.withArgName("file name").hasArg().withDescription("create wallet") .create("c"); Option update_wallet = OptionBuilder.withArgName("file name").hasArg().withDescription("update wallet") .create("u"); Option balance_wallet = OptionBuilder.withArgName("file name").hasArg() .withDescription("return balance of wallet").create("b"); Option show_wallet = OptionBuilder.withArgName("file name").hasArg() .withDescription("show content of wallet").create("w"); Option send_coins = OptionBuilder.withArgName("file name").hasArg().withDescription("send satoshis") .create("s"); Option monitor_pending = OptionBuilder.withArgName("file name").hasArg() .withDescription("monitor pending transactions of wallet").create("p"); Option monitor_depth = OptionBuilder.withArgName("file name").hasArg() .withDescription("monitor transaction depths of wallet").create("d"); Option number = OptionBuilder.withArgName("integer").hasArg() .withDescription("in combination with -c, -d, -r or -s").create("n"); Option reset = OptionBuilder.withArgName("file name").hasArg().withDescription("reset wallet").create("r"); Options options = new Options(); options.addOption(help); options.addOption(verbose); options.addOption(imprt); options.addOption(exprt); options.addOption(blockchain_address); options.addOption(create_wallet); options.addOption(update_wallet); options.addOption(balance_wallet); options.addOption(show_wallet); options.addOption(send_coins); options.addOption(monitor_pending); options.addOption(monitor_depth); options.addOption(number); options.addOption(reset); BasicParser parser = new BasicParser(); CommandLine cmd = null; String header = "This is KeyBits v0.01b.1412953962" + System.getProperty("line.separator"); // show help if wrong usage try { cmd = parser.parse(options, args); } catch (Exception e) { printHelp(usage, options, header); } if (cmd.getOptions().length == 0) printHelp(usage, options, header); if (cmd.hasOption("h")) printHelp(usage, options, header); if (cmd.hasOption("v")) System.out.println(header); if (cmd.hasOption("c") && cmd.hasOption("n")) number_of_addresses = new Integer(cmd.getOptionValue("n")).intValue(); if (cmd.hasOption("d") && cmd.hasOption("n")) depth = new Integer(cmd.getOptionValue("n")).intValue(); String checkpoints_file_name = "checkpoints"; if (!new File(checkpoints_file_name).exists()) checkpoints_file_name = null; // --------------------------------------------------------------------- if (cmd.hasOption("c")) { String wallet_file_name = cmd.getOptionValue("c"); String passphrase = HelpfulStuff.insertPassphrase("enter password for " + wallet_file_name); if (!new File(wallet_file_name).exists()) { String passphrase_ = HelpfulStuff.reInsertPassphrase("enter password for " + wallet_file_name); if (!passphrase.equals(passphrase_)) { System.out.println("passwords do not match"); System.exit(0); } } MyWallet.createWallet(wallet_file_name, wallet_file_name + ".chain", number_of_addresses, passphrase); System.exit(0); } if (cmd.hasOption("u")) { String wallet_file_name = cmd.getOptionValue("u"); MyWallet.updateWallet(wallet_file_name, wallet_file_name + ".chain", checkpoints_file_name); System.exit(0); } if (cmd.hasOption("b")) { String wallet_file_name = cmd.getOptionValue("b"); System.out.println( MyWallet.getBalanceOfWallet(wallet_file_name, wallet_file_name + ".chain").longValue()); System.exit(0); } if (cmd.hasOption("w")) { String wallet_file_name = cmd.getOptionValue("w"); System.out.println(MyWallet.showContentOfWallet(wallet_file_name, wallet_file_name + ".chain")); System.exit(0); } if (cmd.hasOption("p")) { System.out.println("monitoring of pending transactions ... "); String wallet_file_name = cmd.getOptionValue("p"); MyWallet.monitorPendingTransactions(wallet_file_name, wallet_file_name + ".chain", checkpoints_file_name); System.exit(0); } if (cmd.hasOption("d")) { System.out.println("monitoring of transaction depth ... "); String wallet_file_name = cmd.getOptionValue("d"); MyWallet.monitorTransactionDepth(wallet_file_name, wallet_file_name + ".chain", checkpoints_file_name, depth); System.exit(0); } if (cmd.hasOption("r") && cmd.hasOption("n")) { long epoch = new Long(cmd.getOptionValue("n")); System.out.println("resetting wallet ... "); String wallet_file_name = cmd.getOptionValue("r"); File chain_file = (new File(wallet_file_name + ".chain")); if (chain_file.exists()) chain_file.delete(); MyWallet.setCreationTime(wallet_file_name, epoch); MyWallet.updateWallet(wallet_file_name, wallet_file_name + ".chain", checkpoints_file_name); System.exit(0); } if (cmd.hasOption("s") && cmd.hasOption("a") && cmd.hasOption("n")) { String wallet_file_name = cmd.getOptionValue("s"); String address = cmd.getOptionValue("a"); Integer amount = new Integer(cmd.getOptionValue("n")); String wallet_passphrase = HelpfulStuff.insertPassphrase("enter password for " + wallet_file_name); MyWallet.sendCoins(wallet_file_name, wallet_file_name + ".chain", checkpoints_file_name, address, new BigInteger(amount + ""), wallet_passphrase); System.out.println("waiting ..."); Thread.sleep(10000); System.out.println("monitoring of transaction depth ... "); MyWallet.monitorTransactionDepth(wallet_file_name, wallet_file_name + ".chain", checkpoints_file_name, 1); System.out.println("transaction fixed in blockchain with depth " + depth); System.exit(0); } // ---------------------------------------------------------------------------------------- // creates public key // ---------------------------------------------------------------------------------------- GnuPGP gpg = new GnuPGP(); if (cmd.hasOption("e")) { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); String line = null; StringBuffer sb = new StringBuffer(); while ((line = input.readLine()) != null) sb.append(line + "\n"); PGPPublicKeyRing public_key_ring = gpg.getDearmored(sb.toString()); //System.out.println(gpg.showPublicKeys(public_key_ring)); byte[] public_key_ring_encoded = gpg.getEncoded(public_key_ring); String[] addresses = (new Encoding()).encodePublicKey(public_key_ring_encoded); // System.out.println(gpg.showPublicKey(gpg.getDecoded(encoding.decodePublicKey(addresses)))); // file names for message String public_key_file_name = Long.toHexString(public_key_ring.getPublicKey().getKeyID()) + ".wallet"; String public_key_wallet_file_name = public_key_file_name; String public_key_chain_file_name = public_key_wallet_file_name + ".chain"; // hier muss dass passwort noch nach encodeAddresses weitergeleitet werden da sonst zweimal abfrage String public_key_wallet_passphrase = HelpfulStuff .insertPassphrase("enter password for " + public_key_wallet_file_name); if (!new File(public_key_wallet_file_name).exists()) { String public_key_wallet_passphrase_ = HelpfulStuff .reInsertPassphrase("enter password for " + public_key_wallet_file_name); if (!public_key_wallet_passphrase.equals(public_key_wallet_passphrase_)) { System.out.println("passwords do not match"); System.exit(0); } } MyWallet.createWallet(public_key_wallet_file_name, public_key_chain_file_name, 1, public_key_wallet_passphrase); MyWallet.updateWallet(public_key_wallet_file_name, public_key_chain_file_name, checkpoints_file_name); String public_key_address = MyWallet.getAddress(public_key_wallet_file_name, public_key_chain_file_name, 0); System.out.println("address of public key: " + public_key_address); // 10000 additional satoshis for sending transaction to address of recipient of message and 10000 for fees KeyBits.encodeAddresses(public_key_wallet_file_name, public_key_chain_file_name, checkpoints_file_name, addresses, 2 * SendRequest.DEFAULT_FEE_PER_KB.intValue(), depth, public_key_wallet_passphrase); } if (cmd.hasOption("i")) { String location = cmd.getOptionValue("i"); String[] addresses = null; if (location.indexOf(",") > -1) { String[] locations = location.split(","); addresses = MyWallet.getAddressesFromBlockAndTransaction("main.wallet", "main.wallet.chain", checkpoints_file_name, locations[0], locations[1]); } else { addresses = BlockchainDotInfo.getKeys(location); } byte[] encoded = (new Encoding()).decodePublicKey(addresses); PGPPublicKeyRing public_key_ring = gpg.getDecoded(encoded); System.out.println(gpg.getArmored(public_key_ring)); System.exit(0); } }
From source file:cc.twittertools.search.api.TrecSearchThriftServer.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(new Option(HELP_OPTION, "show help")); options.addOption(OptionBuilder.withArgName("port").hasArg().withDescription("port").create(PORT_OPTION)); options.addOption(/*from w w w. j a v a2 s.c om*/ OptionBuilder.withArgName("index").hasArg().withDescription("index location").create(INDEX_OPTION)); options.addOption(OptionBuilder.withArgName("num").hasArg() .withDescription("max number of threads in thread pool").create(MAX_THREADS_OPTION)); options.addOption(OptionBuilder.withArgName("file").hasArg() .withDescription("file containing access tokens").create(CREDENTIALS_OPTION)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (cmdline.hasOption(HELP_OPTION) || !cmdline.hasOption(INDEX_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(TrecSearchThriftServer.class.getName(), options); System.exit(-1); } int port = cmdline.hasOption(PORT_OPTION) ? Integer.parseInt(cmdline.getOptionValue(PORT_OPTION)) : DEFAULT_PORT; int maxThreads = cmdline.hasOption(MAX_THREADS_OPTION) ? Integer.parseInt(cmdline.getOptionValue(MAX_THREADS_OPTION)) : DEFAULT_MAX_THREADS; File index = new File(cmdline.getOptionValue(INDEX_OPTION)); Map<String, String> credentials = null; if (cmdline.hasOption(CREDENTIALS_OPTION)) { credentials = Maps.newHashMap(); File cfile = new File(cmdline.getOptionValue(CREDENTIALS_OPTION)); if (!cfile.exists()) { System.err.println("Error: " + cfile + " does not exist!"); System.exit(-1); } for (String s : Files.readLines(cfile, Charsets.UTF_8)) { try { String[] arr = s.split(":"); credentials.put(arr[0], arr[1]); } catch (Exception e) { // Catch any exceptions from parsing file contain access tokens System.err.println("Error reading access tokens from " + cfile + "!"); System.exit(-1); } } } if (!index.exists()) { System.err.println("Error: " + index + " does not exist!"); System.exit(-1); } TServerSocket serverSocket = new TServerSocket(port); TrecSearch.Processor<TrecSearch.Iface> searchProcessor = new TrecSearch.Processor<TrecSearch.Iface>( new TrecSearchHandler(index, credentials)); TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverSocket); serverArgs.maxWorkerThreads(maxThreads); TServer thriftServer = new TThreadPoolServer( serverArgs.processor(searchProcessor).protocolFactory(new TBinaryProtocol.Factory())); thriftServer.serve(); }
From source file:ar.com.ergio.uncoma.cei.MiniPas.java
/** * @param args/* w w w.j a v a 2 s . c om*/ * @throws IOException */ @SuppressWarnings("static-access") public static void main(String[] args) throws IOException { // Config logging system -- TODO improve this Handler console = new ConsoleHandler(); ROOT_LOG.addHandler(console); // Create cmdline options - TODO - I18N final Options options = new Options(); options.addOption(new Option("help", "Muestra este mensaje")); options.addOption(new Option("version", "Muestra la informaci\u00f3 de versi\u00f3n y termina")); options.addOption(new Option("debug", "Muestra informaci\u00f3n para depuraci\u00f3n")); options.addOption( OptionBuilder.withArgName("file").hasArg().withDescription("Archivo de log").create("logFile")); final CommandLineParser cmdlineParser = new GnuParser(); final HelpFormatter formatter = new HelpFormatter(); try { final CommandLine cmdline = cmdlineParser.parse(options, args); // Process command line args -- TODO Improve this if (args.length == 0 || cmdline.hasOption("help")) { formatter.printHelp("minipas", options, true); } else if (cmdline.hasOption("version")) { System.out.println("MiniPas versi\u00f3n: 0.0.1"); } else if (cmdline.hasOption("debug")) { ROOT_LOG.setLevel(Level.FINE); } else { ROOT_LOG.fine("Arguments: " + Arrays.toString(args)); final Scanner scanner = new Scanner(args[0]); while (scanner.hasTokens()) { System.out.println(scanner.nextToken()); } } } catch (ParseException e) { formatter.printHelp("minipas", options, true); } }
From source file:de.prozesskraft.pkraft.Checkconsistency.java
public static void main(String[] args) throws org.apache.commons.cli.ParseException, IOException { /*---------------------------- get options from ini-file// w ww .ja v a 2s. c om ----------------------------*/ File inifile = new java.io.File(WhereAmI.getInstallDirectoryAbsolutePath(Checkconsistency.class) + "/" + "../etc/pkraft-checkconsistency.ini"); if (inifile.exists()) { try { ini = new Ini(inifile); } catch (InvalidFileFormatException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else { System.err.println("ini file does not exist: " + inifile.getAbsolutePath()); System.exit(1); } /*---------------------------- create boolean options ----------------------------*/ Option ohelp = new Option("help", "print this message"); Option ov = new Option("v", "prints version and build-date"); /*---------------------------- create argument options ----------------------------*/ Option odefinition = OptionBuilder.withArgName("definition").hasArg() .withDescription("[mandatory] process model in xml format.") // .isRequired() .create("definition"); /*---------------------------- create options object ----------------------------*/ Options options = new Options(); options.addOption(ohelp); options.addOption(ov); options.addOption(odefinition); /*---------------------------- create the parser ----------------------------*/ CommandLineParser parser = new GnuParser(); // parse the command line arguments commandline = parser.parse(options, args); /*---------------------------- usage/help ----------------------------*/ if (commandline.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("startinstance", options); System.exit(0); } if (commandline.hasOption("v")) { System.out.println("author: alexander.vogel@prozesskraft.de"); System.out.println("version: [% version %]"); System.out.println("date: [% date %]"); System.exit(0); } /*---------------------------- ueberpruefen ob eine schlechte kombination von parametern angegeben wurde ----------------------------*/ if (!(commandline.hasOption("definition"))) { System.out.println("option -definition is mandatory."); exiter(); } /*---------------------------- die lizenz ueberpruefen und ggf abbrechen ----------------------------*/ // check for valid license ArrayList<String> allPortAtHost = new ArrayList<String>(); allPortAtHost.add(ini.get("license-server", "license-server-1")); allPortAtHost.add(ini.get("license-server", "license-server-2")); allPortAtHost.add(ini.get("license-server", "license-server-3")); MyLicense lic = new MyLicense(allPortAtHost, "1", "user-edition", "0.1"); // lizenz-logging ausgeben for (String actLine : (ArrayList<String>) lic.getLog()) { System.err.println(actLine); } // abbruch, wenn lizenz nicht valide if (!lic.isValid()) { System.exit(1); } /*---------------------------- die eigentliche business logic ----------------------------*/ Process p1 = new Process(); p1.setInfilexml(commandline.getOptionValue("definition")); Process p2; try { p2 = p1.readXml(); if (p2.isProcessConsistent()) { System.out.println("process structure is consistent."); } else { System.out.println("process structure is NOT consistent."); } p2.printLog(); } catch (JAXBException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:isi.pasco2.Main.java
public static void main(String[] args) { CommandLineParser parser = new PosixParser(); Options options = new Options(); Option undelete = new Option("d", "Undelete activity records"); options.addOption(undelete);/*from ww w .j a v a2 s . c o m*/ Option disableAllocation = new Option("M", "Disable allocation detection"); options.addOption(disableAllocation); Option fieldDelimeter = OptionBuilder.withArgName("field-delimeter").hasArg() .withDescription("Field Delimeter (TAB by default)").create("t"); options.addOption(fieldDelimeter); Option timeFormat = OptionBuilder.withArgName("time-format").hasArg() .withDescription("xsd or standard (pasco1 compatible)").create("f"); options.addOption(timeFormat); Option fileTypeOption = OptionBuilder.withArgName("file-type").hasArg() .withDescription("The type of file: cache or history").create("T"); options.addOption(fileTypeOption); try { CommandLine line = parser.parse(options, args); boolean undeleteMethod = false; String delimeter = null; String format = null; String fileType = null; boolean disableAllocationTest = false; if (line.hasOption("d")) { undeleteMethod = true; } if (line.hasOption('t')) { delimeter = line.getOptionValue('t'); } if (line.hasOption('M')) { disableAllocationTest = true; } if (line.hasOption('T')) { fileType = line.getOptionValue('T'); } if (line.hasOption('f')) { format = line.getOptionValue('f'); } if (line.getArgs().length != 1) { System.err.println("No file specified."); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("pasco2", options); System.exit(1); } String fileName = line.getArgs()[0]; try { IndexFile fr = new FastReadIndexFile(fileName, "r"); CountingCacheHandler handler = null; if (fileType == null) { handler = new CountingCacheHandler(); } if (fileType == null) { handler = new CountingCacheHandler(); } else if (fileType.equals("cache")) { handler = new CountingCacheHandler(); } else if (fileType.equals("history")) { handler = new Pasco2HistoryHandler(); } if (format != null) { if (format.equals("pasco")) { DateFormat regularDateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss.SSS"); handler.setDateFormat(regularDateFormat); TimeZone tz = TimeZone.getTimeZone("Australia/Brisbane"); regularDateFormat.setTimeZone(tz); } else if (format.equals("standard")) { DateFormat xsdDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); handler.setDateFormat(xsdDateFormat); xsdDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); } else { System.err.println("Format not supported."); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("pasco2", options); System.exit(1); } } if (delimeter != null) { handler.setDelimeter(delimeter); } IEIndexFileParser logparser = null; if (fileType == null) { System.err.println("Using cache file parser."); logparser = new IECacheFileParser(fileName, fr, handler); } else if (fileType.equals("cache")) { logparser = new IECacheFileParser(fileName, fr, handler); } else if (fileType.equals("history")) { logparser = new IEHistoryFileParser(fileName, fr, handler); } else { System.err.println("Unsupported file type."); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("pasco2", options); System.exit(1); } if (disableAllocationTest) { logparser.setDisableAllocationTest(true); } logparser.parseFile(); } catch (Exception ex) { System.err.println(ex.getMessage()); ex.printStackTrace(); } } catch (ParseException exp) { System.out.println("Unexpected exception:" + exp.getMessage()); } }