List of usage examples for org.apache.commons.cli ParseException printStackTrace
public void printStackTrace()
From source file:org.cc.smali.main.java
/** * Run!/*from w w w.ja v a 2 s . co m*/ */ public static void main(String[] args) { Locale locale = new Locale("en", "US"); Locale.setDefault(locale); CommandLineParser parser = new PosixParser(); CommandLine commandLine; try { commandLine = parser.parse(options, args); } catch (ParseException ex) { usage(); return; } int jobs = -1; boolean allowOdex = false; boolean verboseErrors = false; boolean printTokens = false; boolean experimental = false; int apiLevel = 15; String outputDexFile = "out.dex"; String[] remainingArgs = commandLine.getArgs(); Option[] options = commandLine.getOptions(); for (int i = 0; i < options.length; i++) { Option option = options[i]; String opt = option.getOpt(); switch (opt.charAt(0)) { case 'v': version(); return; case '?': while (++i < options.length) { if (options[i].getOpt().charAt(0) == '?') { usage(true); return; } } usage(false); return; case 'o': outputDexFile = commandLine.getOptionValue("o"); break; case 'x': allowOdex = true; break; case 'X': experimental = true; break; case 'a': apiLevel = Integer.parseInt(commandLine.getOptionValue("a")); break; case 'j': jobs = Integer.parseInt(commandLine.getOptionValue("j")); break; case 'V': verboseErrors = true; break; case 'T': printTokens = true; break; default: assert false; } } if (remainingArgs.length == 0) { usage(); return; } try { LinkedHashSet<File> filesToProcess = new LinkedHashSet<File>(); for (String arg : remainingArgs) { File argFile = new File(arg); if (!argFile.exists()) { throw new RuntimeException("Cannot find file or directory \"" + arg + "\""); } if (argFile.isDirectory()) { getSmaliFilesInDir(argFile, filesToProcess); } else if (argFile.isFile()) { filesToProcess.add(argFile); } } if (jobs <= 0) { jobs = Runtime.getRuntime().availableProcessors(); if (jobs > 6) { jobs = 6; } } boolean errors = false; final DexBuilder dexBuilder = DexBuilder.makeDexBuilder(apiLevel); ExecutorService executor = Executors.newFixedThreadPool(jobs); List<Future<Boolean>> tasks = Lists.newArrayList(); final boolean finalVerboseErrors = verboseErrors; final boolean finalPrintTokens = printTokens; final boolean finalAllowOdex = allowOdex; final int finalApiLevel = apiLevel; final boolean finalExperimental = experimental; for (final File file : filesToProcess) { tasks.add(executor.submit(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return assembleSmaliFile(file, dexBuilder, finalVerboseErrors, finalPrintTokens, finalAllowOdex, finalApiLevel, finalExperimental); } })); } for (Future<Boolean> task : tasks) { while (true) { try { if (!task.get()) { errors = true; } } catch (InterruptedException ex) { continue; } break; } } executor.shutdown(); if (errors) { System.exit(1); } dexBuilder.writeTo(new FileDataStore(new File(outputDexFile))); } catch (RuntimeException ex) { System.err.println("\nUNEXPECTED TOP-LEVEL EXCEPTION:"); ex.printStackTrace(); System.exit(2); } catch (Throwable ex) { System.err.println("\nUNEXPECTED TOP-LEVEL ERROR:"); ex.printStackTrace(); System.exit(3); } }
From source file:org.columba.core.main.ColumbaServer.java
/** * Handles a client connect and authentication. *//* www . j a v a 2 s . c o m*/ protected void handleClient(Socket client) { try { // only accept client from local machine String host = client.getLocalAddress().getHostAddress(); if (!(host.equals("127.0.0.1"))) { // client isn't from local machine return; } BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream())); String line = reader.readLine(); if (!line.startsWith("Columba ")) { return; } line = reader.readLine(); if (!line.startsWith("User ")) { return; } PrintWriter writer = new PrintWriter(client.getOutputStream()); if (!line.substring(5).equals(System.getProperty("user.name", ANONYMOUS_USER))) { writer.write("WRONG USER\r\n"); writer.close(); return; } writer.write("\r\n"); writer.flush(); line = reader.readLine(); // do something with the arguments.. List<String> list = new LinkedList<String>(); StringTokenizer st = new StringTokenizer(line, "%"); while (st.hasMoreTokens()) { String tok = (String) st.nextToken(); list.add(tok); } try { CommandLine commandLine = ColumbaCmdLineParser.getInstance() .parse((String[]) list.toArray(new String[0])); ComponentManager.getInstance().handleCommandLineParameters(commandLine); } catch (ParseException e) { e.printStackTrace(); } } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { client.close(); } catch (IOException ioe) { } } }
From source file:org.cripac.isee.vpe.ctrl.SystemPropertyCenter.java
public SystemPropertyCenter(@Nonnull String[] args) throws URISyntaxException, ParserConfigurationException, SAXException { CommandLineParser parser = new BasicParser(); Options options = new Options(); options.addOption("h", "help", false, "Print this help message."); options.addOption("v", "verbose", false, "Display debug information."); options.addOption("a", "application", true, "Application specified to run."); options.addOption(null, "spark-property-file", true, "Path of the spark property file."); options.addOption(null, "system-property-file", true, "Path of the system property file."); options.addOption(null, "app-property-file", true, "Path of the application-specific system property file."); options.addOption(null, "log4j-property-file", true, "Path of the log4j property file."); options.addOption(null, "report-listening-addr", true, "Address of runtime report listener."); options.addOption(null, "report-listening-topic", true, "Port of runtime report listener."); CommandLine commandLine;// ww w . ja v a 2s .co m try { commandLine = parser.parse(options, args); } catch (ParseException e) { e.printStackTrace(); logger.debug("Try using '-h' for more information."); System.exit(0); return; } if (commandLine.hasOption('h')) { final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("LaS-VPE Platform", options); System.exit(0); return; } verbose = commandLine.hasOption('v'); if (verbose) { logger.setLevel(Level.DEBUG); } if (commandLine.hasOption('a')) { appsToStart = commandLine.getOptionValues('a'); logger.debug("To run application:"); for (String app : appsToStart) { logger.debug("\t\t" + app); } } if (commandLine.hasOption("system-property-file")) { sysPropFilePath = commandLine.getOptionValue("system-property-file"); } if (commandLine.hasOption("log4j-property-file")) { log4jPropFilePath = commandLine.getOptionValue("log4j-property-file"); } if (commandLine.hasOption("spark-property-file")) { sparkConfFilePath = commandLine.getOptionValue("spark-property-file"); } if (commandLine.hasOption("app-property-file")) { appPropFilePath = commandLine.getOptionValue("app-property-file"); } // Load properties from file. BufferedInputStream propInputStream; try { if (sysPropFilePath.contains("hdfs:/")) { // TODO: Check if can load property file from HDFS. logger.debug("Loading system-wise default properties using HDFS platform from " + sysPropFilePath + "..."); final FileSystem hdfs = FileSystem.get(new URI(sysPropFilePath), HadoopHelper.getDefaultConf()); final FSDataInputStream hdfsInputStream = hdfs.open(new Path(sysPropFilePath)); propInputStream = new BufferedInputStream(hdfsInputStream); } else { final File propFile = new File(sysPropFilePath); logger.debug("Loading system-wise default properties locally from " + propFile.getAbsolutePath() + "..."); propInputStream = new BufferedInputStream(new FileInputStream(propFile)); } sysProps.load(propInputStream); propInputStream.close(); } catch (IOException e) { e.printStackTrace(); logger.error("Couldn't find system-wise default property file at specified path: \"" + sysPropFilePath + "\"!\n"); logger.error("Try use '-h' for more information."); System.exit(0); return; } if (appPropFilePath != null) { try { if (appPropFilePath.contains("hdfs:/")) { // TODO: Check if can load property file from HDFS. logger.debug("Loading application-specific properties" + " using HDFS platform from " + appPropFilePath + "..."); final FileSystem hdfs = FileSystem.get(new URI(appPropFilePath), HadoopHelper.getDefaultConf()); final FSDataInputStream hdfsInputStream = hdfs.open(new Path(appPropFilePath)); propInputStream = new BufferedInputStream(hdfsInputStream); } else { final File propFile = new File(appPropFilePath); logger.debug("Loading application-specific properties locally from " + propFile.getAbsolutePath() + "..."); propInputStream = new BufferedInputStream(new FileInputStream(propFile)); } sysProps.load(propInputStream); propInputStream.close(); } catch (IOException e) { e.printStackTrace(); logger.error("Couldn't find application-specific property file at specified path: \"" + appPropFilePath + "\"!\n"); logger.error("Try use '-h' for more information."); System.exit(0); return; } } // Digest the settings. for (Entry<Object, Object> entry : sysProps.entrySet()) { if (verbose) { logger.debug("Read from property file: " + entry.getKey() + "=" + entry.getValue()); } switch ((String) entry.getKey()) { case "zookeeper.connect": zkConn = (String) entry.getValue(); break; case "kafka.bootstrap.servers": kafkaBootstrapServers = (String) entry.getValue(); break; case "kafka.partitions": kafkaNumPartitions = new Integer((String) entry.getValue()); break; case "kafka.replication.factor": kafkaReplFactor = new Integer((String) entry.getValue()); break; case "kafka.fetch.max.size": kafkaMsgMaxBytes = new Integer((String) entry.getValue()); break; case "kafka.location.strategy": kafkaLocationStrategy = (String) entry.getValue(); break; case "spark.checkpoint.dir": checkpointRootDir = (String) entry.getValue(); break; case "vpe.metadata.dir": metadataDir = (String) entry.getValue(); break; case "spark.master": sparkMaster = (String) entry.getValue(); break; case "spark.deploy.mode": sparkDeployMode = (String) entry.getValue(); break; case "vpe.platform.jar": jarPath = (String) entry.getValue(); break; case "spark.yarn.am.nodeLabelExpression": yarnAmNodeLabelExpression = (String) entry.getValue(); break; case "hdfs.default.name": hdfsDefaultName = (String) entry.getValue(); break; case "executor.num": numExecutors = new Integer((String) entry.getValue()); break; case "executor.memory": executorMem = (String) entry.getValue(); break; case "executor.cores": executorCores = new Integer((String) entry.getValue()); break; case "total.executor.cores": totalExecutorCores = new Integer((String) entry.getValue()); break; case "driver.memory": driverMem = (String) entry.getValue(); break; case "driver.cores": driverCores = new Integer((String) entry.getValue()); break; case "hadoop.queue": hadoopQueue = (String) entry.getValue(); break; case "vpe.recv.parallel": break; case "vpe.buf.duration": bufDuration = new Integer((String) entry.getValue()); break; case "vpe.batch.duration": batchDuration = new Integer((String) entry.getValue()); break; case "kafka.send.max.size": kafkaSendMaxSize = new Integer((String) entry.getValue()); break; case "kafka.request.timeout.ms": kafkaRequestTimeoutMs = new Integer((String) entry.getValue()); break; case "kafka.fetch.timeout.ms": kafkaFetchTimeoutMs = new Integer((String) entry.getValue()); break; case "caffe.gpu": caffeGPU = new Integer((String) entry.getValue()); break; } } }
From source file:org.dcm4che.tool.dcm2dcm.Dcm2Dcm.java
public static void main(String[] args) { try {/* www .j a v a 2 s. c om*/ CommandLine cl = parseComandLine(args); Dcm2Dcm main = new Dcm2Dcm(); main.setEncodingOptions(CLIUtils.encodingOptionsOf(cl)); if (cl.hasOption("F")) { if (transferSyntaxOf(cl, null) != null) throw new ParseException(rb.getString("transfer-syntax-no-fmi")); main.setTransferSyntax(UID.ImplicitVRLittleEndian); main.setWithoutFileMetaInformation(true); } else { main.setTransferSyntax(transferSyntaxOf(cl, UID.ExplicitVRLittleEndian)); main.setRetainFileMetaInformation(cl.hasOption("f")); } if (cl.hasOption("verify")) main.addCompressionParam("maxPixelValueError", cl.getParsedOptionValue("verify")); if (cl.hasOption("verify-block")) main.addCompressionParam("avgPixelValueBlockSize", cl.getParsedOptionValue("verify-block")); if (cl.hasOption("q")) main.addCompressionParam("compressionQuality", cl.getParsedOptionValue("q")); if (cl.hasOption("Q")) main.addCompressionParam("encodingRate", cl.getParsedOptionValue("Q")); String[] cparams = cl.getOptionValues("C"); if (cparams != null) for (int i = 0; i < cparams.length;) main.addCompressionParam(cparams[i++], toValue(cparams[i++])); @SuppressWarnings("unchecked") final List<String> argList = cl.getArgList(); int argc = argList.size(); if (argc < 2) throw new ParseException(rb.getString("missing")); File dest = new File(argList.get(argc - 1)); if ((argc > 2 || new File(argList.get(0)).isDirectory()) && !dest.isDirectory()) throw new ParseException(MessageFormat.format(rb.getString("nodestdir"), dest)); for (String src : argList.subList(0, argc - 1)) main.mtranscode(new File(src), dest); } catch (ParseException e) { System.err.println("dcm2dcm: " + e.getMessage()); System.err.println(rb.getString("try")); System.exit(2); } catch (Exception e) { System.err.println("dcm2dcm: " + e.getMessage()); e.printStackTrace(); System.exit(2); } }
From source file:org.dcm4che.tool.dcm2jpg.Dcm2Jpg.java
public static void main(String[] args) { try {/*from w w w . j av a 2s.c o m*/ CommandLine cl = parseComandLine(args); Dcm2Jpg main = new Dcm2Jpg(); main.initImageWriter(cl.getOptionValue("F", "JPEG"), cl.getOptionValue("suffix"), cl.getOptionValue("E"), cl.getOptionValue("C"), (Number) cl.getParsedOptionValue("q")); if (cl.hasOption("frame")) main.setFrame(((Number) cl.getParsedOptionValue("frame")).intValue()); if (cl.hasOption("c")) main.setWindowCenter(((Number) cl.getParsedOptionValue("c")).floatValue()); if (cl.hasOption("w")) main.setWindowWidth(((Number) cl.getParsedOptionValue("w")).floatValue()); if (cl.hasOption("window")) main.setWindowIndex(((Number) cl.getParsedOptionValue("window")).intValue() - 1); if (cl.hasOption("voilut")) main.setVOILUTIndex(((Number) cl.getParsedOptionValue("voilut")).intValue() - 1); if (cl.hasOption("overlays")) main.setOverlayActivationMask(parseHex(cl.getOptionValue("overlays"))); if (cl.hasOption("ovlygray")) main.setOverlayGrayscaleValue(parseHex(cl.getOptionValue("ovlygray"))); main.setPreferWindow(!cl.hasOption("uselut")); main.setAutoWindowing(!cl.hasOption("noauto")); main.setPresentationState(loadDicomObject((File) cl.getParsedOptionValue("ps"))); @SuppressWarnings("unchecked") final List<String> argList = cl.getArgList(); int argc = argList.size(); if (argc < 2) throw new ParseException(rb.getString("missing")); File dest = new File(argList.get(argc - 1)); if ((argc > 2 || new File(argList.get(0)).isDirectory()) && !dest.isDirectory()) throw new ParseException(MessageFormat.format(rb.getString("nodestdir"), dest)); for (String src : argList.subList(0, argc - 1)) main.mconvert(new File(src), dest); } catch (ParseException e) { System.err.println("dcm2jpg: " + e.getMessage()); System.err.println(rb.getString("try")); System.exit(2); } catch (Exception e) { System.err.println("dcm2jpg: " + e.getMessage()); e.printStackTrace(); System.exit(2); } }
From source file:org.dcm4che.tool.dcm2xml.Dcm2Xml.java
@SuppressWarnings("unchecked") public static void main(String[] args) { try {/* w w w .j a va2 s.com*/ CommandLine cl = parseComandLine(args); Dcm2Xml main = new Dcm2Xml(); if (cl.hasOption("x")) main.setXSLT(new File(cl.getOptionValue("x"))); main.setIndent(cl.hasOption("I")); main.setIncludeKeyword(!cl.hasOption("K")); main.setIncludeNamespaceDeclaration(cl.hasOption("xmlns")); if (cl.hasOption("xml11")) main.setXMLVersion(XML_1_1); configureBulkdata(main, cl); String fname = fname(cl.getArgList()); if (fname.equals("-")) { main.parse(new DicomInputStream(System.in)); } else { DicomInputStream dis = new DicomInputStream(new File(fname)); try { main.parse(dis); } finally { dis.close(); } } } catch (ParseException e) { System.err.println("dcm2xml: " + e.getMessage()); System.err.println(rb.getString("try")); System.exit(2); } catch (Exception e) { System.err.println("dcm2xml: " + e.getMessage()); e.printStackTrace(); System.exit(2); } }
From source file:org.dcm4che.tool.dcmqrscp.DcmQRSCP.java
public static void main(String[] args) { try {/*from w w w . j a va 2s. co m*/ CommandLine cl = parseComandLine(args); DcmQRSCP main = new DcmQRSCP(); CLIUtils.configure(main.fsInfo, cl); CLIUtils.configureBindServer(main.conn, main.ae, cl); CLIUtils.configure(main.conn, cl); configureDicomFileSet(main, cl); configureTransferCapability(main, cl); configureInstanceAvailability(main, cl); configureStgCmt(main, cl); configureSendPending(main, cl); configureRemoteConnections(main, cl); ExecutorService executorService = Executors.newCachedThreadPool(); ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); main.device.setScheduledExecutor(scheduledExecutorService); main.device.setExecutor(executorService); main.device.bindConnections(); } catch (ParseException e) { System.err.println("dcmqrscp: " + e.getMessage()); System.err.println(rb.getString("try")); System.exit(2); } catch (Exception e) { System.err.println("dcmqrscp: " + e.getMessage()); e.printStackTrace(); System.exit(2); } }
From source file:org.dcm4che.tool.emf2sf.Emf2sf.java
@SuppressWarnings("unchecked") public static void main(String[] args) { try {/*from w w w . j a v a 2s. c o m*/ CommandLine cl = parseComandLine(args); Emf2sf main = new Emf2sf(); if (cl.hasOption("frame")) main.setFrames(toFrames(cl.getOptionValues("frame"))); main.setPreserveSeriesInstanceUID(cl.hasOption("not-chseries")); main.setOutputDirectory(new File(cl.getOptionValue("out-dir", "."))); if (cl.hasOption("out-file")) main.setOutputFileFormat(cl.getOptionValue("out-file")); long start = System.currentTimeMillis(); int n = main.extract(new File(fname(cl.getArgList()))); long end = System.currentTimeMillis(); System.out.println(); System.out.println(MessageFormat.format(rb.getString("extracted"), n, (end - start) / 1000f)); } catch (ParseException e) { System.err.println("emf2sf: " + e.getMessage()); System.err.println(rb.getString("try")); System.exit(2); } catch (Exception e) { System.err.println("emf2sf: " + e.getMessage()); e.printStackTrace(); System.exit(2); } }
From source file:org.dcm4che.tool.findscu.FindSCU.java
@SuppressWarnings("unchecked") public static void main(String[] args) { try {/* www.j a va 2 s . co m*/ CommandLine cl = parseComandLine(args); FindSCU main = new FindSCU(); CLIUtils.configureConnect(main.remote, main.rq, cl); CLIUtils.configureBind(main.conn, main.ae, cl); CLIUtils.configure(main.conn, cl); main.remote.setTlsProtocols(main.conn.getTlsProtocols()); main.remote.setTlsCipherSuites(main.conn.getTlsCipherSuites()); configureServiceClass(main, cl); configureKeys(main, cl); configureOutput(main, cl); configureCancel(main, cl); main.setPriority(CLIUtils.priorityOf(cl)); ExecutorService executorService = Executors.newSingleThreadExecutor(); ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); main.device.setExecutor(executorService); main.device.setScheduledExecutor(scheduledExecutorService); try { main.open(); List<String> argList = cl.getArgList(); if (argList.isEmpty()) main.query(); else for (String arg : argList) main.query(new File(arg)); } finally { main.close(); executorService.shutdown(); scheduledExecutorService.shutdown(); } } catch (ParseException e) { System.err.println("findscu: " + e.getMessage()); System.err.println(rb.getString("try")); System.exit(2); } catch (Exception e) { System.err.println("findscu: " + e.getMessage()); e.printStackTrace(); System.exit(2); } }
From source file:org.dcm4che.tool.getscu.GetSCU.java
@SuppressWarnings("unchecked") public static void main(String[] args) { try {//from www. j ava2s . c o m CommandLine cl = parseComandLine(args); GetSCU main = new GetSCU(); CLIUtils.configureConnect(main.remote, main.rq, cl); CLIUtils.configureBind(main.conn, main.ae, cl); CLIUtils.configure(main.conn, cl); main.remote.setTlsProtocols(main.conn.getTlsProtocols()); main.remote.setTlsCipherSuites(main.conn.getTlsCipherSuites()); configureServiceClass(main, cl); configureKeys(main, cl); main.setPriority(CLIUtils.priorityOf(cl)); configureStorageDirectory(main, cl); ExecutorService executorService = Executors.newSingleThreadExecutor(); ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); main.device.setExecutor(executorService); main.device.setScheduledExecutor(scheduledExecutorService); try { main.open(); List<String> argList = cl.getArgList(); if (argList.isEmpty()) main.retrieve(); else for (String arg : argList) main.retrieve(new File(arg)); } finally { main.close(); executorService.shutdown(); scheduledExecutorService.shutdown(); } } catch (ParseException e) { System.err.println("getscu: " + e.getMessage()); System.err.println(rb.getString("try")); System.exit(2); } catch (Exception e) { System.err.println("getscu: " + e.getMessage()); e.printStackTrace(); System.exit(2); } }