List of usage examples for java.util List get
E get(int index);
From source file:com.continuent.tungsten.common.security.KeystoreManagerCtrl.java
/** * Password Manager entry point// w ww .ja v a 2 s . com * * @param argv * @throws Exception */ public static void main(String argv[]) throws Exception { keystoreManager = new KeystoreManagerCtrl(); // --- Options --- CommandLine line = null; try { CommandLineParser parser = new GnuParser(); // --- Parse the command line arguments --- // --- Help line = parser.parse(keystoreManager.helpOptions, argv, true); if (line.hasOption(_HELP)) { DisplayHelpAndExit(EXIT_CODE.EXIT_OK); } // --- Program command line options line = parser.parse(keystoreManager.options, argv); // --- Compulsory arguments : Get options --- if (line.hasOption(_KEYSTORE_LOCATION)) keystoreManager.keystoreLocation = line.getOptionValue(_KEYSTORE_LOCATION); if (line.hasOption(_KEY_ALIAS)) keystoreManager.keyAlias = line.getOptionValue(_KEY_ALIAS); if (line.hasOption(_KEY_TYPE)) { String keyType = line.getOptionValue(_KEY_TYPE); // This will throw an exception if the type is not recognised KEYSTORE_TYPE certificateTYpe = KEYSTORE_TYPE.fromString(keyType); keystoreManager.keyType = certificateTYpe; } if (line.hasOption(_KEYSTORE_PASSWORD)) keystoreManager.keystorePassword = line.getOptionValue(_KEYSTORE_PASSWORD); if (line.hasOption(_KEY_PASSWORD)) keystoreManager.keyPassword = line.getOptionValue(_KEY_PASSWORD); } catch (ParseException exp) { logger.error(exp.getMessage()); DisplayHelpAndExit(EXIT_CODE.EXIT_ERROR); } catch (Exception e) { // Workaround for Junit test if (e.toString().contains("CheckExitCalled")) { throw e; } else // Normal behaviour { logger.error(e.getMessage()); Exit(EXIT_CODE.EXIT_ERROR); } } // --- Perform commands --- // ######### Check password ########## if (line.hasOption(_CHECK)) { try { if (keystoreManager.keystorePassword == null || keystoreManager.keyPassword == null) { // --- Get passwords from stdin if not given on command line List<String> listPrompts = Arrays.asList("Keystore password:", MessageFormat.format("Password for key {0}:", keystoreManager.keyAlias)); List<String> listUserInput = keystoreManager.getUserInputFromStdin(listPrompts); if (listUserInput.size() == listPrompts.size()) { keystoreManager.keystorePassword = listUserInput.get(0); keystoreManager.keyPassword = listUserInput.get(1); } else { throw new NoSuchElementException(); } } try { // --- Check that all keys in keystore use the keystore // password logger.info(MessageFormat.format("Using keystore:{0}", keystoreManager.keystoreLocation)); SecurityHelper.checkKeyStorePasswords(keystoreManager.keystoreLocation, keystoreManager.keyType, keystoreManager.keystorePassword, keystoreManager.keyAlias, keystoreManager.keyPassword); logger.info(MessageFormat.format("OK : Identical password for Keystore and key={0}", keystoreManager.keyAlias)); } catch (UnrecoverableKeyException uke) { logger.error(MessageFormat.format("At least 1 key has a wrong password.{0}", uke.getMessage())); Exit(EXIT_CODE.EXIT_ERROR); } catch (Exception e) { logger.error(MessageFormat.format("{0}", e.getMessage())); Exit(EXIT_CODE.EXIT_ERROR); } } catch (NoSuchElementException nse) { logger.error(nse.getMessage()); Exit(EXIT_CODE.EXIT_ERROR); } catch (Exception e) { logger.error(MessageFormat.format("Error while running the program: {0}", e.getMessage())); Exit(EXIT_CODE.EXIT_ERROR); } } Exit(EXIT_CODE.EXIT_OK); }
From source file:example.client.CamelMongoJmsStockClient.java
@SuppressWarnings("resource") public static void main(final String[] args) throws Exception { systemProps = loadProperties();/*from ww w .j a va 2 s .com*/ AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml"); ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class); List<Map<String, Object>> stocks = readJsonsFromMongoDB(); for (Map<String, Object> stock : stocks) { stock.remove("_id"); stock.remove("Earnings Date"); camelTemplate.sendBody(String.format("jms:queue:%s", systemProps.getProperty("ticker.queue.name")), ExchangePattern.InOnly, stock); } new Timer().schedule(new TimerTask() { @Override public void run() { Map<String, Object> aRandomStock = stocks.get(RandomUtils.nextInt(0, stocks.size())); aRandomStock.put("Price", ((Double) aRandomStock.get("Price")) + RandomUtils.nextFloat(0.1f, 9.99f)); camelTemplate.sendBody(String.format("jms:queue:%s", systemProps.getProperty("ticker.queue.name")), ExchangePattern.InOnly, aRandomStock); } }, 1000, 2000); }
From source file:com.jaspersoft.jasperserver.export.RemoveDuplicatedDisplayName.java
public static void main(String[] args) { Parameters params = null;/* ww w .j a v a 2 s . c om*/ boolean success = false; try { GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader configReader = new XmlBeanDefinitionReader(ctx); List resourceXML = getPaths(args[2]); if (args != null && args.length > 0) { for (int i = 0; i < resourceXML.size(); i++) { org.springframework.core.io.Resource resource = classPathResourceFactory .create((String) resourceXML.get(i)); configReader.loadBeanDefinitions(resource); } } ctx.refresh(); if (args.length > 3) { if ("UPDATE".equals(args[3])) { updateRepo = true; } } // write to file // try { CommandBean commandBean = (CommandBean) ctx.getBean("removeDuplicateDisplayName", CommandBean.class); Charset encoding = Charset.forName( ((RemoveDuplicatedDisplayName) commandBean).getEncodingProvider().getCharacterEncoding()); osw = new OutputStreamWriter(new FileOutputStream("remove_duplicated_display_name_report.txt"), encoding); commandBean.process(params); } finally { osw.close(); } success = true; } catch (Exception e) { e.printStackTrace(System.err); } System.exit(success ? 0 : -1); }
From source file:edu.usu.sdl.wso2client.SampleWSRegistryClient.java
public static void main(String[] args) throws Exception { Registry registry = initialize(); try {//from w w w . jav a 2 s . c o m //load component List<ComponentAll> components; try (InputStream in = new FileInputStream("C:\\temp\\components.json")) { components = StringProcessor.defaultObjectMapper().readValue(in, new TypeReference<List<ComponentAll>>() { }); } catch (IOException ex) { throw ex; } ComponentAll componentAll = components.get(0); Resource resource = registry.newResource(); resource.setContent(componentAll.getComponent().getDescription()); resource.setDescription("Storefront Component"); resource.setMediaType("application/openstorefront"); resource.setUUID(componentAll.getComponent().getComponentId()); try { Map fieldMap = BeanUtils.describe(componentAll.getComponent()); fieldMap.keySet().stream().forEach((key) -> { if ("description".equals(key) == false) { resource.setProperty(Component.class.getSimpleName() + "_" + key, "" + fieldMap.get(key)); //System.out.println("key = " + Component.class.getSimpleName() + "_" + key); //System.out.println("Value = " + fieldMap.get(key)); } }); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { Logger.getLogger(StringProcessor.class.getName()).log(Level.SEVERE, null, ex); } String resourcePath = "/storefront/components/" + componentAll.getComponent().getComponentId(); registry.put(resourcePath, resource); // System.out.println("A resource added to: " + resourcePath); // registry.rateResource(resourcePath, 4); // // System.out.println("Resource rated with 4 stars!"); // Comment comment = new Comment(); // comment.setText("Testing Connection"); // registry.addComment(resourcePath, comment); // System.out.println("Comment added to resource"); // // Resource getResource = registry.get("/abc2"); // System.out.println("Resource retrived"); // System.out.println("Printing retrieved resource content: " // + new String((byte[]) getResource.getContent())); // Resource resource = registry.newResource(); // resource.setContent("Hello Out there!"); // // String resourcePath = "/abc3"; // registry.put(resourcePath, resource); // // System.out.println("A resource added to: " + resourcePath); // // registry.rateResource(resourcePath, 4); // // System.out.println("Resource rated with 4 stars!"); // Comment comment = new Comment(); // comment.setText("Testing Connection"); // registry.addComment(resourcePath, comment); // System.out.println("Comment added to resource"); // // Resource getResource = registry.get("/abc3"); // System.out.println("Resource retrived"); // System.out.println("Printing retrieved resource content: " // + new String((byte[]) getResource.getContent())); } finally { //Close the session ((WSRegistryServiceClient) registry).logut(); } System.exit(0); }
From source file:ca.uqac.lif.bullwinkle.BullwinkleCli.java
/** * @param args//from w ww .j a v a 2 s . c om */ public static void main(String[] args) { // Setup parameters int verbosity = 1; String output_format = "xml", grammar_filename = null, filename_to_parse = null; // 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) 2014 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 LICENSE-2.0 for details.\n"); System.exit(ERR_OK); } if (c_line.hasOption("h")) { showUsage(options); System.exit(ERR_OK); } if (c_line.hasOption("f")) { output_format = c_line.getOptionValue("f"); } // Get grammar file @SuppressWarnings("unchecked") List<String> remaining_args = c_line.getArgList(); if (remaining_args.isEmpty()) { System.err.println("ERROR: no grammar file specified"); System.exit(ERR_ARGUMENTS); } grammar_filename = remaining_args.get(0); // Get file to parse, if any if (remaining_args.size() >= 2) { filename_to_parse = remaining_args.get(1); } // Read grammar file BnfParser parser = null; try { parser = new BnfParser(new File(grammar_filename)); } catch (InvalidGrammarException e) { System.err.println("ERROR: invalid grammar"); System.exit(ERR_GRAMMAR); } catch (IOException e) { System.err.println("ERROR reading grammar " + grammar_filename); System.exit(ERR_IO); } assert parser != null; // Read input file BufferedReader bis = null; if (filename_to_parse == null) { // Read from stdin bis = new BufferedReader(new InputStreamReader(System.in)); } else { // Read from file try { bis = new BufferedReader(new InputStreamReader(new FileInputStream(new File(filename_to_parse)))); } catch (FileNotFoundException e) { System.err.println("ERROR: file not found " + filename_to_parse); System.exit(ERR_IO); } } assert bis != null; String str; StringBuilder input_file = new StringBuilder(); try { while ((str = bis.readLine()) != null) { input_file.append(str).append("\n"); } } catch (IOException e) { System.err.println("ERROR reading input"); System.exit(ERR_IO); } String file_contents = input_file.toString(); // Parse contents of file ParseNode p_node = null; try { p_node = parser.parse(file_contents); } catch (ca.uqac.lif.bullwinkle.BnfParser.ParseException e) { System.err.println("ERROR parsing input\n"); e.printStackTrace(); System.exit(ERR_PARSE); } if (p_node == null) { System.err.println("ERROR parsing input\n"); System.exit(ERR_PARSE); } assert p_node != null; // Output parse node to desired format PrintStream output = System.out; OutputFormatVisitor out_vis = null; if (output_format.compareToIgnoreCase("xml") == 0) { // Output to XML out_vis = new XmlVisitor(); } else if (output_format.compareToIgnoreCase("dot") == 0) { // Output to DOT out_vis = new GraphvizVisitor(); } else if (output_format.compareToIgnoreCase("txt") == 0) { // Output to indented plain text out_vis = new IndentedTextVisitor(); } else if (output_format.compareToIgnoreCase("json") == 0) { // Output to JSON } if (out_vis == null) { System.err.println("ERROR: unknown output format " + output_format); System.exit(ERR_ARGUMENTS); } assert out_vis != null; p_node.prefixAccept(out_vis); output.print(out_vis.toOutputString()); // Terminate without error System.exit(ERR_OK); }
From source file:br.eb.ime.labprog3.tam.GeradorGrafoDijkstra.java
public static void main(String args[]) { String fileNameTrechos = "rotas.xml"; String fileNameAeroportos = "aeroportos.xml"; File aeroportos = new File(fileNameAeroportos); File trechos = new File(fileNameTrechos); Resource resource = null;//ww w.j a va 2 s .c o m TrechoDAO daoTrecho = null; AeroportoDAO daoAeroporto = null; daoTrecho = new TrechoDAO(trechos); daoAeroporto = new AeroportoDAO(aeroportos); int indexOrigem = 4; int indexDestino = 23; List<Aeroporto> listaDeAeroportos = daoAeroporto.listarAeroportos(); List<Trecho> listarTrechos = daoTrecho.listarTrechos(); GeradorGrafoDijkstra geradorDeGrafo = new GeradorGrafoDijkstra(daoAeroporto.listarAeroportos(), daoTrecho.listarTrechos()); List<Aeroporto> listaDeAeroportosDestino = geradorDeGrafo.geraMenorCaminho(indexOrigem, indexDestino); System.out.println(listaDeAeroportosDestino.size()); System.out.println("Origem: " + listaDeAeroportos.get(indexOrigem - 1).getId() + " : " + listaDeAeroportos.get(indexOrigem - 1).getNome()); System.out.println("Destino: " + listaDeAeroportos.get(indexDestino - 1).getId() + " : " + listaDeAeroportos.get(indexDestino - 1).getNome()); for (Aeroporto aeroporto : listaDeAeroportosDestino) { System.out.println(aeroporto.getId() + " : " + aeroporto.getNome()); } }
From source file:io.s4.tools.loadgenerator.LoadGenerator.java
public static void main(String args[]) { Options options = new Options(); boolean warmUp = false; options.addOption(/*from w w w. ja v a2 s . co m*/ OptionBuilder.withArgName("rate").hasArg().withDescription("Rate (events per second)").create("r")); options.addOption(OptionBuilder.withArgName("display_rate").hasArg() .withDescription("Display Rate at specified second boundary").create("d")); options.addOption(OptionBuilder.withArgName("adapter_address").hasArg() .withDescription("Address of client adapter").create("a")); options.addOption(OptionBuilder.withArgName("listener_application_name").hasArg() .withDescription("Listener application name").create("g")); options.addOption( OptionBuilder.withArgName("sleep_overhead").hasArg().withDescription("Sleep overhead").create("o")); options.addOption(new Option("w", "Warm-up")); CommandLineParser parser = new GnuParser(); CommandLine line = null; try { // parse the command line arguments line = parser.parse(options, args); } catch (ParseException exp) { // oops, something went wrong System.err.println("Parsing failed. Reason: " + exp.getMessage()); System.exit(1); } int expectedRate = 250; if (line.hasOption("r")) { try { expectedRate = Integer.parseInt(line.getOptionValue("r")); } catch (Exception e) { System.err.println("Bad expected rate specified " + line.getOptionValue("r")); System.exit(1); } } int displayRateIntervalSeconds = 20; if (line.hasOption("d")) { try { displayRateIntervalSeconds = Integer.parseInt(line.getOptionValue("d")); } catch (Exception e) { System.err.println("Bad display rate value specified " + line.getOptionValue("d")); System.exit(1); } } int updateFrequency = 0; if (line.hasOption("f")) { try { updateFrequency = Integer.parseInt(line.getOptionValue("f")); } catch (Exception e) { System.err.println("Bad query udpdate frequency specified " + line.getOptionValue("f")); System.exit(1); } System.out.printf("Update frequency is %d\n", updateFrequency); } String clientAdapterAddress = null; String clientAdapterHost = null; int clientAdapterPort = -1; if (line.hasOption("a")) { clientAdapterAddress = line.getOptionValue("a"); String[] parts = clientAdapterAddress.split(":"); if (parts.length != 2) { System.err.println("Bad adapter address specified " + clientAdapterAddress); System.exit(1); } clientAdapterHost = parts[0]; try { clientAdapterPort = Integer.parseInt(parts[1]); } catch (NumberFormatException nfe) { System.err.println("Bad adapter address specified " + clientAdapterAddress); System.exit(1); } } long sleepOverheadMicros = -1; if (line.hasOption("o")) { try { sleepOverheadMicros = Long.parseLong(line.getOptionValue("o")); } catch (NumberFormatException e) { System.err.println("Bad sleep overhead specified " + line.getOptionValue("o")); System.exit(1); } System.out.printf("Specified sleep overhead is %d\n", sleepOverheadMicros); } if (line.hasOption("w")) { warmUp = true; } List loArgs = line.getArgList(); if (loArgs.size() < 1) { System.err.println("No input file specified"); System.exit(1); } String inputFilename = (String) loArgs.get(0); LoadGenerator loadGenerator = new LoadGenerator(); loadGenerator.setInputFilename(inputFilename); loadGenerator.setDisplayRateInterval(displayRateIntervalSeconds); loadGenerator.setExpectedRate(expectedRate); loadGenerator.setClientAdapterHost(clientAdapterHost); loadGenerator.setClientAdapterPort(clientAdapterPort); loadGenerator.run(); System.exit(0); }
From source file:eu.crisis_economics.configuration.CommaListExpression.java
public static void main(String[] args) { System.out.println("testing CommaListExpression type.."); {/*from www. java2s . c o m*/ String expression = "Type[2] { first, second , NUMBER=$( 1 + 1 ) }"; List<String> expected = Arrays.asList("Type[2]", "first", "second", "NUMBER=$( 1 + 1 )"), gained = CommaListExpression.isExpressionOfType(expression, '{', '}', null); Assert.assertEquals(expected.size(), gained.size()); for (int i = 0; i < expected.size(); ++i) { Assert.assertEquals(expected.get(i), gained.get(i)); } } { String expression = "Type{ A }"; List<String> expected = Arrays.asList("Type", "A"), gained = CommaListExpression.isExpressionOfType(expression, '{', '}', null); Assert.assertEquals(expected.size(), gained.size()); for (int i = 0; i < expected.size(); ++i) { Assert.assertEquals(expected.get(i), gained.get(i)); } } { String expression = "Type{ }"; Assert.assertEquals(CommaListExpression.isExpressionOfType(expression, '{', '}', null) == null, true); } { List<String> expected = Arrays.asList( "ARGUMENT_ONE = OBJECT { FIRST = $(1.0/(1.0+1.0)), SECOND = objRef }", "ARGUMENT_TWO = OBJECT(FIRST = $(1.0/(1.0+1.0)), SECOND = objRef)", "ARGUMENT_THREE = objRef", "ARGUMENT_FOUR = objRef", "ARGUMENT_FIVE = OBJECT { FIRST = $(1.0/(1.0+1.0)), SECOND = objRef }", "ARGUMENT_SIX = objRef", "ARGUMENT_SEVEN = OBJECT(FIRST = $(1.0/(1.0+1.0)), SECOND = objRef)", "ARGUMENT_EIGHT = OBJECT(FIRST = $(1.0/(1.0+1.0)), SECOND = objRef, " + " THIRD = OBJECT[$(2+2)] { FIRST=$(1), SECOND=OBJECT(FIRST=objRef) } )"); List<String> gained = CommaListExpression .topLevelSplit("ARGUMENT_ONE = OBJECT { FIRST = $(1.0/(1.0+1.0)), SECOND = objRef }, " + "ARGUMENT_TWO = OBJECT(FIRST = $(1.0/(1.0+1.0)), SECOND = objRef), " + "ARGUMENT_THREE = objRef, " + "ARGUMENT_FOUR = objRef, " + "ARGUMENT_FIVE = OBJECT { FIRST = $(1.0/(1.0+1.0)), SECOND = objRef }, " + "ARGUMENT_SIX = objRef, " + "ARGUMENT_SEVEN = OBJECT(FIRST = $(1.0/(1.0+1.0)), SECOND = objRef), " + "ARGUMENT_EIGHT = OBJECT(FIRST = $(1.0/(1.0+1.0)), SECOND = objRef, " + " THIRD = OBJECT[$(2+2)] { FIRST=$(1), SECOND=OBJECT(FIRST=objRef) } )"); Assert.assertEquals(expected.size(), gained.size()); for (int i = 0; i < expected.size(); ++i) { Assert.assertEquals(expected.get(i), gained.get(i)); } } System.out.println("CommaListExpression tests pass."); }
From source file:hudson.plugins.vcloud.VCloudDirector.java
public static void main(String args[]) throws VCloudException, TimeoutException, KeyManagementException, UnrecoverableKeyException { String vcloudHost = "https://res01.ilandcloud.com"; String vdDescription = "vdc1"; String vdOrganization = "Splunk-130810582"; String vdcConfiguration = "Splunk RES vDC"; String username = "ilandsplunk@Splunk-130810582"; String password = "splunk1235"; int maxOnlineSlaves = Integer.parseInt("9"); String vAppTemplateName = "centos-gold"; VCloudDirector splunkVcd = new VCloudDirector(vcloudHost, vdDescription, vdOrganization, vdcConfiguration, username, password, maxOnlineSlaves); Vdc vdc = splunkVcd.getVdcByName(splunkVcd.vdconfiguration); if (vdc != null) { log.info(String.format("We found the actual VDC with name=%s", vdc.getResource().getName())); }// w w w .j a va 2s .c om ReferenceType refType = splunkVcd.getVappTemplateByName(vdc, vAppTemplateName); if (refType != null) { log.info(String.format("We found the actual template with name=%s", refType.getName())); } Vapp vapp = splunkVcd.newvAppFromTemplate(vAppTemplateName, vdc); List<Task> tasks = vapp.getTasks(); if (tasks.size() > 0) { tasks.get(0).waitForTask(0); } splunkVcd.getListOfVappTemplates(); splunkVcd.configureVMsIPAddressingMode(vapp.getReference(), vdc); String vappName = vapp.getReference().getName(); log.info("Deploying the " + vappName); vapp.deploy(false, 1000000, false).waitForTask(0); log.info("PowerOn the " + vappName); vapp.powerOn().waitForTask(0); log.info("Suspend the " + vappName); vapp.suspend().waitForTask(0); log.info("PowerOn the " + vappName); vapp.powerOn().waitForTask(0); log.info("PowerOff the " + vappName); vapp.powerOff().waitForTask(0); log.info("Undeploy the " + vappName); vapp.undeploy(UndeployPowerActionType.SHUTDOWN).waitForTask(0); log.info("Delete the " + vappName); vapp.delete().waitForTask(0); }
From source file:com.meidusa.venus.benchmark.FileLineData.java
public static void main(String[] args) throws Exception { final FileLineData mapping = new FileLineData(); mapping.setFile(new File("./role.txt")); mapping.init();//from w ww . j a va 2s. c o m List<Thread> list = new ArrayList<Thread>(); long start = TimeUtil.currentTimeMillis(); for (int j = 0; j < 1; j++) { Thread thread = new Thread() { public void run() { for (int i = 0; i < 1000; i++) { System.out.println(mapping.nextData()); } } }; list.add(thread); thread.start(); } for (int i = 0; i < list.size(); i++) { list.get(i).join(); } System.out.println("time=" + (TimeUtil.currentTimeMillis() - start)); }