List of usage examples for java.util List isEmpty
boolean isEmpty();
From source file:ca.uqac.info.monitor.BeepBeepMonitor.java
public static void main(String[] args) { int verbosity = 1, slowdown = 0, tcp_port = 0; boolean show_stats = false, to_stdout = false; String trace_filename = "", pipe_filename = "", event_name = "message"; final MonitorFactory mf = new MonitorFactory(); // In case we open a socket ServerSocket m_serverSocket = null; Socket m_connection = null;//from w w w .j a v a 2 s .co m // Parse command line arguments Options options = setupOptions(); CommandLine c_line = setupCommandLine(args, options); assert c_line != null; if (c_line.hasOption("verbosity")) { verbosity = Integer.parseInt(c_line.getOptionValue("verbosity")); } if (verbosity > 0) { showHeader(); } if (c_line.hasOption("version")) { System.err.println("(C) 2008-2013 Sylvain Hall et al., Universit du Qubec Chicoutimi"); System.err.println("This program comes with ABSOLUTELY NO WARRANTY."); System.err.println("This is a free software, and you are welcome to redistribute it"); System.err.println("under certain conditions. See the file COPYING for details.\n"); System.exit(ERR_OK); } if (c_line.hasOption("h")) { showUsage(options); System.exit(ERR_OK); } if (c_line.hasOption("version")) { System.exit(ERR_OK); } if (c_line.hasOption("slowdown")) { slowdown = Integer.parseInt(c_line.getOptionValue("slowdown")); if (verbosity > 0) System.err.println("Slowdown factor: " + slowdown + " ms"); } if (c_line.hasOption("stats")) { show_stats = true; } if (c_line.hasOption("csv")) { // Will output data in CSV format to stdout to_stdout = true; } if (c_line.hasOption("eventname")) { // Set event name event_name = c_line.getOptionValue("eventname"); } if (c_line.hasOption("t")) { // Read events from a trace trace_filename = c_line.getOptionValue("t"); } if (c_line.hasOption("p")) { // Read events from a pipe pipe_filename = c_line.getOptionValue("p"); } if (c_line.hasOption("k")) { // Read events from a TCP port tcp_port = Integer.parseInt(c_line.getOptionValue("k")); } if (!trace_filename.isEmpty() && !pipe_filename.isEmpty()) { System.err.println("ERROR: you must specify at most one of trace file or named pipe"); showUsage(options); System.exit(ERR_ARGUMENTS); } @SuppressWarnings("unchecked") List<String> remaining_args = c_line.getArgList(); if (remaining_args.isEmpty()) { System.err.println("ERROR: no input formula specified"); showUsage(options); System.exit(ERR_ARGUMENTS); } // Instantiate the event notifier boolean notify = (verbosity > 0); EventNotifier en = new EventNotifier(notify); en.m_slowdown = slowdown; en.m_csvToStdout = to_stdout; // Create one monitor for each input file and add it to the notifier for (String formula_filename : remaining_args) { try { String formula_contents = FileReadWrite.readFile(formula_filename); Operator op = Operator.parseFromString(formula_contents); op.accept(mf); Monitor mon = mf.getMonitor(); Map<String, String> metadata = getMetadata(formula_contents); metadata.put("Filename", formula_filename); en.addMonitor(mon, metadata); } catch (IOException e) { e.printStackTrace(); System.exit(ERR_IO); } catch (Operator.ParseException e) { System.err.println("Error parsing input formula"); System.exit(ERR_PARSE); } } // Read trace and iterate // Opens file PipeReader pr = null; try { if (!pipe_filename.isEmpty()) { // We tell the pipe reader we read a pipe File f = new File(pipe_filename); if (verbosity > 0) System.err.println("Reading from pipe named " + f.getName()); pr = new PipeReader(new FileInputStream(f), en, false); } else if (!trace_filename.isEmpty()) { // We tell the pipe reader we read a regular file File f = new File(trace_filename); if (verbosity > 0) System.err.println("Reading from file " + f.getName()); pr = new PipeReader(new FileInputStream(f), en, true); } else if (tcp_port > 0) { // We tell the pipe reader we read from a socket if (verbosity > 0) System.err.println("Reading from TCP port " + tcp_port); m_serverSocket = new ServerSocket(tcp_port); m_connection = m_serverSocket.accept(); pr = new PipeReader(m_connection.getInputStream(), en, false); } else { // We tell the pipe reader we read from standard input if (verbosity > 0) System.err.println("Reading from standard input"); pr = new PipeReader(System.in, en, false); } } catch (FileNotFoundException ex) { // We print both trace and pipe since one of them must be empty System.err.println("ERROR: file not found " + trace_filename + pipe_filename); System.exit(ERR_IO); } catch (IOException e) { // Caused by socket error e.printStackTrace(); System.exit(ERR_IO); } pr.setSeparator("<" + event_name + ">", "</" + event_name + ">"); // Check parameters for the event notifier if (c_line.hasOption("no-trigger")) { en.m_notifyOnVerdict = false; } else { en.m_notifyOnVerdict = true; } if (c_line.hasOption("mirror")) { en.m_mirrorEventsOnStdout = true; } // Start event notifier en.reset(); Thread th = new Thread(pr); long clock_start = System.nanoTime(); th.start(); try { th.join(); // Wait for thread to finish } catch (InterruptedException e1) { // Thread is finished } if (tcp_port > 0 && m_serverSocket != null) { // We opened a socket; now we close it try { m_serverSocket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } long clock_end = System.nanoTime(); int ret_code = pr.getReturnCode(); switch (ret_code) { case PipeReader.ERR_EOF: if (verbosity > 0) System.err.println("\nEnd of file reached"); break; case PipeReader.ERR_EOT: if (verbosity > 0) System.err.println("\nEOT received on pipe: closing"); break; case PipeReader.ERR_OK: // Do nothing break; default: // An error System.err.println("Runtime error"); System.exit(ERR_RUNTIME); break; } if (show_stats) { if (verbosity > 0) { System.out.println("Messages: " + en.m_numEvents); System.out.println("Time: " + (int) (en.m_totalTime / 1000000f) + " ms"); System.out.println("Clock time: " + (int) ((clock_end - clock_start) / 1000000f) + " ms"); System.out.println("Max heap: " + (int) (en.heapSize / 1048576f) + " MB"); } else { // If stats are asked but verbosity = 0, only show time value // (both monitor and wall clock) System.out.print((int) (en.m_totalTime / 1000000f)); System.out.print(","); System.out.print((int) ((clock_end - clock_start) / 1000000f)); } } System.exit(ERR_OK); }
From source file:edu.wustl.mir.erl.ihe.xdsi.util.StoreSCU.java
@SuppressWarnings("unchecked") public static void main(String[] args) { long t1, t2;/* w w w. j a v a 2 s . c o m*/ try { CommandLine cl = parseComandLine(args); Device device = new Device("storescu"); Connection conn = new Connection(); device.addConnection(conn); ApplicationEntity ae = new ApplicationEntity("STORESCU"); device.addApplicationEntity(ae); ae.addConnection(conn); StoreSCU main = new StoreSCU(ae); configureTmpFile(main, cl); CLIUtils.configureConnect(main.remote, main.rq, cl); CLIUtils.configureBind(conn, ae, cl); CLIUtils.configure(conn, cl); main.remote.setTlsProtocols(conn.getTlsProtocols()); main.remote.setTlsCipherSuites(conn.getTlsCipherSuites()); configureRelatedSOPClass(main, cl); main.setAttributes(new Attributes()); CLIUtils.addAttributes(main.attrs, cl.getOptionValues("s")); main.setUIDSuffix(cl.getOptionValue("uid-suffix")); main.setPriority(CLIUtils.priorityOf(cl)); List<String> argList = cl.getArgList(); boolean echo = argList.isEmpty(); if (!echo) { System.out.println(rb.getString("scanning")); t1 = System.currentTimeMillis(); main.scanFiles(argList); t2 = System.currentTimeMillis(); int n = main.filesScanned; System.out.println(); if (n == 0) return; System.out.println( MessageFormat.format(rb.getString("scanned"), n, (t2 - t1) / 1000F, (t2 - t1) / n)); } ExecutorService executorService = Executors.newSingleThreadExecutor(); ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); device.setExecutor(executorService); device.setScheduledExecutor(scheduledExecutorService); try { t1 = System.currentTimeMillis(); main.open(); t2 = System.currentTimeMillis(); System.out .println(MessageFormat.format(rb.getString("connected"), main.as.getRemoteAET(), t2 - t1)); if (echo) main.echo(); else { t1 = System.currentTimeMillis(); main.sendFiles(); t2 = System.currentTimeMillis(); } } finally { main.close(); executorService.shutdown(); scheduledExecutorService.shutdown(); } if (main.filesScanned > 0) { float s = (t2 - t1) / 1000F; float mb = main.totalSize / 1048576F; System.out.println(MessageFormat.format(rb.getString("sent"), main.filesSent, mb, s, mb / s)); } } catch (ParseException e) { System.err.println("storescu: " + e.getMessage()); System.err.println(rb.getString("try")); System.exit(2); } catch (Exception e) { System.err.println("storescu: " + e.getMessage()); e.printStackTrace(); System.exit(2); } }
From source file:edu.ksu.cis.indus.staticanalyses.dependency.DependencyXMLizerCLI.java
/** * This is the entry point via command-line. * // ww w . j a v a 2 s . c om * @param args is the command line arguments. * @throws RuntimeException when an Throwable exception beyond our control occurs. * @pre args != null */ public static void main(final String[] args) { final Options _options = new Options(); Option _option = new Option("o", "output", true, "Directory into which xml files will be written into. Defaults to current directory if omitted"); _option.setArgs(1); _option.setArgName("output-directory"); _options.addOption(_option); _option = new Option("j", "jimple", false, "Dump xmlized jimple."); _options.addOption(_option); final DivergenceDA _fidda = DivergenceDA.getDivergenceDA(IDependencyAnalysis.Direction.FORWARD_DIRECTION); _fidda.setConsiderCallSites(true); final DivergenceDA _bidda = DivergenceDA.getDivergenceDA(IDependencyAnalysis.Direction.BACKWARD_DIRECTION); _bidda.setConsiderCallSites(true); final NonTerminationSensitiveEntryControlDA _ncda = new NonTerminationSensitiveEntryControlDA(); final Object[][] _dasOptions = { { "ibdda1", "Identifier based data dependence (Soot)", new IdentifierBasedDataDA() }, { "ibdda2", "Identifier based data dependence (Indus)", new IdentifierBasedDataDAv2() }, { "ibdda3", "Identifier based data dependence (Indus Optimized)", new IdentifierBasedDataDAv3() }, { "rbdda", "Reference based data dependence", new ReferenceBasedDataDA() }, { "nscda", "Non-termination sensitive Entry control dependence", _ncda }, { "nicda", "Non-termination insensitive Entry control dependence", new NonTerminationInsensitiveEntryControlDA(), }, { "xcda", "Exit control dependence", new ExitControlDA() }, { "sda", "Synchronization dependence", new SynchronizationDA() }, { "frda1", "Forward Ready dependence v1", ReadyDAv1.getForwardReadyDA() }, { "brda1", "Backward Ready dependence v1", ReadyDAv1.getBackwardReadyDA() }, { "frda2", "Forward Ready dependence v2", ReadyDAv2.getForwardReadyDA() }, { "brda2", "Backward Ready dependence v2", ReadyDAv2.getBackwardReadyDA() }, { "frda3", "Forward Ready dependence v3", ReadyDAv3.getForwardReadyDA() }, { "brda3", "Backward Ready dependence v3", ReadyDAv3.getBackwardReadyDA() }, { "ida1", "Interference dependence v1", new InterferenceDAv1() }, { "ida2", "Interference dependence v2", new InterferenceDAv2() }, { "ida3", "Interference dependence v3", new InterferenceDAv3() }, { "fdda", "Forward Intraprocedural Divergence dependence", DivergenceDA.getDivergenceDA(IDependencyAnalysis.Direction.FORWARD_DIRECTION), }, { "bdda", "Backward Intraprocedural Divergence dependence", DivergenceDA.getDivergenceDA(IDependencyAnalysis.Direction.BACKWARD_DIRECTION), }, { "fidda", "Forward Intra+Interprocedural Divergence dependence", _fidda }, { "bidda", "Backward Intra+Interprocedural Divergence dependence", _bidda }, { "fpidda", "Forward Interprocedural Divergence dependence", InterProceduralDivergenceDA .getDivergenceDA(IDependencyAnalysis.Direction.FORWARD_DIRECTION), }, { "bpidda", "Backward Interprocedural Divergence dependence", InterProceduralDivergenceDA .getDivergenceDA(IDependencyAnalysis.Direction.BACKWARD_DIRECTION), }, }; _option = new Option("h", "help", false, "Display message."); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path."); _option.setArgs(1); _option.setArgName("classpath"); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("aliasedusedefv1", false, "Use version 1 of aliased use-def info."); _options.addOption(_option); _option = new Option("safelockanalysis", false, "Use safe-lock-analysis for ready dependence."); _options.addOption(_option); _option = new Option("ofaforinterference", false, "Use OFA for interference dependence."); _options.addOption(_option); _option = new Option("ofaforready", false, "Use OFA for ready dependence."); _options.addOption(_option); _option = new Option("exceptionalexits", false, "Consider exceptional exits for control dependence."); _options.addOption(_option); _option = new Option("commonuncheckedexceptions", false, "Consider common unchecked exceptions."); _options.addOption(_option); _option = new Option("S", "scope", true, "The scope that should be analyzed."); _option.setArgs(1); _option.setArgName("scope"); _option.setRequired(false); _options.addOption(_option); for (int _i = 0; _i < _dasOptions.length; _i++) { final String _shortOption = _dasOptions[_i][0].toString(); final String _description = _dasOptions[_i][1].toString(); _option = new Option(_shortOption, false, _description); _options.addOption(_option); } final CommandLineParser _parser = new GnuParser(); try { final CommandLine _cl = _parser.parse(_options, args); if (_cl.hasOption("h")) { printUsage(_options); System.exit(1); } final DependencyXMLizerCLI _xmlizerCLI = new DependencyXMLizerCLI(); String _outputDir = _cl.getOptionValue('o'); if (_outputDir == null) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Defaulting to current directory for output."); } _outputDir = "."; } _xmlizerCLI.xmlizer.setXmlOutputDir(_outputDir); if (_cl.hasOption('p')) { _xmlizerCLI.addToSootClassPath(_cl.getOptionValue('p')); } if (_cl.hasOption('S')) { _xmlizerCLI.setScopeSpecFile(_cl.getOptionValue('S')); } _xmlizerCLI.dumpJimple = _cl.hasOption('j'); _xmlizerCLI.useAliasedUseDefv1 = _cl.hasOption("aliasedusedefv1"); _xmlizerCLI.useSafeLockAnalysis = _cl.hasOption("safelockanalysis"); _xmlizerCLI.exceptionalExits = _cl.hasOption("exceptionalexits"); _xmlizerCLI.commonUncheckedException = _cl.hasOption("commonuncheckedexceptions"); final List<String> _classNames = _cl.getArgList(); if (_classNames.isEmpty()) { throw new MissingArgumentException("Please specify atleast one class."); } _xmlizerCLI.setClassNames(_classNames); final int _exitControlDAIndex = 6; if (_cl.hasOption(_dasOptions[_exitControlDAIndex][0].toString())) { _xmlizerCLI.das.add(_ncda); for (final Iterator<DependenceSort> _i = _ncda.getIds().iterator(); _i.hasNext();) { final DependenceSort _id = _i.next(); MapUtils.putIntoCollectionInMapUsingFactory(_xmlizerCLI.info, _id, _ncda, SetUtils.getFactory()); } } if (!parseForDependenceOptions(_dasOptions, _cl, _xmlizerCLI)) { throw new ParseException("Atleast one dependence analysis must be requested."); } _xmlizerCLI.<ITokens>execute(); } catch (final ParseException _e) { LOGGER.error("Error while parsing command line.", _e); System.out.println("Error while parsing command line." + _e); printUsage(_options); } catch (final Throwable _e) { LOGGER.error("Beyond our control. May day! May day!", _e); throw new RuntimeException(_e); } }
From source file:is.merkor.core.cli.Main.java
public static void main(String[] args) throws Exception { List<String> results = new ArrayList<String>(); PrintStream out = new PrintStream(System.out, true, "UTF-8"); CommandLineParser parser = new GnuParser(); try {//from w w w .j a va 2s . c o m MerkorCoreCommandLineOptions.createOptions(); results = processCommandLine(parser.parse(MerkorCoreCommandLineOptions.options, args)); out.print("\n"); for (String str : results) { if (!str.equals("no message")) out.println(str); } out.print("\n"); if (results.isEmpty()) { out.println("nothing found for parameters: "); for (int i = 0; i < args.length; i++) out.println("\t" + args[i]); out.println("for help type: -help or see README.markdown"); out.print("\n"); } } catch (ParseException e) { System.err.println("Parsing failed. Reason: " + e.getMessage()); } }
From source file:com.boundary.aws.kinesis.Sample.java
public static void main(String[] args) throws Exception { init();//from www . j a va2 s .c o m final String myStreamName = "boundary-test-stream"; final Integer myStreamSize = 1; // Create a stream. The number of shards determines the provisioned // throughput. CreateStreamRequest createStreamRequest = new CreateStreamRequest(); createStreamRequest.setStreamName(myStreamName); createStreamRequest.setShardCount(myStreamSize); kinesisClient.createStream(createStreamRequest); // The stream is now being created. LOG.info("Creating Stream : " + myStreamName); waitForStreamToBecomeAvailable(myStreamName); // list all of my streams ListStreamsRequest listStreamsRequest = new ListStreamsRequest(); listStreamsRequest.setLimit(10); ListStreamsResult listStreamsResult = kinesisClient.listStreams(listStreamsRequest); List<String> streamNames = listStreamsResult.getStreamNames(); while (listStreamsResult.isHasMoreStreams()) { if (streamNames.size() > 0) { listStreamsRequest.setExclusiveStartStreamName(streamNames.get(streamNames.size() - 1)); } listStreamsResult = kinesisClient.listStreams(listStreamsRequest); streamNames.addAll(listStreamsResult.getStreamNames()); } LOG.info("Printing my list of streams : "); // print all of my streams. if (!streamNames.isEmpty()) { System.out.println("List of my streams: "); } for (int i = 0; i < streamNames.size(); i++) { System.out.println(streamNames.get(i)); } LOG.info("Putting records in stream : " + myStreamName); // Write 10 records to the stream for (int j = 0; j < 100; j++) { PutRecordRequest putRecordRequest = new PutRecordRequest(); putRecordRequest.setStreamName(myStreamName); putRecordRequest.setData(ByteBuffer.wrap(String.format("testData-%d", j).getBytes())); putRecordRequest.setPartitionKey(String.format("partitionKey-%d", j)); PutRecordResult putRecordResult = kinesisClient.putRecord(putRecordRequest); System.out.println("Successfully putrecord, partition key : " + putRecordRequest.getPartitionKey() + ", ShardID : " + putRecordResult.getShardId()); } // Delete the stream. LOG.info("Deleting stream : " + myStreamName); DeleteStreamRequest deleteStreamRequest = new DeleteStreamRequest(); deleteStreamRequest.setStreamName(myStreamName); kinesisClient.deleteStream(deleteStreamRequest); // The stream is now being deleted. LOG.info("Stream is now being deleted : " + myStreamName); }
From source file:io.werval.cli.DamnSmallDevShell.java
public static void main(String[] args) { Options options = declareOptions();//from w ww.j a va2s .com CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); // Handle --help if (cmd.hasOption("help")) { PrintWriter out = new PrintWriter(System.out); printHelp(options, out); out.flush(); System.exit(0); } // Handle --version if (cmd.hasOption("version")) { System.out.print(String.format( "Werval CLI v%s\n" + "Git commit: %s%s, built on: %s\n" + "Java version: %s, vendor: %s\n" + "Java home: %s\n" + "Default locale: %s, platform encoding: %s\n" + "OS name: %s, version: %s, arch: %s\n", VERSION, COMMIT, (DIRTY ? " (DIRTY)" : ""), DATE, System.getProperty("java.version"), System.getProperty("java.vendor"), System.getProperty("java.home"), Locale.getDefault().toString(), System.getProperty("file.encoding"), System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch"))); System.out.flush(); System.exit(0); } // Debug final boolean debug = cmd.hasOption('d'); // Temporary directory final File tmpDir = new File(cmd.getOptionValue('t', "build" + separator + "devshell.tmp")); if (debug) { System.out.println("Temporary directory set to '" + tmpDir.getAbsolutePath() + "'."); } // Handle commands @SuppressWarnings("unchecked") List<String> commands = cmd.getArgList(); if (commands.isEmpty()) { commands = Collections.singletonList("start"); } if (debug) { System.out.println("Commands to be executed: " + commands); } Iterator<String> commandsIterator = commands.iterator(); while (commandsIterator.hasNext()) { String command = commandsIterator.next(); switch (command) { case "new": System.out.println(LOGO); newCommand(commandsIterator.hasNext() ? commandsIterator.next() : "werval-application", cmd); break; case "clean": cleanCommand(debug, tmpDir); break; case "devshell": System.out.println(LOGO); devshellCommand(debug, tmpDir, cmd); break; case "start": System.out.println(LOGO); startCommand(debug, tmpDir, cmd); break; case "secret": secretCommand(); break; default: PrintWriter out = new PrintWriter(System.err); System.err.println("Unknown command: '" + command + "'"); printHelp(options, out); out.flush(); System.exit(1); break; } } } catch (IllegalArgumentException | ParseException | IOException ex) { PrintWriter out = new PrintWriter(System.err); printHelp(options, out); out.flush(); System.exit(1); } catch (WervalException ex) { ex.printStackTrace(System.err); System.err.flush(); System.exit(1); } }
From source file:AmazonKinesisSample.java
public static void main(String[] args) throws Exception { init();/*from w w w. j a v a 2 s. co m*/ final String myStreamName = "myFirstStream"; final Integer myStreamSize = 1; // Create a stream. The number of shards determines the provisioned throughput. CreateStreamRequest createStreamRequest = new CreateStreamRequest(); createStreamRequest.setStreamName(myStreamName); createStreamRequest.setShardCount(myStreamSize); kinesisClient.createStream(createStreamRequest); // The stream is now being created. LOG.info("Creating Stream : " + myStreamName); waitForStreamToBecomeAvailable(myStreamName); // list all of my streams ListStreamsRequest listStreamsRequest = new ListStreamsRequest(); listStreamsRequest.setLimit(10); ListStreamsResult listStreamsResult = kinesisClient.listStreams(listStreamsRequest); List<String> streamNames = listStreamsResult.getStreamNames(); while (listStreamsResult.isHasMoreStreams()) { if (streamNames.size() > 0) { listStreamsRequest.setExclusiveStartStreamName(streamNames.get(streamNames.size() - 1)); } listStreamsResult = kinesisClient.listStreams(listStreamsRequest); streamNames.addAll(listStreamsResult.getStreamNames()); } LOG.info("Printing my list of streams : "); // print all of my streams. if (!streamNames.isEmpty()) { System.out.println("List of my streams: "); } for (int i = 0; i < streamNames.size(); i++) { System.out.println(streamNames.get(i)); } LOG.info("Putting records in stream : " + myStreamName); // Write 10 records to the stream for (int j = 0; j < 10; j++) { PutRecordRequest putRecordRequest = new PutRecordRequest(); putRecordRequest.setStreamName(myStreamName); putRecordRequest.setData(ByteBuffer.wrap(String.format("testData-%d", j).getBytes())); putRecordRequest.setPartitionKey(String.format("partitionKey-%d", j)); PutRecordResult putRecordResult = kinesisClient.putRecord(putRecordRequest); System.out.println("Successfully putrecord, partition key : " + putRecordRequest.getPartitionKey() + ", ShardID : " + putRecordResult.getShardId()); } // Delete the stream. LOG.info("Deleting stream : " + myStreamName); DeleteStreamRequest deleteStreamRequest = new DeleteStreamRequest(); deleteStreamRequest.setStreamName(myStreamName); kinesisClient.deleteStream(deleteStreamRequest); // The stream is now being deleted. LOG.info("Stream is now being deleted : " + myStreamName); }
From source file:de.rrze.idmone.utils.jidgen.IdGenerator.java
/** * Entry point of the program (CLI)/*from w ww . j ava 2s. c o m*/ * * @param args * the program arguments */ public static void main(String[] args) { logger.info(Messages.getString("IdGenerator.WELCOME")); // create an instance of the IdGenerator and start the generation process IdGenerator generator = new IdGenerator(); // pass on the CLI options array generator.setCLIArgs(args); // initialize the generator options manually // so we can print the usage on error if (!generator.init()) { generator.printUsage(); System.exit(150); } /* * PROCESS CLI ONLY OPTIONS */ // check for -h option or call with no options at all if (generator.options.hasOptionValue("h") || generator.options.getNum() == 0) { generator.printUsage(); System.exit(0); } // check for -hh option if (generator.options.hasOptionValue("hh")) { generator.printHelp(); System.exit(0); } // set number of ids if (generator.options.hasOptionValue("N")) { Globals.NUM_IDs = Integer.parseInt(generator.options.getOptionValue("N")); logger.trace("Set number of ids to generate to " + Globals.NUM_IDs + "."); } // enable column output if (generator.options.hasOptionValue("C")) { Globals.ENABLE_COLUMN_OUTPUT = true; logger.trace("Enable column output..."); } // set terminal width if (generator.options.hasOptionValue("W")) { Globals.TERM_WIDTH = Integer.parseInt(generator.options.getOptionValue("W")); logger.trace("Set terminal width to " + Globals.TERM_WIDTH + "."); } /* * START WORKING */ // generate ids List<String> ids = generator.generateIDs(Globals.NUM_IDs); // output the generated ids if (ids != null && !ids.isEmpty()) { logger.info(Messages.getString("IdGenerator.ID")); if (Globals.ENABLE_COLUMN_OUTPUT) { generator.printColumns(ids); } else { generator.print(ids); } } }
From source file:edu.vt.middleware.ldap.search.PeopleSearch.java
/** * This provides command line access to a <code>PeopleSearch</code>. * * @param args <code>String[]</code> * * @throws Exception if an error occurs *///from ww w . ja va2 s . c o m public static void main(final String[] args) throws Exception { final PeopleSearch ps = createFromSpringContext("/peoplesearch-context.xml", "peopleSearch"); final Query query = new Query(); final List<String> attrs = new ArrayList<String>(); try { for (int i = 0; i < args.length; i++) { if ("-query".equals(args[i])) { query.setRawQuery(args[++i]); } else { attrs.add(args[i]); } } if (query.getRawQuery() == null) { throw new ArrayIndexOutOfBoundsException(); } if (!attrs.isEmpty()) { query.setQueryAttributes(attrs.toArray(new String[0])); } ps.search(query, OutputFormat.LDIF, new BufferedWriter(new OutputStreamWriter(System.out))); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Usage: java " + PeopleSearch.class.getName() + " -query <query> <attributes>"); System.exit(1); } }
From source file:AmazonKinesisList.java
public static void main(String[] args) throws Exception { init();// w w w . j av a2 s.com final String myStreamName = "anotestBstream"; final Integer myStreamSize = 1; // Create a stream. The number of shards determines the provisioned throughput. // CreateStreamRequest createStreamRequest = new CreateStreamRequest(); // createStreamRequest.setStreamName(myStreamName); // createStreamRequest.setShardCount(myStreamSize); // pt // kinesisClient.createStream(createStreamRequest); // The stream is now being created. // LOG.info("Creating Stream : " + myStreamName); // waitForStreamToBecomeAvailable(myStreamName); // list all of my streams ListStreamsRequest listStreamsRequest = new ListStreamsRequest(); listStreamsRequest.setLimit(10); ListStreamsResult listStreamsResult = kinesisClient.listStreams(listStreamsRequest); List<String> streamNames = listStreamsResult.getStreamNames(); while (listStreamsResult.isHasMoreStreams()) { if (streamNames.size() > 0) { listStreamsRequest.setExclusiveStartStreamName(streamNames.get(streamNames.size() - 1)); } listStreamsResult = kinesisClient.listStreams(listStreamsRequest); streamNames.addAll(listStreamsResult.getStreamNames()); } LOG.info("Printing my list of streams : "); // print all of my streams. if (!streamNames.isEmpty()) { System.out.println("List of my streams: "); } for (int i = 0; i < streamNames.size(); i++) { System.out.println(streamNames.get(i)); } /* LOG.info("Putting records in stream : " + myStreamName); // Write 10 records to the stream for (int j = 0; j < 10; j++) { PutRecordRequest putRecordRequest = new PutRecordRequest(); putRecordRequest.setStreamName(myStreamName); putRecordRequest.setData(ByteBuffer.wrap(String.format("testData-%d", j).getBytes())); putRecordRequest.setPartitionKey(String.format("partitionKey-%d", j)); PutRecordResult putRecordResult = kinesisClient.putRecord(putRecordRequest); System.out.println("Successfully putrecord, partition key : " + putRecordRequest.getPartitionKey() + ", ShardID : " + putRecordResult.getShardId()); } */ // Delete the stream. /* LOG.info("Deleting stream : " + myStreamName); DeleteStreamRequest deleteStreamRequest = new DeleteStreamRequest(); deleteStreamRequest.setStreamName(myStreamName); kinesisClient.deleteStream(deleteStreamRequest); // The stream is now being deleted. LOG.info("Stream is now being deleted : " + myStreamName); LOG.info("Streaming completed" + myStreamName); */ }