List of usage examples for org.apache.commons.cli OptionBuilder withLongOpt
public static OptionBuilder withLongOpt(String newLongopt)
From source file:com.samsung.sjs.Compiler.java
@SuppressWarnings("static-access") public static void main(String[] args) throws IOException, SolverException, InterruptedException { boolean debug = false; boolean use_gc = true; CompilerOptions.Platform p = CompilerOptions.Platform.Native; CompilerOptions opts = null;/*from w ww. j av a 2s . c o m*/ boolean field_opts = false; boolean typecheckonly = false; boolean showconstraints = false; boolean showconstraintsolution = false; String[] decls = null; String[] links = null; String[] objs = null; boolean guest = false; boolean stop_at_c = false; String external_compiler = null; boolean encode_vals = false; boolean x32 = false; boolean validate = true; boolean interop = false; boolean boot_interop = false; boolean oldExpl = false; String explanationStrategy = null; boolean efl = false; Options options = new Options(); options.addOption("debugcompiler", false, "Enable compiler debug spew"); //options.addOption("o", true, "Set compiler output file (must be .c)"); options.addOption(OptionBuilder //.withArgName("o") .withLongOpt("output-file").withDescription("Output file (must be .c)").hasArg().withArgName("file") .create("o")); options.addOption(OptionBuilder.withLongOpt("target") .withDescription("Select target platform: 'native' or 'web'").hasArg().create()); options.addOption(OptionBuilder.withLongOpt("gc") .withDescription("Disable GC: param is 'on' (default) or 'off'").hasArg().create()); options.addOption(OptionBuilder .withDescription("Enable field access optimizations: param is 'true' (default) or 'false'").hasArg() .create("Xfields")); options.addOption(OptionBuilder .withDescription("Compile for encoded values. TEMPORARY. For testing interop codegen").hasArg() .create("XEncodedValues")); options.addOption(OptionBuilder.withLongOpt("typecheck-only") .withDescription("Only typecheck the file, don't compile").create()); options.addOption(OptionBuilder.withLongOpt("show-constraints") .withDescription("Show constraints generated during type inference").create()); options.addOption(OptionBuilder.withLongOpt("show-constraint-solution") .withDescription("Show solution to type inference constraints").create()); options.addOption(OptionBuilder.withLongOpt("extra-decls") .withDescription("Specify extra declaration files, comma-separated").hasArg() .withValueSeparator(',').create()); options.addOption(OptionBuilder.withLongOpt("native-libs") .withDescription("Specify extra linkage files, comma-separated").hasArg().withValueSeparator(',') .create()); Option extraobjs = OptionBuilder.withLongOpt("extra-objs") .withDescription("Specify extra .c/.cpp files, comma-separated").hasArg().withValueSeparator(',') .create(); extraobjs.setArgs(Option.UNLIMITED_VALUES); options.addOption(extraobjs); options.addOption(OptionBuilder.withLongOpt("guest-runtime") .withDescription( "Emit code to be called by another runtime (i.e., main() is written in another language).") .create()); options.addOption(OptionBuilder.withLongOpt("only-c") .withDescription("Generate C code, but do not attempt to compile it").create()); options.addOption(OptionBuilder.withLongOpt("c-compiler") .withDescription("Disable GC: param is 'on' (default) or 'off'").hasArg().create("cc")); options.addOption(OptionBuilder.withLongOpt("runtime-src") .withDescription("Specify path to runtime system source").hasArg().create()); options.addOption(OptionBuilder.withLongOpt("ext-path") .withDescription("Specify path to external dependency dir (GC, etc.)").hasArg().create()); options.addOption(OptionBuilder.withLongOpt("skip-validation") .withDescription("Run the backend without validating the results of type inference").create()); options.addOption(OptionBuilder.withLongOpt("m32").withDescription("Force 32-bit compilation").create()); options.addOption(OptionBuilder.withLongOpt("Xbootinterop") .withDescription("Programs start with global interop dirty flag set (experimental)").create()); options.addOption(OptionBuilder.withLongOpt("Xinterop") .withDescription("Enable (experimental) interoperability backend").create()); options.addOption(OptionBuilder.withDescription("C compiler default optimization level").create("O")); options.addOption(OptionBuilder.withDescription("C compiler optimization level 0").create("O0")); options.addOption(OptionBuilder.withDescription("C compiler optimization level 1").create("O1")); options.addOption(OptionBuilder.withDescription("C compiler optimization level 2").create("O2")); options.addOption(OptionBuilder.withDescription("C compiler optimization level 3").create("O3")); options.addOption( OptionBuilder.withLongOpt("oldExpl").withDescription("Use old error explanations").create()); String explanationStrategyHelp = "default: " + FixingSetFinder.defaultStrategy() + "; other choices: " + FixingSetFinder.strategyNames().stream().filter(s -> !s.equals(FixingSetFinder.defaultStrategy())) .collect(Collectors.joining(", ")); options.addOption(OptionBuilder.withLongOpt("explanation-strategy") .withDescription("Error explanation strategy to use (" + explanationStrategyHelp + ')').hasArg() .create()); options.addOption( OptionBuilder.withLongOpt("efl").withDescription("Set up efl environment in main()").create()); try { CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); String[] newargs = cmd.getArgs(); if (newargs.length != 1) { throw new ParseException("Invalid number of arguments"); } String sourcefile = newargs[0]; if (!sourcefile.endsWith(".js")) { throw new ParseException("Invalid file extension on input file: " + sourcefile); } String gc = cmd.getOptionValue("gc", "on"); if (gc.equals("on")) { use_gc = true; } else if (gc.equals("off")) { use_gc = false; } else { throw new ParseException("Invalid GC option: " + gc); } String fields = cmd.getOptionValue("Xfields", "true"); if (fields.equals("true")) { field_opts = true; } else if (fields.equals("false")) { field_opts = false; } else { throw new ParseException("Invalid field optimization option: " + fields); } String encoding = cmd.getOptionValue("XEncodedValues", "false"); if (encoding.equals("true")) { encode_vals = true; } else if (encoding.equals("false")) { encode_vals = false; } else { throw new ParseException("Invalid value encoding option: " + encode_vals); } String plat = cmd.getOptionValue("target", "native"); if (plat.equals("native")) { p = CompilerOptions.Platform.Native; } else if (plat.equals("web")) { p = CompilerOptions.Platform.Web; } else { throw new ParseException("Invalid target platform: " + plat); } if (cmd.hasOption("cc")) { external_compiler = cmd.getOptionValue("cc"); } if (cmd.hasOption("skip-validation")) { validate = false; } if (cmd.hasOption("typecheck-only")) { typecheckonly = true; } if (cmd.hasOption("show-constraints")) { showconstraints = true; } if (cmd.hasOption("show-constraint-solution")) { showconstraintsolution = true; } if (cmd.hasOption("debugcompiler")) { debug = true; } if (cmd.hasOption("m32")) { x32 = true; } if (cmd.hasOption("Xinterop")) { interop = true; } if (cmd.hasOption("Xbootinterop")) { boot_interop = true; if (!interop) { System.err.println("WARNING: --Xbootinterop enabled without --Xinterop (no effect)"); } } if (cmd.hasOption("oldExpl")) { oldExpl = true; } if (cmd.hasOption("explanation-strategy")) { explanationStrategy = cmd.getOptionValue("explanation-strategy"); } String output = cmd.getOptionValue("o"); if (output == null) { output = sourcefile.replaceFirst(".js$", ".c"); } else { if (!output.endsWith(".c")) { throw new ParseException("Invalid file extension on output file: " + output); } } String runtime_src = cmd.getOptionValue("runtime-src"); String ext_path = cmd.getOptionValue("ext-path"); if (ext_path == null) { ext_path = new File(".").getCanonicalPath() + "/external"; } if (cmd.hasOption("extra-decls")) { decls = cmd.getOptionValues("extra-decls"); } if (cmd.hasOption("native-libs")) { links = cmd.getOptionValues("native-libs"); } if (cmd.hasOption("extra-objs")) { objs = cmd.getOptionValues("extra-objs"); } if (cmd.hasOption("guest-runtime")) { guest = true; } if (cmd.hasOption("only-c")) { stop_at_c = true; } if (cmd.hasOption("efl")) { efl = true; } int coptlevel = -1; // default optimization if (cmd.hasOption("O3")) { coptlevel = 3; } else if (cmd.hasOption("O2")) { coptlevel = 2; } else if (cmd.hasOption("O1")) { coptlevel = 1; } else if (cmd.hasOption("O0")) { coptlevel = 0; } else if (cmd.hasOption("O")) { coptlevel = -1; } else { coptlevel = 3; } if (!Files.exists(Paths.get(sourcefile))) { System.err.println("File " + sourcefile + " was not found."); throw new FileNotFoundException(sourcefile); } String cwd = new java.io.File(".").getCanonicalPath(); opts = new CompilerOptions(p, sourcefile, debug, output, use_gc, external_compiler == null ? "clang" : external_compiler, external_compiler == null ? "emcc" : external_compiler, cwd + "/a.out", // emcc automatically adds .js new File(".").getCanonicalPath(), true, field_opts, showconstraints, showconstraintsolution, runtime_src, encode_vals, x32, oldExpl, explanationStrategy, efl, coptlevel); if (guest) { opts.setGuestRuntime(); } if (interop) { opts.enableInteropMode(); } if (boot_interop) { opts.startInInteropMode(); } opts.setExternalDeps(ext_path); if (decls != null) { for (String s : decls) { Path fname = FileSystems.getDefault().getPath(s); opts.addDeclarationFile(fname); } } if (links != null) { for (String s : links) { Path fname = FileSystems.getDefault().getPath(s); opts.addLinkageFile(fname); } } if (objs == null) { objs = new String[0]; } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("sjsc", options); } if (opts != null) { // This typechecks, and depending on flags, also generates C compile(opts, typecheckonly, validate); // don't worry about type validation on command line for now if (!typecheckonly && !stop_at_c) { int ret = 0; // Kept around for debugging 32-bit... if (p == CompilerOptions.Platform.Native) { if (opts.m32()) { String[] x = new String[2]; x[0] = "-m32"; x[1] = opts.getExternalDeps() + "/gc/x86/lib/libgc.a"; ret = clang_compile(opts, objs, x); } else { ret = clang_compile(opts, objs, new String[0]); } } else { ret = emcc_compile(opts, objs, new String[0]); } // If clang failed, propagate the failure outwards if (ret != 0) { System.exit(ret); } } } }
From source file:com.svds.genericconsumer.main.GenericConsumerGroup.java
/** * Given command-line arguments, create GenericConsumerGroup * /*from w w w . j a v a 2 s . c om*/ * @param args command-line arguments to parse * @throws IOException */ public static void main(String[] args) throws IOException { LOG.info("HELLO from main"); Options options = new Options(); options.addOption(OptionBuilder.isRequired().withLongOpt(ZOOKEEPER).withDescription("Zookeeper servers") .hasArg().create()); options.addOption(OptionBuilder.isRequired().withLongOpt(GROUPID).withDescription("Kafka group id").hasArg() .create()); options.addOption(OptionBuilder.isRequired().withLongOpt(TOPICNAME).withDescription("Kafka topic name") .hasArg().create()); options.addOption(OptionBuilder.isRequired().withLongOpt(THREADS).withType(Number.class) .withDescription("Number of threads").hasArg().create()); options.addOption(OptionBuilder.isRequired().withLongOpt(CONSUMERCLASS) .withDescription("Consumer Class from processing topic name").hasArg().create()); options.addOption(OptionBuilder.withLongOpt(PARAMETERS) .withDescription("Parameters needed for the consumer Class if needed").hasArgs() .withValueSeparator(',').create()); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { LOG.error(e.getMessage(), e); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("GenericConsumerGroup.main", options); throw new IOException(e); } try { GenericConsumerGroup consumerGroupExample = new GenericConsumerGroup(); consumerGroupExample.doWork(cmd); } catch (ParseException ex) { LOG.error("Error parsing command-line args"); throw new IOException(ex); } }
From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.evaluation.CouchDbExport.java
@SuppressWarnings("static-access") public static void main(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("host") .withDescription("(optional) The couchdb host. default: 127.0.0.1").hasArg().create()); options.addOption(OptionBuilder.withLongOpt("port") .withDescription("(optional) The couchdb port. default: 5984").hasArg().create()); options.addOption(OptionBuilder.withLongOpt("username") .withDescription("(optional) The couchdb username. default: <empty>").hasArg().create()); options.addOption(OptionBuilder.withLongOpt("password") .withDescription("(optional) The couchdb password. default: <empty>").hasArg().create()); options.addOption(OptionBuilder.withLongOpt("dbname") .withDescription("(optional) The couchdb database name. default: noun_decompounding").hasArg() .create());/*from ww w . j a v a2 s . co m*/ options.addOption(OptionBuilder.withLongOpt("limit") .withDescription("(optional) The amount of documents you want to export. default: all").hasArg() .create()); CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("countTotalFreq", options); return; } String host = (cmd.hasOption("host")) ? cmd.getOptionValue("host") : "127.0.0.1"; int port = Integer.parseInt((cmd.hasOption("port")) ? cmd.getOptionValue("port") : "5984"); String username = (cmd.hasOption("username")) ? cmd.getOptionValue("username") : ""; String password = (cmd.hasOption("password")) ? cmd.getOptionValue("password") : ""; String dbName = (cmd.hasOption("dbname")) ? cmd.getOptionValue("dbname") : ""; int limit = (cmd.hasOption("limit")) ? Integer.parseInt(cmd.getOptionValue("limit")) : Integer.MAX_VALUE; IDictionary dict = new IGerman98Dictionary(new File("src/main/resources/de_DE.dic"), new File("src/main/resources/de_DE.aff")); LinkingMorphemes morphemes = new LinkingMorphemes(new File("src/main/resources/linkingMorphemes.txt")); LeftToRightSplitAlgorithm algo = new LeftToRightSplitAlgorithm(dict, morphemes); HttpClient httpClient = new StdHttpClient.Builder().host(host).port(port).username(username) .password(password).build(); CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient); CouchDbConnector db = new StdCouchDbConnector(dbName, dbInstance); try { CouchDbExport exporter = new CouchDbExport( new CcorpusReader(new File("src/main/resources/evaluation/ccorpus.txt")), db); exporter.export(algo, limit); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:com.examples.cloud.speech.AsyncRecognizeClient.java
public static void main(String[] args) throws Exception { String audioFile = ""; String host = "speech.googleapis.com"; Integer port = 443;//from w w w . j a va 2s. co m Integer sampling = 16000; CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("uri").withDescription("path to audio uri").hasArg() .withArgName("FILE_PATH").create()); options.addOption( OptionBuilder.withLongOpt("host").withDescription("endpoint for api, e.g. speech.googleapis.com") .hasArg().withArgName("ENDPOINT").create()); options.addOption(OptionBuilder.withLongOpt("port").withDescription("SSL port, usually 443").hasArg() .withArgName("PORT").create()); options.addOption(OptionBuilder.withLongOpt("sampling").withDescription("Sampling Rate, i.e. 16000") .hasArg().withArgName("RATE").create()); try { CommandLine line = parser.parse(options, args); if (line.hasOption("uri")) { audioFile = line.getOptionValue("uri"); } else { System.err.println("An Audio uri must be specified (e.g. file:///foo/baz.raw)."); System.exit(1); } if (line.hasOption("host")) { host = line.getOptionValue("host"); } else { System.err.println("An API enpoint must be specified (typically speech.googleapis.com)."); System.exit(1); } if (line.hasOption("port")) { port = Integer.parseInt(line.getOptionValue("port")); } else { System.err.println("An SSL port must be specified (typically 443)."); System.exit(1); } if (line.hasOption("sampling")) { sampling = Integer.parseInt(line.getOptionValue("sampling")); } else { System.err.println("An Audio sampling rate must be specified."); System.exit(1); } } catch (ParseException exp) { System.err.println("Unexpected exception:" + exp.getMessage()); System.exit(1); } ManagedChannel channel = AsyncRecognizeClient.createChannel(host, port); AsyncRecognizeClient client = new AsyncRecognizeClient(channel, URI.create(audioFile), sampling); try { client.recognize(); } finally { client.shutdown(); } }
From source file:com.algollabs.rgx.java
public static void main(String[] args) throws Exception { CommandLine cli;/*from w w w. j a v a 2 s.co m*/ // create the command line parser CommandLineParser parser = new GnuParser(); // create the Options options.addOption("h", "help", false, "print this help message"); options.addOption("d", "daemonize", false, "run rgx:Java as a daemon"); options.addOption(OptionBuilder.withLongOpt("pattern") .withDescription("Java regular expression raw pattern").hasArg().withArgName("PATTERN").create()); options.addOption(OptionBuilder.withLongOpt("subject") .withDescription("subject to test the pattern against").hasArg().withArgName("SUBJECT").create()); options.addOption( OptionBuilder.withLongOpt("interface").withDescription("the interface to bind to when daemonized") .hasArg().withArgName("INTERFACE").create()); options.addOption(OptionBuilder.withLongOpt("port").withDescription("the port to bind to when daemonized") .hasArg().withArgName("PORT").create()); try { // parse the command line arguments cli = parser.parse(options, args); } catch (ParseException exp) { System.out.println("Unexpected exception:" + exp.getMessage()); return; } if (cli.hasOption("help")) { printHelp(); return; } if (cli.hasOption("daemonize")) { String port = "9400"; String host = "0.0.0.0"; if (cli.hasOption("port")) { port = cli.getOptionValue("port"); } if (cli.hasOption("interface")) { host = cli.getOptionValue("interface"); } Container container = new rgx(); Server server = new ContainerServer(container); Connection connection = new SocketConnection(server); SocketAddress address = new InetSocketAddress(host, Integer.parseInt(port)); connection.connect(address); System.out.println("Accepting requests on " + host + ":" + port); } else { String ptrn = null; String subj = null; String flags = null; if (!cli.hasOption("pattern") || !cli.hasOption("subject")) { printHelp(); return; } ptrn = cli.getOptionValue("pattern"); subj = cli.getOptionValue("subject"); if (cli.hasOption("flags")) flags = cli.getOptionValue("flags"); System.out.println(new Construct(ptrn, subj, flags, false).test()); } }
From source file:com.examples.cloud.speech.StreamingRecognizeClient.java
public static void main(String[] args) throws Exception { String audioFile = ""; String host = "speech.googleapis.com"; Integer port = 443;/*from w ww . ja v a 2 s . com*/ Integer sampling = 16000; CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("file").withDescription("path to audio file").hasArg() .withArgName("FILE_PATH").create()); options.addOption( OptionBuilder.withLongOpt("host").withDescription("endpoint for api, e.g. speech.googleapis.com") .hasArg().withArgName("ENDPOINT").create()); options.addOption(OptionBuilder.withLongOpt("port").withDescription("SSL port, usually 443").hasArg() .withArgName("PORT").create()); options.addOption(OptionBuilder.withLongOpt("sampling").withDescription("Sampling Rate, i.e. 16000") .hasArg().withArgName("RATE").create()); try { CommandLine line = parser.parse(options, args); if (line.hasOption("file")) { audioFile = line.getOptionValue("file"); } else { System.err.println("An Audio file must be specified (e.g. /foo/baz.raw)."); System.exit(1); } if (line.hasOption("host")) { host = line.getOptionValue("host"); } else { System.err.println("An API enpoint must be specified (typically speech.googleapis.com)."); System.exit(1); } if (line.hasOption("port")) { port = Integer.parseInt(line.getOptionValue("port")); } else { System.err.println("An SSL port must be specified (typically 443)."); System.exit(1); } if (line.hasOption("sampling")) { sampling = Integer.parseInt(line.getOptionValue("sampling")); } else { System.err.println("An Audio sampling rate must be specified."); System.exit(1); } } catch (ParseException exp) { System.err.println("Unexpected exception:" + exp.getMessage()); System.exit(1); } ManagedChannel channel = AsyncRecognizeClient.createChannel(host, port); StreamingRecognizeClient client = new StreamingRecognizeClient(channel, audioFile, sampling); try { client.recognize(); } finally { client.shutdown(); } }
From source file:com.astexample.Recognize.java
public static void main(String[] args) throws Exception { String audioFile = ""; String host = "speech.googleapis.com"; Integer port = 443;/*w w w. ja v a 2s . c o m*/ Integer sampling = 16000; CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("file").withDescription("path to audio file").hasArg() .withArgName("FILE_PATH").create()); options.addOption( OptionBuilder.withLongOpt("host").withDescription("endpoint for api, e.g. speech.googleapis.com") .hasArg().withArgName("ENDPOINT").create()); options.addOption(OptionBuilder.withLongOpt("port").withDescription("SSL port, usually 443").hasArg() .withArgName("PORT").create()); options.addOption(OptionBuilder.withLongOpt("sampling").withDescription("Sampling Rate, i.e. 16000") .hasArg().withArgName("RATE").create()); try { CommandLine line = parser.parse(options, args); if (line.hasOption("file")) { audioFile = line.getOptionValue("file"); } else { System.err.println("An Audio file must be specified (e.g. /foo/baz.raw)."); System.exit(1); } if (line.hasOption("host")) { host = line.getOptionValue("host"); } else { System.err.println("An API enpoint must be specified (typically speech.googleapis.com)."); System.exit(1); } if (line.hasOption("port")) { port = Integer.parseInt(line.getOptionValue("port")); } else { System.err.println("An SSL port must be specified (typically 443)."); System.exit(1); } if (line.hasOption("sampling")) { sampling = Integer.parseInt(line.getOptionValue("sampling")); } else { System.err.println("An Audio sampling rate must be specified."); System.exit(1); } } catch (ParseException exp) { System.err.println("Unexpected exception:" + exp.getMessage()); System.exit(1); } Recognize client = new Recognize(host, port, audioFile, sampling); try { client.recognize(); } finally { client.shutdown(); } }
From source file:com.astexample.RecognizeGoogleTest.java
public static void main(String[] args) throws Exception { String audioFile = ""; String host = "speech.googleapis.com"; Integer port = 443;/*from ww w .j a v a 2s .c o m*/ Integer sampling = 16000; CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("file").withDescription("path to audio file").hasArg() .withArgName("FILE_PATH").create()); options.addOption( OptionBuilder.withLongOpt("host").withDescription("endpoint for api, e.g. speech.googleapis.com") .hasArg().withArgName("ENDPOINT").create()); options.addOption(OptionBuilder.withLongOpt("port").withDescription("SSL port, usually 443").hasArg() .withArgName("PORT").create()); options.addOption(OptionBuilder.withLongOpt("sampling").withDescription("Sampling Rate, i.e. 16000") .hasArg().withArgName("RATE").create()); try { CommandLine line = parser.parse(options, args); if (line.hasOption("file")) { audioFile = line.getOptionValue("file"); } else { System.err.println("An Audio file must be specified (e.g. /foo/baz.raw)."); System.exit(1); } if (line.hasOption("host")) { host = line.getOptionValue("host"); } else { System.err.println("An API enpoint must be specified (typically speech.googleapis.com)."); System.exit(1); } if (line.hasOption("port")) { port = Integer.parseInt(line.getOptionValue("port")); } else { System.err.println("An SSL port must be specified (typically 443)."); System.exit(1); } if (line.hasOption("sampling")) { sampling = Integer.parseInt(line.getOptionValue("sampling")); } else { System.err.println("An Audio sampling rate must be specified."); System.exit(1); } } catch (ParseException exp) { System.err.println("Unexpected exception:" + exp.getMessage()); System.exit(1); } RecognizeGoogleTest client = new RecognizeGoogleTest(host, port, audioFile, sampling); try { client.recognize(); } finally { client.shutdown(); } }
From source file:com.google.cloud.speech.grpc.demos.RecognizeClient.java
public static void main(String[] args) throws Exception { String audioFile = ""; String host = "speech.googleapis.com"; Integer port = 443;//from w ww. j ava 2 s . c o m Integer sampling = 16000; CommandLineParser parser = new DefaultParser(); Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("file").withDescription("path to audio file").hasArg() .withArgName("FILE_PATH").create()); options.addOption( OptionBuilder.withLongOpt("host").withDescription("endpoint for api, e.g. speech.googleapis.com") .hasArg().withArgName("ENDPOINT").create()); options.addOption(OptionBuilder.withLongOpt("port").withDescription("SSL port, usually 443").hasArg() .withArgName("PORT").create()); options.addOption(OptionBuilder.withLongOpt("sampling").withDescription("Sampling Rate, i.e. 16000") .hasArg().withArgName("RATE").create()); try { CommandLine line = parser.parse(options, args); if (line.hasOption("file")) { audioFile = line.getOptionValue("file"); } else { System.err.println("An Audio file must be specified (e.g. /foo/baz.raw)."); System.exit(1); } if (line.hasOption("host")) { host = line.getOptionValue("host"); } else { System.err.println("An API enpoint must be specified (typically speech.googleapis.com)."); System.exit(1); } if (line.hasOption("port")) { port = Integer.parseInt(line.getOptionValue("port")); } else { System.err.println("An SSL port must be specified (typically 443)."); System.exit(1); } if (line.hasOption("sampling")) { sampling = Integer.parseInt(line.getOptionValue("sampling")); } else { System.err.println("An Audio sampling rate must be specified."); System.exit(1); } } catch (ParseException exp) { System.err.println("Unexpected exception:" + exp.getMessage()); System.exit(1); } RecognizeClient client = new RecognizeClient(host, port, audioFile, sampling); try { client.recognize(); } finally { client.shutdown(); } }
From source file:com.phonytive.astive.server.AstiveServer.java
public static void main(String[] args) throws Exception { astivedSP = getServiceProperties(ASTIVED_PROPERTIES, "astived"); adminDaemonSP = getServiceProperties(ADMIN_DAEMON_PROPERTIES, "admin thread"); telnedSP = getServiceProperties(TELNED_PROPERTIES, "telned"); ArrayList<ServiceProperties> serviceProperties = new ArrayList(); serviceProperties.add(astivedSP);/*w w w . j a v a 2s . c o m*/ if (!adminDaemonSP.isDisabled()) { serviceProperties.add(adminDaemonSP); } if (!telnedSP.isDisabled()) { serviceProperties.add(telnedSP); } if ((args.length == 0) || args[0].equals("-h") || args[0].equals("--help")) { printUsage(); System.exit(1); } // Create a Parser CommandLineParser parser = new BasicParser(); Options start = new Options(); start.addOption("h", "help", false, AppLocale.getI18n("cli.option.printUsage")); start.addOption("v", "version", false, "Prints the Astive Server version and exits."); start.addOption("d", "debug", false, AppLocale.getI18n("cli.option.debug")); start.addOption("q", "quiet", false, AppLocale.getI18n("cli.option.daemonMode")); start.addOption(OptionBuilder.hasArg(true).withArgName("host").withLongOpt("admin-bind") .withDescription("" + AppLocale.getI18n("cli.option.bind", new Object[] { "admin" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("port").withLongOpt("admin-port") .withDescription("" + AppLocale.getI18n("cli.option.port", new Object[] { "admin" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("port").withLongOpt("astived-port") .withDescription("" + AppLocale.getI18n("cli.option.port", new Object[] { "astived" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("host").withLongOpt("astived-host") .withDescription("" + AppLocale.getI18n("cli.option.bind", new Object[] { "astived" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("port").withLongOpt("telned-port") .withDescription("" + AppLocale.getI18n("cli.option.port", new Object[] { "telned" })).create()); start.addOption(OptionBuilder.hasArg(true).withArgName("host").withLongOpt("telned-host") .withDescription("" + AppLocale.getI18n("cli.option.host", new Object[] { "telned" })).create()); Options stop = new Options(); stop.addOption(OptionBuilder.withLongOpt("--help") .withDescription("" + AppLocale.getI18n("cli.option.printUsage")).create()); stop.addOption("h", "host", false, AppLocale.getI18n("cli.option.stop.host", new Object[] { DEFAULT_AGI_SERVER_BIND_ADDR })); stop.addOption("p", "port", false, AppLocale.getI18n("cli.option.stop.port", new Object[] { DEFAULT_AGI_SERVER_PORT })); Options deploy = new Options(); deploy.addOption("h", "help", false, AppLocale.getI18n("cli.option.printUsage")); Options undeploy = new Options(); undeploy.addOption("h", "help", false, AppLocale.getI18n("cli.option.printUsage")); if (args.length == 0) { printUsage(); System.exit(1); } else if (!isCommand(args[0])) { printUnavailableCmd(args[0]); System.exit(1); } AdminCommand cmd = AdminCommand.get(args[0]); if (cmd.equals(AdminCommand.DEPLOY) && ((args.length < 2) || !isFileJar(args[1]))) { logger.error(AppLocale.getI18n("cli.invalid.app")); printUsage(AdminCommand.DEPLOY, deploy); System.exit(1); } if (cmd.equals(AdminCommand.UNDEPLOY) && ((args.length < 2) || !isFileJar(args[1]))) { printUsage(AdminCommand.UNDEPLOY, undeploy); System.exit(1); } // Parse the program arguments try { if (cmd.equals(AdminCommand.START)) { CommandLine commandLine = parser.parse(start, args); if (commandLine.hasOption('h')) { printUsage(cmd, start); System.exit(0); } if (commandLine.hasOption('v')) { // Them start the server without noise } if (commandLine.hasOption("astived-bind")) { astivedSP.setBindAddr(InetAddress.getByName(commandLine.getOptionValue("astived-port"))); } if (commandLine.hasOption("astived-port")) { astivedSP.setPort(Integer.parseInt(commandLine.getOptionValue("astived-port"))); } if (commandLine.hasOption("admin-bind")) { adminDaemonSP.setBindAddr(InetAddress.getByName(commandLine.getOptionValue("admin-bind"))); } if (commandLine.hasOption("admin-port")) { adminDaemonSP.setPort(Integer.parseInt(commandLine.getOptionValue("admin-port"))); } if (commandLine.hasOption("telned-bind")) { telnedSP.setBindAddr(InetAddress.getByName(commandLine.getOptionValue("telned-bind"))); } if (commandLine.hasOption("telned-port")) { adminDaemonSP.setPort(Integer.parseInt(commandLine.getOptionValue("telned-port"))); } if (!NetUtil.available(astivedSP.getPort())) { out.println(AppLocale.getI18n("cantStartFastAgiServerSocket", new Object[] { astivedSP.getBindAddr().getHostAddress(), astivedSP.getPort() })); System.exit(-1); } if (!NetUtil.available(adminDaemonSP.getPort())) { adminDaemonSP.setUnableToOpen(true); } if (!NetUtil.available(telnedSP.getPort())) { telnedSP.setUnableToOpen(true); } InitOutput.printInit(serviceProperties); AstiveServer server = new AstiveServer(astivedSP.getPort(), astivedSP.getBacklog(), astivedSP.getBindAddr()); server.start(); } if (!cmd.equals(AdminCommand.START) && adminDaemonSP.isDisabled()) { logger.info("unableToAccessAdminDaemon"); } if (cmd.equals(AdminCommand.STOP)) { CommandLine commandLine = parser.parse(stop, args); if (commandLine.hasOption("--help")) { printUsage(cmd, stop); System.exit(0); } if (commandLine.hasOption('h')) { if (commandLine.getOptionValue('h') == null) { printUsage(cmd, stop); System.exit(0); } astivedSP.setBindAddr(InetAddress.getByName(commandLine.getOptionValue('h'))); } if (commandLine.hasOption('p')) { if (commandLine.getOptionValue('p') == null) { printUsage(cmd, stop); System.exit(0); } astivedSP.setPort(Integer.parseInt(commandLine.getOptionValue('p'))); } AdminDaemonClient adClient = new AdminDaemonClient(adminDaemonSP.getBindAddr(), adminDaemonSP.getPort()); adClient.stop(); } // TODO: This needs to be researched before a full implementation. // for now is only possible to do deployments into the local server. if (cmd.equals(AdminCommand.DEPLOY)) { AdminDaemonClient adClient = new AdminDaemonClient(adminDaemonSP.getBindAddr(), adminDaemonSP.getPort()); adClient.deploy(args[1]); } if (cmd.equals(AdminCommand.UNDEPLOY)) { AdminDaemonClient adClient = new AdminDaemonClient(adminDaemonSP.getBindAddr(), adminDaemonSP.getPort()); adClient.undeploy(args[1]); } } catch (java.net.ConnectException ex) { logger.info("serverNotRunning"); } catch (Exception ex) { logger.error(AppLocale.getI18n("unexpectedError", new Object[] { ex.getMessage() })); } }