List of usage examples for java.lang Exception getMessage
public String getMessage()
From source file:edu.msu.cme.rdp.classifier.ClassifierCmd.java
/** * This is the main method to do classification. * <p>Usage: java ClassifierCmd queryFile outputFile [property file]. * <br>/* w w w .jav a 2 s .co m*/ * queryFile can be one of the following formats: Fasta, Genbank and EMBL. * <br> * outputFile will be used to save the classification output. * <br> * property file contains the mapping of the training files. * <br> * Note: the training files and the property file should be in the same directory. * The default property file is set to data/classifier/16srrna/rRNAClassifier.properties. */ public static void main(String[] args) throws Exception { String queryFile = null; String outputFile = null; String propFile = null; String gene = null; ClassificationResultFormatter.FORMAT format = CmdOptions.DEFAULT_FORMAT; int min_bootstrap_words = Classifier.MIN_BOOTSTRSP_WORDS; try { CommandLine line = new PosixParser().parse(options, args); if (line.hasOption(CmdOptions.OUTFILE_SHORT_OPT)) { outputFile = line.getOptionValue(CmdOptions.OUTFILE_SHORT_OPT); } else { throw new Exception("outputFile must be specified"); } if (line.hasOption(CmdOptions.TRAINPROPFILE_SHORT_OPT)) { if (gene != null) { throw new IllegalArgumentException( "Already specified the gene from the default location. Can not specify train_propfile"); } else { propFile = line.getOptionValue(CmdOptions.TRAINPROPFILE_SHORT_OPT); } } if (line.hasOption(CmdOptions.FORMAT_SHORT_OPT)) { String f = line.getOptionValue(CmdOptions.FORMAT_SHORT_OPT); if (f.equalsIgnoreCase("allrank")) { format = ClassificationResultFormatter.FORMAT.allRank; } else if (f.equalsIgnoreCase("fixrank")) { format = ClassificationResultFormatter.FORMAT.fixRank; } else if (f.equalsIgnoreCase("filterbyconf")) { format = ClassificationResultFormatter.FORMAT.filterbyconf; } else if (f.equalsIgnoreCase("db")) { format = ClassificationResultFormatter.FORMAT.dbformat; } else { throw new IllegalArgumentException( "Not valid output format, only allrank, fixrank, filterbyconf and db allowed"); } } if (line.hasOption(CmdOptions.GENE_SHORT_OPT)) { if (propFile != null) { throw new IllegalArgumentException( "Already specified train_propfile. Can not specify gene any more"); } gene = line.getOptionValue(CmdOptions.GENE_SHORT_OPT).toLowerCase(); if (!gene.equals(ClassifierFactory.RRNA_16S_GENE) && !gene.equals(ClassifierFactory.FUNGALLSU_GENE)) { throw new IllegalArgumentException(gene + " is NOT valid, only allows " + ClassifierFactory.RRNA_16S_GENE + " and " + ClassifierFactory.FUNGALLSU_GENE); } } if (line.hasOption(CmdOptions.MIN_BOOTSTRAP_WORDS_SHORT_OPT)) { min_bootstrap_words = Integer .parseInt(line.getOptionValue(CmdOptions.MIN_BOOTSTRAP_WORDS_SHORT_OPT)); if (min_bootstrap_words < Classifier.MIN_BOOTSTRSP_WORDS) { throw new IllegalArgumentException(CmdOptions.MIN_BOOTSTRAP_WORDS_LONG_OPT + " must be at least " + Classifier.MIN_BOOTSTRSP_WORDS); } } args = line.getArgs(); if (args.length != 1) { throw new Exception("Expect one query file"); } queryFile = args[0]; } catch (Exception e) { System.out.println("Command Error: " + e.getMessage()); new HelpFormatter().printHelp(120, "ClassifierCmd [options] <samplefile>\nNote this is the legacy command for one sample classification ", "", options, ""); return; } if (propFile == null && gene == null) { gene = CmdOptions.DEFAULT_GENE; } ClassifierCmd classifierCmd = new ClassifierCmd(); printLicense(); classifierCmd.doClassify(queryFile, outputFile, propFile, format, gene, min_bootstrap_words); }
From source file:apps.classification.ClassifySVMPerf.java
public static void main(String[] args) throws IOException { boolean dumpConfidences = false; String cmdLineSyntax = ClassifySVMPerf.class.getName() + " [OPTIONS] <path to svm_perf_classify> <testIndexDirectory> <modelDirectory>"; Options options = new Options(); OptionBuilder.withArgName("d"); OptionBuilder.withDescription("Dump confidences file"); OptionBuilder.withLongOpt("d"); OptionBuilder.isRequired(false);/*from w w w . jav a 2 s . c o m*/ OptionBuilder.hasArg(false); options.addOption(OptionBuilder.create()); OptionBuilder.withArgName("t"); OptionBuilder.withDescription("Path for temporary files"); OptionBuilder.withLongOpt("t"); OptionBuilder.isRequired(false); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create()); OptionBuilder.withArgName("v"); OptionBuilder.withDescription("Verbose output"); OptionBuilder.withLongOpt("v"); OptionBuilder.isRequired(false); OptionBuilder.hasArg(false); options.addOption(OptionBuilder.create()); OptionBuilder.withArgName("s"); OptionBuilder.withDescription("Don't delete temporary training file in svm_perf format (default: delete)"); OptionBuilder.withLongOpt("s"); OptionBuilder.isRequired(false); OptionBuilder.hasArg(false); options.addOption(OptionBuilder.create()); SvmPerfClassifierCustomizer customizer = null; GnuParser parser = new GnuParser(); String[] remainingArgs = null; try { CommandLine line = parser.parse(options, args); remainingArgs = line.getArgs(); customizer = new SvmPerfClassifierCustomizer(remainingArgs[0]); if (line.hasOption("d")) dumpConfidences = true; if (line.hasOption("v")) customizer.printSvmPerfOutput(true); if (line.hasOption("s")) { customizer.setDeleteTestFiles(false); customizer.setDeletePredictionsFiles(false); } if (line.hasOption("t")) customizer.setTempPath(line.getOptionValue("t")); } catch (Exception exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(cmdLineSyntax, options); System.exit(-1); } if (remainingArgs.length != 3) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(cmdLineSyntax, options); System.exit(-1); } String testFile = remainingArgs[1]; File file = new File(testFile); String testName = file.getName(); String testPath = file.getParent(); String classifierFile = remainingArgs[2]; file = new File(classifierFile); String classifierName = file.getName(); String classifierPath = file.getParent(); FileSystemStorageManager storageManager = new FileSystemStorageManager(testPath, false); storageManager.open(); IIndex test = TroveReadWriteHelper.readIndex(storageManager, testName, TroveContentDBType.Full, TroveClassificationDBType.Full); storageManager.close(); SvmPerfDataManager dataManager = new SvmPerfDataManager(customizer); storageManager = new FileSystemStorageManager(classifierPath, false); storageManager.open(); SvmPerfClassifier classifier = (SvmPerfClassifier) dataManager.read(storageManager, classifierName); storageManager.close(); classifier.setRuntimeCustomizer(customizer); // CLASSIFICATION String classificationName = testName + "_" + classifierName; Classifier classifierModule = new Classifier(test, classifier, dumpConfidences); classifierModule.setClassificationMode(ClassificationMode.PER_CATEGORY); classifierModule.exec(); IClassificationDB testClassification = classifierModule.getClassificationDB(); storageManager = new FileSystemStorageManager(testPath, false); storageManager.open(); TroveReadWriteHelper.writeClassification(storageManager, testClassification, classificationName + ".cla", true); storageManager.close(); if (dumpConfidences) { ClassificationScoreDB confidences = classifierModule.getConfidences(); ClassificationScoreDB.write(testPath + Os.pathSeparator() + classificationName + ".confidences", confidences); } }
From source file:br.usp.poli.lta.cereda.macro.Application.java
/** * Mtodo principal./*from w ww. ja v a2s . c om*/ * @param args Argumentos de linha de comando. */ public static void main(String[] args) { // imprime banner System.out.println(StringUtils.repeat("-", 50)); System.out.println(StringUtils.center("Expansor de macros", 50)); System.out.println(StringUtils.repeat("-", 50)); System.out.println(StringUtils.center("Laboratrio de linguagens e tcnicas adaptativas", 50)); System.out.println(StringUtils.center("Escola Politcnica - Universidade de So Paulo", 50)); System.out.println(); try { // faz o parsing dos argumentos de linha de comando CLIParser parser = new CLIParser(args); Pair<String, File> pair = parser.parse(); // se o par no nulo, possvel prosseguir com a expanso if (pair != null) { // obtm a expanso do texto fornecido na entrada String output = MacroExpander.parse(pair.getFirst()); // se foi definido um arquivo de sada, grava a expanso do // texto nele, ou imprime o resultado no terminal, caso // contrrio if (pair.getSecond() != null) { FileUtils.writeStringToFile(pair.getSecond(), output, Charset.forName("UTF-8")); System.out.println("Arquivo gerado com sucesso."); } else { System.out.println(output); } } else { // verifica se a execuo corresponde a uma chamada ao editor // embutido de macros if (parser.isEditor()) { // cria o editor e exibe SwingUtilities.invokeLater(new Runnable() { @Override public void run() { DisplayUtils.init(); Editor editor = new Editor(); editor.setVisible(true); } }); } } } catch (Exception exception) { // ocorreu uma exceo, imprime a mensagem de erro System.out.println(StringUtils.rightPad("ERRO: ", 50, "-")); System.out.println(WordUtils.wrap(exception.getMessage(), 50)); System.out.println(StringUtils.repeat(".", 50)); } }
From source file:org.openbaton.nfvo.cli.OpenbatonCLI.java
/** * Base start as a single module/*from w ww . j av a 2 s . c o m*/ * * @param args parameters for starting the shell and bootstrap */ public static void main(String[] args) { OpenbatonCLI openbatonCLI = new OpenbatonCLI(); try { openbatonCLI.run(args); } catch (Exception e) { openbatonCLI.log.error(e.getMessage()); } }
From source file:com.springsource.hq.plugin.tcserver.cli.commandline.Bootstrap.java
/** * @param args/*from w ww.j a v a2s .com*/ */ public static void main(final String[] args) { try { initConnectionProperties(args); } catch (Exception e) { LOGGER.warn( "Error parsing command line connection properties. Will uses connection properties read from ~/ams/client.properties if present or default values. Error: " + e.getMessage()); } final ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( new String[] { "classpath:META-INF/spring/tcsadmin-context.xml" }); try { final int exitCode = ((CommandDispatcher) applicationContext.getBean("commandDispatcher")) .dispatch(args); System.exit(exitCode); } catch (Exception e) { System.err.println("Failed to execute command. Reason: " + e.getMessage()); System.exit(1); } }
From source file:mover.java
public static void main(String argv[]) { int start = 1; int end = -1; int optind;/*from w w w . ja va 2 s . com*/ for (optind = 0; optind < argv.length; optind++) { if (argv[optind].equals("-T")) { // protocol protocol = argv[++optind]; } else if (argv[optind].equals("-H")) { // host host = argv[++optind]; } else if (argv[optind].equals("-U")) { // user user = argv[++optind]; } else if (argv[optind].equals("-P")) { // password password = argv[++optind]; } else if (argv[optind].equals("-L")) { url = argv[++optind]; } else if (argv[optind].equals("-s")) { // Source mbox src = argv[++optind]; } else if (argv[optind].equals("-d")) { // Destination mbox dest = argv[++optind]; } else if (argv[optind].equals("-x")) { // Expunge ? expunge = true; } else if (argv[optind].equals("--")) { optind++; break; } else if (argv[optind].startsWith("-")) { System.out.println("Usage: mover [-T protocol] [-H host] [-U user] [-P password] [-L url] [-v]"); System.out.println("\t[-s source mbox] [-d destination mbox] [-x] [msgnum1] [msgnum2]"); System.out.println("\t The -x option => EXPUNGE deleted messages"); System.out.println("\t msgnum1 => start of message-range; msgnum2 => end of message-range"); System.exit(1); } else { break; } } if (optind < argv.length) start = Integer.parseInt(argv[optind++]); // start msg if (optind < argv.length) end = Integer.parseInt(argv[optind++]); // end msg try { // Get a Properties object Properties props = System.getProperties(); // Get a Session object Session session = Session.getInstance(props, null); // Get a Store object Store store = null; if (url != null) { URLName urln = new URLName(url); store = session.getStore(urln); store.connect(); } else { if (protocol != null) store = session.getStore(protocol); else store = session.getStore(); // Connect if (host != null || user != null || password != null) store.connect(host, user, password); else store.connect(); } // Open source Folder Folder folder = store.getFolder(src); if (folder == null || !folder.exists()) { System.out.println("Invalid folder: " + src); System.exit(1); } folder.open(Folder.READ_WRITE); int count = folder.getMessageCount(); if (count == 0) { // No messages in the source folder System.out.println(folder.getName() + " is empty"); // Close folder, store and return folder.close(false); store.close(); return; } // Open destination folder, create if reqd Folder dfolder = store.getFolder(dest); if (!dfolder.exists()) dfolder.create(Folder.HOLDS_MESSAGES); if (end == -1) end = count; // Get the message objects to copy Message[] msgs = folder.getMessages(start, end); System.out.println("Moving " + msgs.length + " messages"); if (msgs.length != 0) { folder.copyMessages(msgs, dfolder); folder.setFlags(msgs, new Flags(Flags.Flag.DELETED), true); // Dump out the Flags of the moved messages, to insure that // all got deleted for (int i = 0; i < msgs.length; i++) { if (!msgs[i].isSet(Flags.Flag.DELETED)) System.out.println("Message # " + msgs[i] + " not deleted"); } } // Close folders and store folder.close(expunge); store.close(); } catch (MessagingException mex) { Exception ex = mex; do { System.out.println(ex.getMessage()); if (ex instanceof MessagingException) ex = ((MessagingException) ex).getNextException(); else ex = null; } while (ex != null); } }
From source file:com.sm.store.TestRemoteCall.java
public static void main(String[] args) { String[] opts = new String[] { "-store", "-url", "-times" }; String[] defaults = new String[] { "store", "localhost:7100", "10" }; String[] paras = getOpts(args, opts, defaults); String store = paras[0];//from w ww.jav a 2 s . co m String url = paras[1]; int times = Integer.valueOf(paras[2]); RemoteClientImpl client = new NTRemoteClientImpl(url, null, store); for (int i = 0; i < times; i++) { try { int j = i % 4; Integer res = null; Invoker invoker; switch (j) { case 0: logger.info("+ j= " + j); invoker = new Invoker("com.sm.store.Operation", "add", new Integer[] { j++, j++ }); res = (Integer) client.invoke(invoker); break; case 1: logger.info("- j= " + j); invoker = new Invoker("com.sm.store.Operation", "substract", new Integer[] { j + 2, j }); res = (Integer) client.invoke(invoker); break; case 2: logger.info("X j= " + j); invoker = new Invoker("com.sm.store.Operation", "multiply", new Integer[] { j + 5, j }); res = (Integer) client.invoke(invoker); break; case 3: logger.info("Add j= " + j); invoker = new Invoker("com.sm.store.Operation", "div", new Integer[] { j + 10, j++ }); res = (Integer) client.invoke(invoker); break; default: logger.info("unknown bucket j=" + j); } logger.info("result i " + i + " j " + j + " res " + res.toString()); invoker = new Invoker("com.sm.store.Hello", "greeting", new String[] { "test-" + i }); logger.info("greeting " + (String) client.invoke(invoker)); } catch (Exception ex) { logger.error(ex.getMessage(), ex); } } client.close(); }
From source file:com.example.video.Detect.java
/** * Detects entities,sentiment and syntax in a document using the Natural Language API. * @param args specifies features to detect and the path to the video on Google Cloud Storage. * * @throws IOException on Input/Output errors. *///from w w w .ja va 2 s. c o m public static void main(String[] args) throws IOException, InterruptedException { try { argsHelper(args); } catch (Exception e) { System.out.println("Exception while running:\n" + e.getMessage() + "\n"); e.printStackTrace(System.out); } }
From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.web1t.LuceneIndexer.java
/** * Execute the indexer. Following parameter are allowed: * /*from w ww .j a v a 2 s.com*/ * * --web1t The folder with all extracted n-gram files * * --outputPath The lucene index folder * * --index (optional) Number of how many indexes should be created. Default: 1 * * @param args */ @SuppressWarnings("static-access") public static void main(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("web1t") .withDescription("Folder with the web1t extracted documents").hasArg().isRequired().create()); options.addOption(OptionBuilder.withLongOpt("outputPath") .withDescription("File, where the index should be created").hasArg().isRequired().create()); options.addOption(OptionBuilder.withLongOpt("index") .withDescription("(optional) Number of how many indexes should be created. Default: 1").hasArg() .create()); options.addOption(OptionBuilder.withLongOpt("igerman98").withDescription( "(optional) If this argument is set, only words of the german dictionary will be added to the index") .create()); CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); int i = 1; if (cmd.hasOption("index")) { i = Integer.valueOf(cmd.getOptionValue("index")); } LuceneIndexer indexer = new LuceneIndexer(new File(cmd.getOptionValue("web1t")), new File(cmd.getOptionValue("outputPath")), i); if (cmd.hasOption("igerman98")) { indexer.setDictionary(new IGerman98Dictionary(new File("src/main/resources/de_DE.dic"), new File("src/main/resources/de_DE.aff"))); } indexer.index(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("LuceneIndexer", options); } }
From source file:com.p2p.peercds.cli.TorrentMain.java
/** * Torrent reader and creator.//from ww w . j a va 2s . c o m * * <p> * You can use the {@code main()} function of this class to read or create * torrent files. See usage for details. * </p> * */ public static void main(String[] args) { BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%-5p: %m%n"))); CmdLineParser parser = new CmdLineParser(); CmdLineParser.Option help = parser.addBooleanOption('h', "help"); CmdLineParser.Option filename = parser.addStringOption('t', "torrent"); CmdLineParser.Option create = parser.addBooleanOption('c', "create"); CmdLineParser.Option announce = parser.addStringOption('a', "announce"); try { parser.parse(args); } catch (CmdLineParser.OptionException oe) { System.err.println(oe.getMessage()); usage(System.err); System.exit(1); } // Display help and exit if requested if (Boolean.TRUE.equals((Boolean) parser.getOptionValue(help))) { usage(System.out); System.exit(0); } String filenameValue = (String) parser.getOptionValue(filename); if (filenameValue == null) { usage(System.err, "Torrent file must be provided!"); System.exit(1); } Boolean createFlag = (Boolean) parser.getOptionValue(create); //For repeated announce urls @SuppressWarnings("unchecked") Vector<String> announceURLs = (Vector<String>) parser.getOptionValues(announce); String[] otherArgs = parser.getRemainingArgs(); if (Boolean.TRUE.equals(createFlag) && (otherArgs.length != 1 || announceURLs.isEmpty())) { usage(System.err, "Announce URL and a file or directory must be " + "provided to create a torrent file!"); System.exit(1); } OutputStream fos = null; try { if (Boolean.TRUE.equals(createFlag)) { if (filenameValue != null) { fos = new FileOutputStream(filenameValue); } else { fos = System.out; } //Process the announce URLs into URIs List<URI> announceURIs = new ArrayList<URI>(); for (String url : announceURLs) { announceURIs.add(new URI(url)); } //Create the announce-list as a list of lists of URIs //Assume all the URI's are first tier trackers List<List<URI>> announceList = new ArrayList<List<URI>>(); announceList.add(announceURIs); File source = new File(otherArgs[0]); if (!source.exists() || !source.canRead()) { throw new IllegalArgumentException( "Cannot access source file or directory " + source.getName()); } String creator = String.format("%s (ttorrent)", System.getProperty("user.name")); Torrent torrent = null; if (source.isDirectory()) { File[] files = source.listFiles(Constants.hiddenFilesFilter); Arrays.sort(files); torrent = Torrent.create(source, Arrays.asList(files), announceList, creator); } else { torrent = Torrent.create(source, announceList, creator); } torrent.save(fos); } else { Torrent.load(new File(filenameValue), true); } } catch (Exception e) { logger.error("{}", e.getMessage(), e); System.exit(2); } finally { if (fos != System.out) { IOUtils.closeQuietly(fos); } } }