List of usage examples for java.lang Integer parseInt
public static int parseInt(String s) throws NumberFormatException
From source file:it.anyplace.sync.relay.server.Main.java
public static void main(String[] args) throws ParseException, Exception { Options options = new Options(); options.addOption("r", "relay-server", true, "set relay server to serve for"); options.addOption("p", "port", true, "set http server port"); options.addOption("h", "help", false, "print help"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("s-client", options); return;//from w ww . ja v a 2 s.c o m } int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 22080; String relayServer = firstNonNull(emptyToNull(cmd.getOptionValue("r")), "relay://localhost"); logger.info("starting http relay server :{} for relay server {}", port, relayServer); HttpRelayServer httpRelayServer = new HttpRelayServer( DeviceAddress.newBuilder().setDeviceId("relay").setAddress(relayServer).build().getSocketAddress()); httpRelayServer.start(port); httpRelayServer.join(); }
From source file:com.linkedin.pinotdruidbenchmark.DruidResponseTime.java
public static void main(String[] args) throws Exception { if (args.length != 4 && args.length != 5) { System.err.println(// w w w.j a v a 2s . co m "4 or 5 arguments required: QUERY_DIR, RESOURCE_URL, WARM_UP_ROUNDS, TEST_ROUNDS, RESULT_DIR (optional)."); return; } File queryDir = new File(args[0]); String resourceUrl = args[1]; int warmUpRounds = Integer.parseInt(args[2]); int testRounds = Integer.parseInt(args[3]); File resultDir; if (args.length == 4) { resultDir = null; } else { resultDir = new File(args[4]); if (!resultDir.exists()) { if (!resultDir.mkdirs()) { throw new RuntimeException("Failed to create result directory: " + resultDir); } } } File[] queryFiles = queryDir.listFiles(); assert queryFiles != null; Arrays.sort(queryFiles); try (CloseableHttpClient httpClient = HttpClients.createDefault()) { HttpPost httpPost = new HttpPost(resourceUrl); httpPost.addHeader("content-type", "application/json"); for (File queryFile : queryFiles) { StringBuilder stringBuilder = new StringBuilder(); try (BufferedReader bufferedReader = new BufferedReader(new FileReader(queryFile))) { int length; while ((length = bufferedReader.read(CHAR_BUFFER)) > 0) { stringBuilder.append(new String(CHAR_BUFFER, 0, length)); } } String query = stringBuilder.toString(); httpPost.setEntity(new StringEntity(query)); System.out.println( "--------------------------------------------------------------------------------"); System.out.println("Running query: " + query); System.out.println( "--------------------------------------------------------------------------------"); // Warm-up Rounds System.out.println("Run " + warmUpRounds + " times to warm up..."); for (int i = 0; i < warmUpRounds; i++) { CloseableHttpResponse httpResponse = httpClient.execute(httpPost); httpResponse.close(); System.out.print('*'); } System.out.println(); // Test Rounds System.out.println("Run " + testRounds + " times to get response time statistics..."); long[] responseTimes = new long[testRounds]; long totalResponseTime = 0L; for (int i = 0; i < testRounds; i++) { long startTime = System.currentTimeMillis(); CloseableHttpResponse httpResponse = httpClient.execute(httpPost); httpResponse.close(); long responseTime = System.currentTimeMillis() - startTime; responseTimes[i] = responseTime; totalResponseTime += responseTime; System.out.print(responseTime + "ms "); } System.out.println(); // Store result. if (resultDir != null) { File resultFile = new File(resultDir, queryFile.getName() + ".result"); CloseableHttpResponse httpResponse = httpClient.execute(httpPost); try (BufferedInputStream bufferedInputStream = new BufferedInputStream( httpResponse.getEntity().getContent()); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(resultFile))) { int length; while ((length = bufferedInputStream.read(BYTE_BUFFER)) > 0) { bufferedWriter.write(new String(BYTE_BUFFER, 0, length)); } } httpResponse.close(); } // Process response times. double averageResponseTime = (double) totalResponseTime / testRounds; double temp = 0; for (long responseTime : responseTimes) { temp += (responseTime - averageResponseTime) * (responseTime - averageResponseTime); } double standardDeviation = Math.sqrt(temp / testRounds); System.out.println("Average response time: " + averageResponseTime + "ms"); System.out.println("Standard deviation: " + standardDeviation); } } }
From source file:com.devoteam.srit.xmlloader.http.test.HttpLoaderClient.java
public static void main(String[] args) throws Exception { if (args.length < 2) { System.err.println("Please specify hostname and port number"); System.exit(1);//from ww w .j a va 2 s . c o m } http = new HttpLoaderServer(args[0], Integer.parseInt(args[1])); http.testConnection(); responseThread = new HttpLoaderClient(); // thread de gestion des reponses cot client responseThread.setDaemon(false); responseThread.start(); // lancement du processus de gestion des msg beginThreadRequest = System.currentTimeMillis(); // top chono des requetes for (int i = 0; i < 5000000; i++) testhttp.createRequest(i); // creation et envoie des messages au serveur endThreadRequest = System.currentTimeMillis(); timeThreadRequest = endThreadRequest - beginThreadRequest; // calcul de la duree de l'envoie des msg' }
From source file:dk.statsbiblioteket.jpar2.filecompare.FileCompare.java
/** * Main method. /* w ww . j a v a 2s . c o m*/ * @param args */ public static void main(String[] args) { Options options = new Options(); options.addOption("s", "slices", true, "The number of slices to use in the comparison"); CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); args = cmd.getArgs(); if (!cmd.hasOption("s") || args.length != 2) { System.exit(2); } int slices = Integer.parseInt(cmd.getOptionValue("s").trim()); File f1 = new File(args[0]); File f2 = new File(args[1]); if (f1.length() == f2.length()) { int sliceSize = (int) (f1.length() / slices);//rounding here... DataFile df1 = new DataFile(f1, sliceSize); DataFile df2 = new DataFile(f2, sliceSize); List<Integer> defectIndexes = df1.compareWithIndex(df2); for (int index : defectIndexes) { System.out.println("index " + index + ", from " + index * sliceSize + " to " + (index + 1) * sliceSize + " is defect"); } if (defectIndexes.size() == 0) { System.out.println("Files are identical"); } } else { System.out.println("Files differ in length, cannot help you"); } } catch (ParseException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
From source file:MethodTroubleToo.java
public static void main(String... args) { try {//from w ww . ja v a 2 s. co m MethodTroubleToo mtt = new MethodTroubleToo(); Method m = MethodTroubleToo.class.getMethod("ping"); switch (Integer.parseInt(args[0])) { case 0: m.invoke(mtt); // works break; case 1: m.invoke(mtt, null); // works (expect compiler warning) break; case 2: Object arg2 = null; m.invoke(mtt, arg2); // IllegalArgumentException break; case 3: m.invoke(mtt, new Object[0]); // works break; case 4: Object arg4 = new Object[0]; m.invoke(mtt, arg4); // IllegalArgumentException break; default: System.out.format("Test not found%n"); } // production code should handle these exceptions more gracefully } catch (Exception x) { x.printStackTrace(); } }
From source file:com.rk.grid.federation.FederatedCluster.java
/** * @param args//from ww w. ja v a2 s . c om * @throws Exception */ public static void main(String[] args) throws Exception { int port = Integer.parseInt(args[0]); String clusterName = args[1]; String masterBrokerServiceName = args[2]; int masterPort = Integer.parseInt(args[3]); String masterHost = args[4]; IBroker<Object> masterBroker = null; for (int i = 0; i < 100; i++) { try { masterBroker = getConnection(masterBrokerServiceName, masterPort, masterHost); if (masterBroker != null) break; } catch (RemoteLookupFailureException e) { if (i % 100 == 0) System.out.println("Sleeping...."); } Thread.sleep(100); } if (masterBroker == null) throw new RuntimeException("Unable to find master broker " + masterBrokerServiceName); BrokerInfo brokerInfo = masterBroker.getBrokerInfo(); GridConfig gridConfig = brokerInfo.getConfig(); List<String> jvmNodeParams = masterBroker.getBrokerInfo().getJvmNodeParams(); GridExecutorService cluster = new GridExecutorService(port, jvmNodeParams, gridConfig, clusterName); cluster.getBroker().unPause(); final TaskExecutor taskExecutor = new TaskExecutor(cluster); final IRemoteResultsHandler<Object> callback = masterBroker.getCallback(); IWorkQueue<Object> workQueue = masterBroker.getWorkQueue(); ExecutorService pool = Executors.newFixedThreadPool(3); masterBroker.unPause(); while (!Thread.currentThread().isInterrupted()) { final IExecutable<?> executable = workQueue.take(); if (executable == null) continue; if (executable.equals(IExecutable.POISON)) { break; } Callable<Object> callable = new Callable<Object>() { @Override public Object call() throws Exception { Future<ITaskResult<?>> future = taskExecutor.submit(executable); ITaskResult<?> iResult = future.get(); String uid = executable.getUID(); try { callback.accept(new RemoteResult<Object>(iResult, uid)); } catch (Throwable t) { t.printStackTrace(); try { callback.accept(new RemoteResult<Object>( new RemoteExecutorException("Error execution remote task '" + uid + "'", t), uid)); } catch (RemoteException e) { throw new RuntimeException(e); } } return null; } }; pool.submit(callable); } pool.shutdown(); taskExecutor.shutdown(); System.out.println("Finished...!"); }
From source file:edu.cmu.cs.lti.ark.fn.parsing.CreateAlphabet.java
public static void main(String[] args) throws IOException { FEFileName.feFilename = args[0];/* w ww . j a v a 2s. co m*/ FEFileName.tagFilename = args[1]; FEFileName.eventFilename = args[2]; FEFileName.alphafilename = args[3]; FEFileName.spanfilename = args[4]; boolean genAlpha = Boolean.parseBoolean(args[5]); FEFileName.KBestParse = Integer.parseInt(args[6]); FEFileName.KBestParseDirectory = args[7]; if (genAlpha) System.out.println("Generating alphabet too..."); final List<String> feLines = readLines(new File(FEFileName.feFilename), UTF_8); final List<String> tagLines = readLines(new File(FEFileName.tagFilename), UTF_8); run(genAlpha, tagLines, feLines); }
From source file:com.gamedev.games.ExampleGame.java
public static void main(String args[]) throws Exception { HighScore hs = new HighScore("ExampleGame"); if (args.length == 0) usage();//from w ww .j a va 2 s.c om if (args[0].equals("set")) { hs.setHighScore(Integer.parseInt(args[1])); } else if (args[0].equals("get")) { System.out.println("score = " + hs.getHighScore()); } else { usage(); } }
From source file:com.mellanox.jxio.helloworld.HelloServer.java
public static void main(String[] args) { if (args.length < 2) { usage();/*w w w. j a v a2s . c o m*/ return; } final String serverhostname = args[0]; final int port = Integer.parseInt(args[1]); URI uri = null; try { uri = new URI("rdma://" + serverhostname + ":" + port + "/"); } catch (URISyntaxException e) { e.printStackTrace(); return; } HelloServer server = new HelloServer(uri); server.run(); LOG.info("Server is releasing JXIO resources and exiting"); server.releaseResources(); }
From source file:Standard.java
public static void main(String args[]) throws IOException { BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); String number;/*from w w w . j a v a 2s. c o m*/ int total = 0; while ((number = cin.readLine()) != null) { try { total += Integer.parseInt(number); } catch (NumberFormatException e) { System.err.println("Invalid number in input"); System.exit(1); } } System.out.println(total); }