List of usage examples for org.apache.commons.cli Options Options
Options
From source file:com.khubla.jvmbasic.jvmbasicc.JVMBasic.java
/** * start here/*from ww w . j a va2 s . c om*/ * <p> * -file src\test\resources\bas\easy\print.bas -verbose true * </p> */ public static void main(String[] args) { try { System.out.println("khubla.com jvmBASIC Compiler"); /* * options */ final Options options = new Options(); Option oo = Option.builder().argName(OUTPUT_OPTION).longOpt(OUTPUT_OPTION).type(String.class).hasArg() .required(false).desc("target directory to output to").build(); options.addOption(oo); oo = Option.builder().argName(FILE_OPTION).longOpt(FILE_OPTION).type(String.class).hasArg() .required(true).desc("file to compile").build(); options.addOption(oo); oo = Option.builder().argName(VERBOSE_OPTION).longOpt(VERBOSE_OPTION).type(String.class).hasArg() .required(false).desc("verbose output").build(); options.addOption(oo); /* * parse */ final CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (final Exception e) { e.printStackTrace(); final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("posix", options); System.exit(0); } /* * verbose output? */ final Boolean verbose = Boolean.parseBoolean(cmd.getOptionValue(VERBOSE_OPTION)); /* * get the file */ final String filename = cmd.getOptionValue(FILE_OPTION); final String outputDirectory = cmd.getOptionValue(OUTPUT_OPTION); if (null != filename) { /* * filename */ final String basFileName = System.getProperty("user.dir") + "/" + filename; final File fl = new File(basFileName); if (true == fl.exists()) { /* * show the filename */ System.out.println("Compiling: " + fl.getCanonicalFile()); /* * compiler */ final JVMBasicCompiler jvmBasicCompiler = new JVMBasicCompiler(); /* * compile */ jvmBasicCompiler.compileToClassfile(basFileName, null, outputDirectory, verbose, true, true); } else { throw new Exception("Unable to find: '" + basFileName + "'"); } } else { throw new Exception("File was not supplied"); } } catch (final Exception e) { e.printStackTrace(); } }
From source file:de.zazaz.iot.bosch.indego.util.IndegoIftttAdapter.java
public static void main(String[] args) { System.setProperty("log4j.configurationFile", "log4j2-indegoIftttAdapter-normal.xml"); Options options = new Options(); StringBuilder commandList = new StringBuilder(); for (DeviceCommand cmd : DeviceCommand.values()) { if (commandList.length() > 0) { commandList.append(", "); }//from ww w .java2 s.com commandList.append(cmd.toString()); } options.addOption(Option // .builder("c") // .longOpt("config") // .desc("The configuration file to use") // .required() // .hasArg() // .build()); options.addOption(Option // .builder("d") // .longOpt("debug") // .desc("Logs more details") // .build()); options.addOption(Option // .builder("?") // .longOpt("help") // .desc("Prints this help") // .build()); CommandLineParser parser = new DefaultParser(); CommandLine cmds = null; try { cmds = parser.parse(options, args); } catch (ParseException ex) { System.err.println(ex.getMessage()); System.err.println(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(IndegoIftttAdapter.class.getName(), options); System.exit(1); return; } if (cmds.hasOption("?")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(CmdLineTool.class.getName(), options); return; } if (cmds.hasOption("d")) { System.setProperty("log4j.configurationFile", "log4j2-indegoIftttAdapter-debug.xml"); } String configFileName = cmds.getOptionValue('c'); File configFile = new File(configFileName); if (!configFile.exists()) { System.err.println(String.format("The specified config file (%s) does not exist", configFileName)); System.err.println(); System.exit(2); return; } Properties properties = new Properties(); try (InputStream in = new FileInputStream(configFile)) { properties.load(in); } catch (IOException ex) { System.err.println(ex.getMessage()); System.err.println(String.format("Was not able to load the properties file (%s)", configFileName)); System.err.println(); } IftttIndegoAdapterConfiguration config = new IftttIndegoAdapterConfiguration(); config.setIftttMakerKey(properties.getProperty("indego.ifttt.maker.key")); config.setIftttIgnoreServerCertificate( Integer.parseInt(properties.getProperty("indego.ifttt.maker.ignore-server-certificate")) != 0); config.setIftttReceiverPort(Integer.parseInt(properties.getProperty("indego.ifttt.maker.receiver-port"))); config.setIftttReceiverSecret(properties.getProperty("indego.ifttt.maker.receiver-secret")); config.setIftttOfflineEventName(properties.getProperty("indego.ifttt.maker.eventname-offline")); config.setIftttOnlineEventName(properties.getProperty("indego.ifttt.maker.eventname-online")); config.setIftttErrorEventName(properties.getProperty("indego.ifttt.maker.eventname-error")); config.setIftttErrorClearedEventName(properties.getProperty("indego.ifttt.maker.eventname-error-cleared")); config.setIftttStateChangeEventName(properties.getProperty("indego.ifttt.maker.eventname-state-change")); config.setIndegoBaseUrl(properties.getProperty("indego.ifttt.device.base-url")); config.setIndegoUsername(properties.getProperty("indego.ifttt.device.username")); config.setIndegoPassword(properties.getProperty("indego.ifttt.device.password")); config.setPollingIntervalMs(Integer.parseInt(properties.getProperty("indego.ifttt.polling-interval-ms"))); IftttIndegoAdapter adapter = new IftttIndegoAdapter(config); adapter.startup(); }
From source file:cc.twittertools.corpus.demo.ReadStatuses.java
@SuppressWarnings("static-access") public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input directory or file") .create(INPUT_OPTION));//w ww . j a v a 2 s .c o m options.addOption(VERBOSE_OPTION, false, "print logging output every 10000 tweets"); options.addOption(DUMP_OPTION, false, "dump statuses"); 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(INPUT_OPTION)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ReadStatuses.class.getName(), options); System.exit(-1); } PrintStream out = new PrintStream(System.out, true, "UTF-8"); StatusStream stream; // Figure out if we're reading from HTML SequenceFiles or JSON. File file = new File(cmdline.getOptionValue(INPUT_OPTION)); if (!file.exists()) { System.err.println("Error: " + file + " does not exist!"); System.exit(-1); } if (file.isDirectory()) { stream = new JsonStatusCorpusReader(file); } else { stream = new JsonStatusBlockReader(file); } int cnt = 0; Status status; while ((status = stream.next()) != null) { if (cmdline.hasOption(DUMP_OPTION)) { String text = status.getText(); if (text != null) { text = text.replaceAll("\\s+", " "); text = text.replaceAll("\0", ""); } out.println(String.format("%d\t%s\t%s\t%s", status.getId(), status.getScreenname(), status.getCreatedAt(), text)); } cnt++; if (cnt % 10000 == 0 && cmdline.hasOption(VERBOSE_OPTION)) { LOG.info(cnt + " statuses read"); } } stream.close(); LOG.info(String.format("Total of %s statuses read.", cnt)); }
From source file:de.onyxbits.raccoon.cli.Router.java
public static void main(String[] args) { Options options = new Options(); Option property = Option.builder("D").argName("property=value").numberOfArgs(2).valueSeparator() .desc(Messages.getString(DESC + "D")).build(); options.addOption(property);/*from w ww. j a va2s . co m*/ Option help = new Option("h", "help", false, Messages.getString(DESC + "h")); options.addOption(help); Option version = new Option("v", "version", false, Messages.getString(DESC + "v")); options.addOption(version); // GPA: Google Play Apps (we might add different markets later) Option playAppDetails = new Option(null, "gpa-details", true, Messages.getString(DESC + "gpa-details")); playAppDetails.setArgName("package"); options.addOption(playAppDetails); Option playAppBulkDetails = new Option(null, "gpa-bulkdetails", true, Messages.getString(DESC + "gpa-bulkdetails")); playAppBulkDetails.setArgName("file"); options.addOption(playAppBulkDetails); Option playAppBatchDetails = new Option(null, "gpa-batchdetails", true, Messages.getString(DESC + "gpa-batchdetails")); playAppBatchDetails.setArgName("file"); options.addOption(playAppBatchDetails); Option playAppSearch = new Option(null, "gpa-search", true, Messages.getString(DESC + "gpa-search")); playAppSearch.setArgName("query"); options.addOption(playAppSearch); CommandLine commandLine = null; try { commandLine = new DefaultParser().parse(options, args); } catch (ParseException e) { System.err.println(e.getMessage()); System.exit(1); } if (commandLine.hasOption(property.getOpt())) { System.getProperties().putAll(commandLine.getOptionProperties(property.getOpt())); } if (commandLine.hasOption(help.getOpt())) { new HelpFormatter().printHelp("raccoon", Messages.getString("header"), options, Messages.getString("footer"), true); System.exit(0); } if (commandLine.hasOption(version.getOpt())) { System.out.println(GlobalsProvider.getGlobals().get(Version.class)); System.exit(0); } if (commandLine.hasOption(playAppDetails.getLongOpt())) { Play.details(commandLine.getOptionValue(playAppDetails.getLongOpt())); System.exit(0); } if (commandLine.hasOption(playAppBulkDetails.getLongOpt())) { Play.bulkDetails(new File(commandLine.getOptionValue(playAppBulkDetails.getLongOpt()))); System.exit(0); } if (commandLine.hasOption(playAppBatchDetails.getLongOpt())) { Play.details(new File(commandLine.getOptionValue(playAppBatchDetails.getLongOpt()))); System.exit(0); } if (commandLine.hasOption(playAppSearch.getLongOpt())) { Play.search(commandLine.getOptionValue(playAppSearch.getLongOpt())); System.exit(0); } }
From source file:com.thimbleware.jmemcached.Main.java
public static void main(String[] args) throws Exception { // look for external log4j.properties // setup command line options Options options = new Options(); options.addOption("h", "help", false, "print this help screen"); options.addOption("bl", "block-store", false, "use external (from JVM) heap"); options.addOption("f", "mapped-file", false, "use external (from JVM) heap through a memory mapped file"); options.addOption("bs", "block-size", true, "block size (in bytes) for external memory mapped file allocator. default is 8 bytes"); options.addOption("i", "idle", true, "disconnect after idle <x> seconds"); options.addOption("p", "port", true, "port to listen on"); options.addOption("m", "memory", true, "max memory to use; in bytes, specify K, kb, M, GB for larger units"); options.addOption("c", "ceiling", true, "ceiling memory to use; in bytes, specify K, kb, M, GB for larger units"); options.addOption("l", "listen", true, "Address to listen on"); options.addOption("s", "size", true, "max items"); options.addOption("b", "binary", false, "binary protocol mode"); options.addOption("V", false, "Show version number"); options.addOption("v", false, "verbose (show commands)"); // read command line options CommandLineParser parser = new PosixParser(); CommandLine cmdline = parser.parse(options, args); if (cmdline.hasOption("help") || cmdline.hasOption("h")) { System.out.println("Memcached Version " + MemCacheDaemon.memcachedVersion); System.out.println("http://thimbleware.com/projects/memcached\n"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar memcached.jar", options); return;//from ww w .j ava 2 s . co m } if (cmdline.hasOption("V")) { System.out.println("Memcached Version " + MemCacheDaemon.memcachedVersion); return; } int port = 11211; if (cmdline.hasOption("p")) { port = Integer.parseInt(cmdline.getOptionValue("p")); } else if (cmdline.hasOption("port")) { port = Integer.parseInt(cmdline.getOptionValue("port")); } InetSocketAddress addr = new InetSocketAddress(port); if (cmdline.hasOption("l")) { addr = new InetSocketAddress(cmdline.getOptionValue("l"), port); } else if (cmdline.hasOption("listen")) { addr = new InetSocketAddress(cmdline.getOptionValue("listen"), port); } int max_size = 1000000; if (cmdline.hasOption("s")) max_size = (int) Bytes.valueOf(cmdline.getOptionValue("s")).bytes(); else if (cmdline.hasOption("size")) max_size = (int) Bytes.valueOf(cmdline.getOptionValue("size")).bytes(); System.out.println("Setting max cache elements to " + String.valueOf(max_size)); int idle = -1; if (cmdline.hasOption("i")) { idle = Integer.parseInt(cmdline.getOptionValue("i")); } else if (cmdline.hasOption("idle")) { idle = Integer.parseInt(cmdline.getOptionValue("idle")); } boolean memoryMapped = false; if (cmdline.hasOption("f")) { memoryMapped = true; } else if (cmdline.hasOption("mapped-file")) { memoryMapped = true; } boolean blockStore = false; if (cmdline.hasOption("bl")) { blockStore = true; } else if (cmdline.hasOption("block-store")) { blockStore = true; } boolean verbose = false; if (cmdline.hasOption("v")) { verbose = true; } long ceiling; if (cmdline.hasOption("c")) { ceiling = Bytes.valueOf(cmdline.getOptionValue("c")).bytes(); System.out.println("Setting ceiling memory size to " + Bytes.bytes(ceiling).megabytes() + "M"); } else if (cmdline.hasOption("ceiling")) { ceiling = Bytes.valueOf(cmdline.getOptionValue("ceiling")).bytes(); System.out.println("Setting ceiling memory size to " + Bytes.bytes(ceiling).megabytes() + "M"); } else if (!memoryMapped) { ceiling = 1024000; System.out.println( "Setting ceiling memory size to default limit of " + Bytes.bytes(ceiling).megabytes() + "M"); } else { System.out .println("ERROR : ceiling memory size mandatory when external memory mapped file is specified"); return; } boolean binary = false; if (cmdline.hasOption("b")) { binary = true; } int blockSize = 8; if (!memoryMapped && (cmdline.hasOption("bs") || cmdline.hasOption("block-size"))) { System.out.println( "WARN : block size option is only valid for memory mapped external heap storage; ignoring"); } else if (cmdline.hasOption("bs")) { blockSize = Integer.parseInt(cmdline.getOptionValue("bs")); } else if (cmdline.hasOption("block-size")) { blockSize = Integer.parseInt(cmdline.getOptionValue("block-size")); } long maxBytes; if (cmdline.hasOption("m")) { maxBytes = Bytes.valueOf(cmdline.getOptionValue("m")).bytes(); System.out.println("Setting max memory size to " + Bytes.bytes(maxBytes).gigabytes() + "GB"); } else if (cmdline.hasOption("memory")) { maxBytes = Bytes.valueOf(cmdline.getOptionValue("memory")).bytes(); System.out.println("Setting max memory size to " + Bytes.bytes(maxBytes).gigabytes() + "GB"); } else if (!memoryMapped) { maxBytes = Runtime.getRuntime().maxMemory(); System.out .println("Setting max memory size to JVM limit of " + Bytes.bytes(maxBytes).gigabytes() + "GB"); } else { System.out.println( "ERROR : max memory size and ceiling size are mandatory when external memory mapped file is specified"); return; } if (!memoryMapped && !blockStore && maxBytes > Runtime.getRuntime().maxMemory()) { System.out.println("ERROR : JVM heap size is not big enough. use '-Xmx" + String.valueOf(maxBytes / 1024000) + "m' java argument before the '-jar' option."); return; } else if ((memoryMapped || !blockStore) && maxBytes > Integer.MAX_VALUE) { System.out.println( "ERROR : when external memory mapped, memory size may not exceed the size of Integer.MAX_VALUE (" + Bytes.bytes(Integer.MAX_VALUE).gigabytes() + "GB"); return; } // create daemon and start it final MemCacheDaemon<LocalCacheElement> daemon = new MemCacheDaemon<LocalCacheElement>(); CacheStorage<Key, LocalCacheElement> storage; if (blockStore) { BlockStoreFactory blockStoreFactory = ByteBufferBlockStore.getFactory(); storage = new BlockStorageCacheStorage(8, (int) ceiling, blockSize, maxBytes, max_size, blockStoreFactory); } else if (memoryMapped) { BlockStoreFactory blockStoreFactory = MemoryMappedBlockStore.getFactory(); storage = new BlockStorageCacheStorage(8, (int) ceiling, blockSize, maxBytes, max_size, blockStoreFactory); } else { storage = ConcurrentLinkedHashMap.create(ConcurrentLinkedHashMap.EvictionPolicy.FIFO, max_size, maxBytes); } daemon.setCache(new CacheImpl(storage)); daemon.setBinary(binary); daemon.setAddr(addr); daemon.setIdleTime(idle); daemon.setVerbose(verbose); daemon.start(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { if (daemon.isRunning()) daemon.stop(); } })); }
From source file:com.partagames.imageresizetool.SimpleImageResizeTool.java
public static void main(String[] args) throws Exception { options = new Options(); // required options options.addOption(/*from www.j a va 2 s .co m*/ Option.builder(ARG_DIMENSIONS_SHORT).longOpt(ARG_DIMENSIONS).hasArg(true).optionalArg(false) .desc("Target image dimensions in pixels (e.g 1280x720)").required(true).build()); // optional options options.addOption(Option.builder(ARG_FORMAT_SHORT).longOpt(ARG_FORMAT).hasArg(true).optionalArg(false) .desc("Image output format (png,jpg,gif)").required(false).build()); options.addOption(Option.builder(ARG_OUTPUT_SHORT).longOpt(ARG_OUTPUT).hasArg(true).optionalArg(false) .desc("Image output folder").required(false).build()); options.addOption(Option.builder(ARG_HINT_SHORT).longOpt(ARG_HINT).hasArg(true).optionalArg(false) .desc("Scaling hint (n=nearest, b=bilinear)").required(false).build()); options.addOption(Option.builder(ARG_HELP_SHORT).longOpt(ARG_HELP).hasArg(false) .desc("Shows this help message.").required(false).build()); if (parseAndPrepareArguments(args, options)) { createBufferedImages(); resizeAndWriteImages(); } }
From source file:mx.unam.fesa.mss.MSSMain.java
/** * @param args// ww w . ja v a2 s .c om */ @SuppressWarnings("static-access") public static void main(String[] args) { // // managing command line options using commons-cli // Options options = new Options(); // help option // options.addOption( OptionBuilder.withDescription("Prints this message.").withLongOpt("help").create(OPT_HELP)); // port option // options.addOption(OptionBuilder.withDescription("The port in which the MineSweeperServer will listen to.") .hasArg().withType(new Integer(0)).withArgName("PORT").withLongOpt("port").create(OPT_PORT)); // parsing options // int port = DEFAULT_PORT; try { // using GNU standard // CommandLine line = new GnuParser().parse(options, args); if (line.hasOption(OPT_HELP)) { new HelpFormatter().printHelp("mss [options]", options); return; } if (line.hasOption(OPT_PORT)) { try { port = (Integer) line.getOptionObject(OPT_PORT); } catch (Exception e) { } } } catch (ParseException e) { System.err.println("Could not parse command line options correctly: " + e.getMessage()); return; } // // configuring logging services // try { LogManager.getLogManager() .readConfiguration(ClassLoader.getSystemResourceAsStream(DEFAULT_LOGGING_CONFIG_FILE)); } catch (Exception e) { throw new Error("Could not load logging properties file", e); } // // setting up UDP server // try { new MSServer(port); } catch (Exception e) { LoggerFactory.getLogger(MSSMain.class).error("Could not execute MineSweeper server: ", e); } }
From source file:com.xafero.vee.cmd.MainApp.java
public static void main(String[] args) { // Define options Option help = new Option("?", "help", false, "print this message"); Option version = new Option("v", "version", false, "print the version information and exit"); Option eval = Option.builder("e").desc("evaluate script").argName("file").longOpt("eval").hasArg().build(); Option list = new Option("l", "list", false, "print all available languages"); // Collect them Options options = new Options(); options.addOption(help);//from w w w. java2s.c om options.addOption(version); options.addOption(eval); options.addOption(list); // If nothing given, nothing will happen if (args == null || args.length < 1) { printHelp(options); return; } // Parse command line try { CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(options, args); // Work on it process(line, options); } catch (Throwable e) { System.err.printf("Error occurred: %n " + e.getMessage()); } }
From source file:net.sf.mcf2pdf.Main.java
@SuppressWarnings("static-access") public static void main(String[] args) { Options options = new Options(); Option o = OptionBuilder.hasArg().isRequired() .withDescription("Installation location of My CEWE Photobook. REQUIRED.").create('i'); options.addOption(o);/*from www . j a va 2 s . co m*/ options.addOption("h", false, "Prints this help and exits."); options.addOption("t", true, "Location of MCF temporary files."); options.addOption("w", true, "Location for temporary images generated during conversion."); options.addOption("r", true, "Sets the resolution to use for page rendering, in DPI. Default is 150."); options.addOption("n", true, "Sets the page number to render up to. Default renders all pages."); options.addOption("b", false, "Prevents rendering of binding between double pages."); options.addOption("x", false, "Generates only XSL-FO content instead of PDF content."); options.addOption("q", false, "Quiet mode - only errors are logged."); options.addOption("d", false, "Enables debugging logging output."); CommandLine cl; try { CommandLineParser parser = new PosixParser(); cl = parser.parse(options, args); } catch (ParseException pe) { printUsage(options, pe); System.exit(3); return; } if (cl.hasOption("h")) { printUsage(options, null); return; } if (cl.getArgs().length != 2) { printUsage(options, new ParseException("INFILE and OUTFILE must be specified. Arguments were: " + cl.getArgList())); System.exit(3); return; } File installDir = new File(cl.getOptionValue("i")); if (!installDir.isDirectory()) { printUsage(options, new ParseException("Specified installation directory does not exist.")); System.exit(3); return; } File tempDir = null; String sTempDir = cl.getOptionValue("t"); if (sTempDir == null) { tempDir = new File(new File(System.getProperty("user.home")), ".mcf"); if (!tempDir.isDirectory()) { printUsage(options, new ParseException("MCF temporary location not specified and default location " + tempDir + " does not exist.")); System.exit(3); return; } } else { tempDir = new File(sTempDir); if (!tempDir.isDirectory()) { printUsage(options, new ParseException("Specified temporary location does not exist.")); System.exit(3); return; } } File mcfFile = new File(cl.getArgs()[0]); if (!mcfFile.isFile()) { printUsage(options, new ParseException("MCF input file does not exist.")); System.exit(3); return; } mcfFile = mcfFile.getAbsoluteFile(); File tempImages = new File(new File(System.getProperty("user.home")), ".mcf2pdf"); if (cl.hasOption("w")) { tempImages = new File(cl.getOptionValue("w")); if (!tempImages.mkdirs() && !tempImages.isDirectory()) { printUsage(options, new ParseException("Specified working dir does not exist and could not be created.")); System.exit(3); return; } } int dpi = 150; if (cl.hasOption("r")) { try { dpi = Integer.valueOf(cl.getOptionValue("r")).intValue(); if (dpi < 30 || dpi > 600) throw new IllegalArgumentException(); } catch (Exception e) { printUsage(options, new ParseException("Parameter for option -r must be an integer between 30 and 600.")); } } int maxPageNo = -1; if (cl.hasOption("n")) { try { maxPageNo = Integer.valueOf(cl.getOptionValue("n")).intValue(); if (maxPageNo < 0) throw new IllegalArgumentException(); } catch (Exception e) { printUsage(options, new ParseException("Parameter for option -n must be an integer >= 0.")); } } boolean binding = true; if (cl.hasOption("b")) { binding = false; } OutputStream finalOut; if (cl.getArgs()[1].equals("-")) finalOut = System.out; else { try { finalOut = new FileOutputStream(cl.getArgs()[1]); } catch (IOException e) { printUsage(options, new ParseException("Output file could not be created.")); System.exit(3); return; } } // configure logging, if no system property is present if (System.getProperty("log4j.configuration") == null) { PropertyConfigurator.configure(Main.class.getClassLoader().getResource("log4j.properties")); Logger.getRootLogger().setLevel(Level.INFO); if (cl.hasOption("q")) Logger.getRootLogger().setLevel(Level.ERROR); if (cl.hasOption("d")) Logger.getRootLogger().setLevel(Level.DEBUG); } // start conversion to XSL-FO // if -x is specified, this is the only thing we do OutputStream xslFoOut; if (cl.hasOption("x")) xslFoOut = finalOut; else xslFoOut = new ByteArrayOutputStream(); Log log = LogFactory.getLog(Main.class); try { new Mcf2FoConverter(installDir, tempDir, tempImages).convert(mcfFile, xslFoOut, dpi, binding, maxPageNo); xslFoOut.flush(); if (!cl.hasOption("x")) { // convert to PDF log.debug("Converting XSL-FO data to PDF"); byte[] data = ((ByteArrayOutputStream) xslFoOut).toByteArray(); PdfUtil.convertFO2PDF(new ByteArrayInputStream(data), finalOut, dpi); finalOut.flush(); } } catch (Exception e) { log.error("An exception has occured", e); System.exit(1); return; } finally { if (finalOut instanceof FileOutputStream) { try { finalOut.close(); } catch (Exception e) { } } } }
From source file:com.adobe.aem.demo.Analytics.java
public static void main(String[] args) { String hostname = null;//from w ww . ja v a 2s . c o m String url = null; String eventfile = null; // Command line options for this tool Options options = new Options(); options.addOption("h", true, "Hostname"); options.addOption("u", true, "Url"); options.addOption("f", true, "Event data file"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("u")) { url = cmd.getOptionValue("u"); } if (cmd.hasOption("f")) { eventfile = cmd.getOptionValue("f"); } if (cmd.hasOption("h")) { hostname = cmd.getOptionValue("h"); } if (eventfile == null || hostname == null || url == null) { System.out.println("Command line parameters: -h hostname -u url -f path_to_XML_file"); System.exit(-1); } } catch (ParseException ex) { logger.error(ex.getMessage()); } URLConnection urlConn = null; DataOutputStream printout = null; BufferedReader input = null; String u = "http://" + hostname + "/" + url; String tmp = null; try { URL myurl = new URL(u); urlConn = myurl.openConnection(); urlConn.setDoInput(true); urlConn.setDoOutput(true); urlConn.setUseCaches(false); urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); printout = new DataOutputStream(urlConn.getOutputStream()); String xml = readFile(eventfile, StandardCharsets.UTF_8); printout.writeBytes(xml); printout.flush(); printout.close(); input = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); logger.debug(xml); while (null != ((tmp = input.readLine()))) { logger.debug(tmp); } printout.close(); input.close(); } catch (Exception ex) { logger.error(ex.getMessage()); } }