List of usage examples for java.lang Integer parseInt
public static int parseInt(String s) throws NumberFormatException
From source file:GetAppInfo.java
/** * @param args/* w ww .j a va 2s .c om*/ */ public static void main(String[] args) { if (args.length != 4) { System.out.println("Usage :\n" + "java -jar this_jar_name confpath query_str startIndex numbers"); System.exit(1); } String confpath = args[0]; GetAppConfig conf = new GetAppConfig(confpath); String email = conf.getUserID(); String password = conf.getPassword(); String query = args[1]; final int startIndex = Integer.parseInt(args[2]); final int numbers = Integer.parseInt(args[3]); String androidid = conf.getDeviceID(); if (email.equals("")) { System.out.println("Error: Failed to get UserID."); System.exit(2); } else if (password.equals("")) { System.out.println("Error: Failed to get Password."); System.exit(3); } else if (androidid.equals("")) { System.out.println("Error: Failed to get DeviceID."); System.exit(4); } System.out.println("query: " + query); MarketSession session = new MarketSession(); session.getContext().setAndroidId(androidid); Locale locale = new Locale("ja", "JP"); session.setLocale(locale); session.setOperator("NTT DOCOMO", "44010"); session.getContext().setDeviceAndSdkVersion("passion:8"); try { session.login(email, password, androidid); } catch (Exception e) { System.out.println("Error: failed to login.: " + e.getMessage()); System.exit(1); } AppsRequest appsRequest = AppsRequest.newBuilder().setQuery(query).setStartIndex(startIndex) .setEntriesCount(numbers).setWithExtendedInfo(true).build(); Callback<AppsResponse> callback = new Callback<AppsResponse>() { @Override public void onResult(ResponseContext context, AppsResponse response) { int totalcnt, cnt; JsonFactory factory = new JsonFactory(); try { JsonGenerator generator = factory.createGenerator(new FileWriter(new File("pkginfo.json"))); generator.writeStartObject(); //generator.setRootValueSeparator(new SerializedString("\n")); if (response != null) { totalcnt = response.getEntriesCount(); cnt = response.getAppCount(); System.out.println("startIndex = " + startIndex); System.out.println("entriesCount = " + numbers); System.out.println("totalcount = " + totalcnt); System.out.println("count = " + cnt); generator.writeNumberField("startIndex", startIndex); generator.writeNumberField("entriesCount", numbers); generator.writeNumberField("total", totalcnt); generator.writeNumberField("count", cnt); generator.writeRaw("\n"); } else { cnt = -1; } generator.writeFieldName("dataset"); generator.writeStartArray(); if (cnt > 0) { for (int i = 0; ((i < cnt) && (i < numbers)); i++) { generator.writeStartObject(); generator.writeNumberField("num", i + startIndex); System.out.println( "------------------------------------------------------------------------------------"); int counter = i + startIndex; System.out.println(counter + ":"); System.out.println( "------------------------------------------------------------------------------------"); generator.writeStringField("title", response.getApp(i).getTitle()); generator.writeStringField("appType", "" + response.getApp(i).getAppType()); generator.writeStringField("category", response.getApp(i).getExtendedInfo().getCategory()); generator.writeStringField("rating", response.getApp(i).getRating()); generator.writeNumberField("ratingCount", response.getApp(i).getRatingsCount()); generator.writeStringField("countText", response.getApp(i).getExtendedInfo().getDownloadsCountText()); generator.writeStringField("creatorId", response.getApp(i).getCreatorId()); generator.writeStringField("id", response.getApp(i).getId()); generator.writeStringField("packageName", response.getApp(i).getPackageName()); generator.writeStringField("version", response.getApp(i).getVersion()); generator.writeNumberField("versionCode", response.getApp(i).getVersionCode()); generator.writeStringField("price", response.getApp(i).getPrice()); generator.writeNumberField("priceMicros", response.getApp(i).getPriceMicros()); generator.writeStringField("priceCurrency", response.getApp(i).getPriceCurrency()); generator.writeStringField("contactWebsite", response.getApp(i).getExtendedInfo().getContactWebsite()); generator.writeNumberField("screenshotsCount", response.getApp(i).getExtendedInfo().getScreenshotsCount()); generator.writeNumberField("installSize", response.getApp(i).getExtendedInfo().getInstallSize()); generator.writeStringField("permissionIdList", "" + response.getApp(i).getExtendedInfo().getPermissionIdList()); generator.writeStringField("promotoText", response.getApp(i).getExtendedInfo().getPromoText()); generator.writeStringField("description", response.getApp(i).getExtendedInfo().getDescription()); System.out.println("title: " + response.getApp(i).getTitle()); System.out.println("appType: " + response.getApp(i).getAppType()); System.out.println("category: " + response.getApp(i).getExtendedInfo().getCategory()); System.out.println("rating: " + response.getApp(i).getRating()); System.out.println("ratingsCount: " + response.getApp(i).getRatingsCount()); System.out .println("count: " + response.getApp(i).getExtendedInfo().getDownloadsCount()); System.out.println( "countText: " + response.getApp(i).getExtendedInfo().getDownloadsCountText()); System.out.println("creator: " + response.getApp(i).getCreator()); System.out.println("creatorId: " + response.getApp(i).getCreatorId()); System.out.println("id: " + response.getApp(i).getId()); System.out.println("packageName: " + response.getApp(i).getPackageName()); System.out.println("version: " + response.getApp(i).getVersion()); //System.out.println("contactEmail: " + response.getApp(i).getExtendedInfo().getContactEmail()); //System.out.println("contactPhone: " + response.getApp(i).getExtendedInfo().getContactPhone()); System.out.println( "installSize: " + response.getApp(i).getExtendedInfo().getInstallSize()); generator.writeEndObject(); generator.writeRaw("\n"); } } else if (cnt == 0) { System.out.println("no hit"); } else { System.out.println("Bad Reqeust"); } generator.writeEndArray(); generator.writeEndObject(); generator.close(); } catch (Exception e) { System.out.println("Error: pkginfo(): " + e.getMessage()); } } // onResult() }; session.append(appsRequest, callback); session.flush(); }
From source file:GenericClient.java
public static void main(String[] args) throws IOException { try {//w ww . j a va 2s . c o m // Check the number of arguments if (args.length != 2) throw new IllegalArgumentException("Wrong number of args"); // Parse the host and port specifications String host = args[0]; int port = Integer.parseInt(args[1]); // Connect to the specified host and port Socket s = new Socket(host, port); // Set up streams for reading from and writing to the server. // The from_server stream is final for use in the inner class below final Reader from_server = new InputStreamReader(s.getInputStream()); PrintWriter to_server = new PrintWriter(s.getOutputStream()); // Set up streams for reading from and writing to the console // The to_user stream is final for use in the anonymous class below BufferedReader from_user = new BufferedReader(new InputStreamReader(System.in)); // Pass true for auto-flush on println() final PrintWriter to_user = new PrintWriter(System.out, true); // Tell the user that we've connected to_user.println("Connected to " + s.getInetAddress() + ":" + s.getPort()); // Create a thread that gets output from the server and displays // it to the user. We use a separate thread for this so that we // can receive asynchronous output Thread t = new Thread() { public void run() { char[] buffer = new char[1024]; int chars_read; try { // Read characters from the server until the // stream closes, and write them to the console while ((chars_read = from_server.read(buffer)) != -1) { to_user.write(buffer, 0, chars_read); to_user.flush(); } } catch (IOException e) { to_user.println(e); } // When the server closes the connection, the loop above // will end. Tell the user what happened, and call // System.exit(), causing the main thread to exit along // with this one. to_user.println("Connection closed by server."); System.exit(0); } }; // Now start the server-to-user thread t.start(); // In parallel, read the user's input and pass it on to the server. String line; while ((line = from_user.readLine()) != null) { to_server.print(line + "\r\n"); to_server.flush(); } // If the user types a Ctrl-D (Unix) or Ctrl-Z (Windows) to end // their input, we'll get an EOF, and the loop above will exit. // When this happens, we stop the server-to-user thread and close // the socket. s.close(); to_user.println("Connection closed by client."); System.exit(0); } // If anything goes wrong, print an error message catch (Exception e) { System.err.println(e); System.err.println("Usage: java GenericClient <hostname> <port>"); } }
From source file:example.Listener.java
public static void main(String[] args) throws Exception { String user = env("ACTIVEMQ_USER", "admin"); String password = env("ACTIVEMQ_PASSWORD", "password"); String host = env("ACTIVEMQ_HOST", "localhost"); int port = Integer.parseInt(env("ACTIVEMQ_PORT", "1883")); final String destination = arg(args, 0, "/topic/event"); MQTT mqtt = new MQTT(); mqtt.setHost(host, port);/*from w ww .j a v a 2 s. c om*/ mqtt.setUserName(user); mqtt.setPassword(password); final CallbackConnection connection = mqtt.callbackConnection(); connection.listener(new org.fusesource.mqtt.client.Listener() { long count = 0; long start = System.currentTimeMillis(); public void onConnected() { } public void onDisconnected() { } public void onFailure(Throwable value) { value.printStackTrace(); System.exit(-2); } public void onPublish(UTF8Buffer topic, Buffer msg, Runnable ack) { String body = msg.utf8().toString(); if ("SHUTDOWN".equals(body)) { long diff = System.currentTimeMillis() - start; System.out.println(String.format("Received %d in %.2f seconds", count, (1.0 * diff / 1000.0))); connection.disconnect(new Callback<Void>() { @Override public void onSuccess(Void value) { System.exit(0); } @Override public void onFailure(Throwable value) { value.printStackTrace(); System.exit(-2); } }); } else { if (count == 0) { start = System.currentTimeMillis(); } if (count % 1000 == 0) { System.out.println(String.format("Received %d messages.", count)); } count++; } ack.run(); } }); connection.connect(new Callback<Void>() { @Override public void onSuccess(Void value) { Topic[] topics = { new Topic(destination, QoS.AT_LEAST_ONCE) }; connection.subscribe(topics, new Callback<byte[]>() { public void onSuccess(byte[] qoses) { } public void onFailure(Throwable value) { value.printStackTrace(); System.exit(-2); } }); } @Override public void onFailure(Throwable value) { value.printStackTrace(); System.exit(-2); } }); // Wait forever.. synchronized (Listener.class) { while (true) Listener.class.wait(); } }
From source file:es.cnio.bioinfo.bicycle.BinomialAnnotator.java
public static void main(String[] args) throws IOException, MathException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); double p = Double.parseDouble(args[0]); String line = null;/*from w ww . j a va 2s . c o m*/ while ((line = in.readLine()) != null) { String[] tokens = line.split("\t"); int reads = Integer.parseInt(tokens[5]); int cCount = Integer.parseInt(tokens[4]); BinomialDistribution binomial = new BinomialDistributionImpl(reads, p); double pval = (reads == 0) ? 1.0d : (1.0d - binomial.cumulativeProbability(cCount - 1)); if (System.out.checkError()) { System.exit(1); } System.out.println(line + "\t" + pval); } }
From source file:GCD.java
/** * The main method from which the program executes; * it handles all I/O and method execution. * * @param args Arguments received from the command line (two numbers). * @param gcd The calcuated Greatest Common Divisor of args[0] and args [1]. *///www.j a v a 2 s .co m public static void main(String[] args) { // ensure the user only enters two arguments if (args.length == 2) { // ensure the users arguments are numbers try { // calculate gcd int gcd = gcd(Integer.parseInt(args[0]), Integer.parseInt(args[1])); System.out.println( "The Greatest Common Divisor of " + args[0] + " and " + args[1] + " is " + gcd + "."); } catch (NumberFormatException c) { System.out.println("Your arguments must be in " + "the form of integers when " + "running the program (ex. " + "enter 'java numeric.GCD " + "50 30')."); } catch (Exception c) { // used only in GUI } } else { System.out.println("Enter two numbers as arguments " + "when running the program (ex. " + "enter 'java numeric.GCD 50 30')."); } }
From source file:com.mellanox.jxio.helloworld.HelloClient.java
public static void main(String[] args) { if (args.length < 2) { usage();/*w w w. j a va 2 s .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; } HelloClient client = new HelloClient(); client.connect(uri); client.run(); LOG.info("Client is releasing JXIO resources and exiting"); client.releaseResources(); System.exit(client.exitStatus); }
From source file:dualcontrol.CryptoClientDemo.java
public static void main(String[] args) throws Exception { if (args.length != 3) { System.err.println("CryptoClientDemo usage: hostAddress port text"); } else {/*w w w .ja va 2s. com*/ new CryptoClientDemo().call(System.getProperties(), new MockableConsoleAdapter(System.console()), args[0], Integer.parseInt(args[1]), args[2].getBytes()); } }
From source file:dataminning2.DataMinning2.java
/** * @param args the command line arguments *///from w w w.j a va 2 s . c om public static void main(String[] args) throws IOException { // here is the code to load the iris.csv data in an array int ColumnCount = 0; int RowCount = 0; double[][] Dataarraytest; double[][] Dataarray; double[][] SVDS = null; double[][] SVDU = null; double[][] SVDV = null; System.out.println("Do you want to work with 1.att.csv or 2.iris.csv "); InputStreamReader Datasetchoice = new InputStreamReader(System.in); BufferedReader BDatasetChoice = new BufferedReader(Datasetchoice); int Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine()); String path = null; // LOadData LDobj=new LOadData(); LOadData LDobj = new LOadData(); TrainingSetDecomposition TestDataonj = new TrainingSetDecomposition(); SVDDecomposition SVDobj = new SVDDecomposition(); switch (Datasetchoicevalue) { case 1: path = "Datasets\\att.csv"; ColumnCount = LDobj.ColumnCount(path); RowCount = LDobj.RowCount(path); Dataarray = LDobj.Datasetup(path, ColumnCount, RowCount); Dataarraytest = TestDataonj.Decomposition(RowCount, RowCount, 2, Dataarray); SVDS = SVDobj.DecompositionS(Dataarraytest); SVDU = SVDobj.DecompositionU(Dataarraytest); SVDV = SVDobj.DecompositionV(Dataarraytest); System.out.println("Do you want the graph to be plotted 1.yes 2.No"); Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine()); if (Datasetchoicevalue == 1) { WriteCSv wcsvobj = new WriteCSv(); wcsvobj.writeCSVmethod(SVDU, "SVD"); } KMeans_Ex4a Kmeanobj1 = new KMeans_Ex4a(); double[][] KmeanData1 = Kmeanobj1.Main(SVDU); System.out.println("Do you want the graph to be plotted 1.yes 2.No"); Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine()); if (Datasetchoicevalue == 1) { WriteCSVKmean wcsvobj = new WriteCSVKmean(); wcsvobj.writeCSVmethod(KmeanData1, "KMean"); } Gui DBScanobj1 = new Gui(); DBScanobj1.main(SVDU); System.out.println("Do you want the graph to be plotted 1.yes 2.No"); Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine()); if (Datasetchoicevalue == 1) { WriteCSv wcsvobj = new WriteCSv(); wcsvobj.writeCSVmethod(SVDU, "DBScan"); } break; case 2: path = "Datasets\\iris.csv"; ColumnCount = LDobj.ColumnCount(path); RowCount = LDobj.RowCount(path); Dataarray = LDobj.Datasetup(path, ColumnCount, RowCount); Dataarraytest = TestDataonj.Decomposition(RowCount, 150, ColumnCount, Dataarray); SVDS = SVDobj.DecompositionS(Dataarraytest); SVDU = SVDobj.DecompositionU(Dataarraytest); SVDV = SVDobj.DecompositionV(Dataarraytest); System.out.println("Do you want the graph to be plotted 1.yes 2.No"); Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine()); if (Datasetchoicevalue == 1) { WriteCSv wcsvobj = new WriteCSv(); wcsvobj.writeCSVmethod(SVDU, "SVD"); } KMeans_Ex4a Kmeanobj = new KMeans_Ex4a(); double[][] KmeanData = Kmeanobj.Main(SVDU); ssecalc distobj = new ssecalc(); String output = distobj.calc(KmeanData); System.out.println(output); System.out.println("Do you want the graph to be plotted 1.yes 2.No"); Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine()); if (Datasetchoicevalue == 1) { WriteCSVKmean wcsvobj = new WriteCSVKmean(); wcsvobj.writeCSVmethod(KmeanData, "KMean"); } Gui DBScanobj = new Gui(); DBScanobj.main(SVDU); System.out.println("Do you want the graph to be plotted 1.yes 2.No"); Datasetchoicevalue = Integer.parseInt(BDatasetChoice.readLine()); if (Datasetchoicevalue == 1) { WriteCSv wcsvobj = new WriteCSv(); wcsvobj.writeCSVmethod(SVDU, "DBScan"); } break; } }
From source file:edu.usc.ee599.CommunityStats.java
public static void main(String[] args) throws Exception { File dir = new File("results5"); PrintWriter writer = new PrintWriter(new FileWriter("results5_stats.txt")); File[] files = dir.listFiles(); DescriptiveStatistics statistics1 = new DescriptiveStatistics(); DescriptiveStatistics statistics2 = new DescriptiveStatistics(); for (File file : files) { BufferedReader reader = new BufferedReader(new FileReader(file)); String line1 = reader.readLine(); String line2 = reader.readLine(); int balanced = Integer.parseInt(line1.split(",")[1]); int unbalanced = Integer.parseInt(line2.split(",")[1]); double bp = (double) balanced / (double) (balanced + unbalanced); double up = (double) unbalanced / (double) (balanced + unbalanced); statistics1.addValue(bp);// w w w .ja v a 2 s . c o m statistics2.addValue(up); } writer.println("AVG Balanced %: " + statistics1.getMean()); writer.println("AVG Unbalanced %: " + statistics2.getMean()); writer.println("STD Balanced %: " + statistics1.getStandardDeviation()); writer.println("STD Unbalanced %: " + statistics2.getStandardDeviation()); writer.flush(); writer.close(); }
From source file:kr.co.exsoft.eframework.util.LicenseUtil.java
public static void main(String[] args) { String ret = ""; if (args.length == 1) { // /*from w w w . j a va 2s . c om*/ ret = licenseDecrpt(args[0]); System.out.println("?? =" + ret); } else if (args.length == 2) { // // LICENSE_TYPE = NAMED - ?? / CONCURRENT - ?? // USER_COUNT = 0 - / ? ? ret = licenseEncrypt(args[0], Integer.parseInt(args[1])); System.out.println("?? =" + ret); } else { System.out.println("Usage: LicenseUtil licenseType userCount"); } }