Example usage for java.lang Integer parseInt

List of usage examples for java.lang Integer parseInt

Introduction

In this page you can find the example usage for java.lang Integer parseInt.

Prototype

public static int parseInt(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal integer.

Usage

From source file:DaytimeClient.java

public static void main(String args[]) throws java.io.IOException {
    // Figure out the host and port we're going to talk to
    String host = args[0];//  w w  w  .  j a  v a 2 s .c om
    int port = 13;
    if (args.length > 1)
        port = Integer.parseInt(args[1]);

    // Create a socket to use
    DatagramSocket socket = new DatagramSocket();

    // Specify a 1-second timeout so that receive() does not block forever.
    socket.setSoTimeout(1000);

    // This buffer will hold the response. On overflow, extra bytes are
    // discarded: there is no possibility of a buffer overflow attack here.
    byte[] buffer = new byte[512];
    DatagramPacket packet = new DatagramPacket(buffer, buffer.length, new InetSocketAddress(host, port));

    // Try three times before giving up
    for (int i = 0; i < 3; i++) {
        try {
            // Send an empty datagram to the specified host (and port)
            packet.setLength(0); // make the packet empty
            socket.send(packet); // send it out

            // Wait for a response (or timeout after 1 second)
            packet.setLength(buffer.length); // make room for the response
            socket.receive(packet); // wait for the response

            // Decode and print the response
            System.out.print(new String(buffer, 0, packet.getLength(), "US-ASCII"));
            // We were successful so break out of the retry loop
            break;
        } catch (SocketTimeoutException e) {
            // If the receive call timed out, print error and retry
            System.out.println("No response");
        }
    }

    // We're done with the channel now
    socket.close();
}

From source file:delete_tcp.java

public static void main(String ar[]) throws IOException {
    ServerSocket ss = new ServerSocket(9999);

    Socket s = ss.accept();//from   w w w.j  a v a2 s  .c o m

    DataInputStream in = new DataInputStream(s.getInputStream());
    DataOutputStream out = new DataOutputStream(s.getOutputStream());

    String id = in.readUTF();

    ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");

    EmployeeJDBCTemplate employeeJDBCTemplate = (EmployeeJDBCTemplate) context.getBean("employeeJDBCTemplate");

    System.out.println("Deleting Records...");

    employeeJDBCTemplate.delete(Integer.parseInt(id));

    out.writeUTF("Success");

    s.close();

}

From source file:com.netflix.suro.client.example.SuroClient4Test.java

public static void main(String[] args) throws JsonProcessingException, InterruptedException {
    // ip num_of_messages message_size sleep num_of_iterations
    String ip = args[0];/*  w w  w. j  a  v  a2 s.  c  om*/
    int numMessages = Integer.parseInt(args[1]);
    int messageSize = Integer.parseInt(args[2]);
    int sleep = Integer.parseInt(args[3]);
    int numIterations = Integer.parseInt(args[4]);

    Properties props = new Properties();
    props.setProperty(ClientConfig.LB_TYPE, "static");
    props.setProperty(ClientConfig.LB_SERVER, ip);

    SuroClient client = new SuroClient(props);
    byte[] payload = createMessagePayload(messageSize);
    for (int n = 0; n < numIterations; ++n) {
        for (int i = 0; i < numMessages; ++i) {
            client.send(new Message(i % 2 == 0 ? "request_trace" : "nf_errors_log", payload));
        }
        Thread.sleep(sleep);
    }
    client.shutdown();
}

From source file:Server_socket.java

public static void main(String argv[]) throws Exception {

    int puerto = Integer.parseInt(argv[0]);
    //String username = argv[1];
    //String password = argv[2];
    String clientformat;/*from  w w  w.  ja  v a2  s .  c o  m*/
    String clientdata;
    String clientresult;
    String clientresource;
    String url_login = "http://localhost:3000/users/sign_in";

    ServerSocket welcomeSocket = new ServerSocket(puerto);

    /*HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(url_login);
            
            
      // Add your data
      List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
      // nameValuePairs.add(new BasicNameValuePair("utf8", Character.toString('\u2713')));
      nameValuePairs.add(new BasicNameValuePair("username", username));
      nameValuePairs.add(new BasicNameValuePair("password", password));
      // nameValuePairs.add(new BasicNameValuePair("commit", "Sign in"));
      httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            
      // Execute HTTP Post Request
      HttpResponse response = httpClient.execute(httpPost);
      String ret = EntityUtils.tostring(response.getEntity());
       System.out.println(ret);
            
            
    */ while (true) {
        Socket connectionSocket = welcomeSocket.accept();

        BufferedReader inFromClient = new BufferedReader(
                new InputStreamReader(connectionSocket.getInputStream()));
        clientformat = inFromClient.readLine();
        System.out.println("FORMAT: " + clientformat);
        BufferedReader inFromClient1 = new BufferedReader(
                new InputStreamReader(connectionSocket.getInputStream()));
        clientdata = inFromClient1.readLine();
        System.out.println("DATA: " + clientdata);
        BufferedReader inFromClient2 = new BufferedReader(
                new InputStreamReader(connectionSocket.getInputStream()));
        clientresult = inFromClient2.readLine();
        System.out.println("RESULT: " + clientresult);
        BufferedReader inFromClient3 = new BufferedReader(
                new InputStreamReader(connectionSocket.getInputStream()));
        clientresource = inFromClient3.readLine();
        System.out.println("RESOURCE: " + clientresource);
        System.out.println("no pasas de aqui");

        String url = "http://localhost:3000/" + clientresource + "/" + clientdata + "." + clientformat;
        System.out.println(url);
        try (InputStream is = new URL(url).openStream()) {
            BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));

            StringBuilder sb = new StringBuilder();
            int cp;
            while ((cp = rd.read()) != -1) {
                sb.append((char) cp);
            }
            String stb = sb.toString();
            System.out.println("estas aqui");

            String output = null;
            String jsonText = stb;

            output = jsonText.replace("[", "").replace("]", "");
            JSONObject json = new JSONObject(output);

            System.out.println(json.toString());
            System.out.println("llegaste al final");
            DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
            outToClient.writeBytes(json.toString());

        }

        connectionSocket.close();
    }
}

From source file:cloudclient.Client.java

public static void main(String[] args) throws Exception {
    //Command interpreter
    CommandLineInterface cmd = new CommandLineInterface(args);

    String socket = cmd.getOptionValue("s");
    String Host_IP = socket.split(":")[0];
    int Port = Integer.parseInt(socket.split(":")[1]);
    String workload = cmd.getOptionValue("w");

    try {//from   www  .j a  v a2  s.  c o m
        // make connection to server socket 
        Socket client = new Socket(Host_IP, Port);

        InputStream inStream = client.getInputStream();
        OutputStream outStream = client.getOutputStream();
        PrintWriter out = new PrintWriter(outStream, true);
        BufferedReader in = new BufferedReader(new InputStreamReader(inStream));

        System.out.println("Send tasks to server...");
        //Start clock
        long startTime = System.currentTimeMillis();

        //Batch sending tasks
        batchSendTask(out, workload);
        client.shutdownOutput();

        //Batch receive responses
        batchReceiveResp(in);

        //End clock
        long endTime = System.currentTimeMillis();
        double totalTime = (endTime - startTime) / 1e3;

        System.out.println("\nDone!");
        System.out.println("Time to execution = " + totalTime + " sec.");

        // close the socket connection
        client.close();

    } catch (IOException ioe) {
        System.err.println(ioe);
    }

}

From source file:com.rockhoppertech.music.examples.PatternFactoryExample.java

public static void main(String[] args) {

    String s = (String) JOptionPane.showInputDialog(null, "Limit", "Chooser", QUESTION_MESSAGE);
    int limit = 7;
    if (s != null) {
        limit = Integer.parseInt(s);
    }/*  ww  w . ja  va  2  s.com*/

    Integer[] nums = new Integer[limit - 1];
    for (int i = 2; i < nums.length + 2; i++) {
        nums[i - 2] = i;
    }
    Integer size = (Integer) showInputDialog(null, "Pattern size", "Chooser", QUESTION_MESSAGE, null, nums,
            nums[0]);

    int w = JOptionPane.showConfirmDialog(null, "Weed Repeats?", "choose one", JOptionPane.YES_NO_OPTION);

    List<int[]> list = null;
    list = PatternFactory.getPatterns(limit, size, w == YES_OPTION);
    printArray(list);
}

From source file:cat.tv3.eng.rec.recomana.lupa.visualization.RecommendationToJson.java

public static void main(String[] args) throws IOException {
    final int TOTAL_WORDS = 20;
    String host = args[0];//from   w  w w . j a va2s  .c  o  m
    int port = Integer.parseInt(args[1]);
    Jedis jedis = new Jedis(host, port, 20000);

    String[] recommendation_keys = jedis.keys("recommendations_*").toArray(new String[0]);

    for (int i = 0; i < recommendation_keys.length; ++i) {
        JSONArray recommendations = new JSONArray();
        String[] split_reco_name = recommendation_keys[i].split("_");
        String id = split_reco_name[split_reco_name.length - 1];

        Set<Tuple> recos = jedis.zrangeWithScores(recommendation_keys[i], 0, -1);
        Iterator<Tuple> it = recos.iterator();

        while (it.hasNext()) {
            Tuple t = it.next();

            JSONObject new_reco = new JSONObject();
            new_reco.put("id", t.getElement());
            new_reco.put("distance", (double) Math.round(t.getScore() * 10000) / 10000);

            recommendations.add(new_reco);
        }
        saveResults(recommendations, id);
    }
    jedis.disconnect();
}

From source file:com.alibaba.simpleimage.ColorQuantPerfTest.java

public static void main(String[] args) throws Exception {
    String appDir = "";
    int threads = 0;
    int times = 0;
    String algName = "";

    appDir = args[0];//ww w  . jav  a  2  s . com
    threads = Integer.parseInt(args[1]);
    times = Integer.parseInt(args[2]);
    algName = args[3];

    new ColorQuantPerfTest(appDir, threads, times, algName).start();
}

From source file:de.tum.i13.ConvertCsvToProtobuf.java

public static void main(String args[]) {
    try {/*from ww  w.  j  a  va  2s  .  c  om*/
        LineIterator it = FileUtils.lineIterator(new File("/Users/manit/Projects/sdcbenchmark/Dataset/debscsv"),
                "UTF-8");
        FileOutputStream out = new FileOutputStream("/Users/manit/Projects/sdcbenchmark/Dataset/debsprotobuf",
                true);

        while (it.hasNext()) {

            String csvLine = (String) it.next();
            byte[] csvLineBytes = csvLine.getBytes();
            String line = new String(csvLineBytes, StandardCharsets.UTF_8);
            Debs2015Protos.Taxitrip.Builder builder = Debs2015Protos.Taxitrip.newBuilder();
            String[] splitted = line.split(",");

            builder.setMedallion(splitted[0]);
            builder.setHackLicense(splitted[1]);
            builder.setPickupDatetime(splitted[2]);
            builder.setDropoffDatetime(splitted[3]);
            builder.setTripTimeInSecs(Integer.parseInt(splitted[4]));
            builder.setTripDistance(Float.parseFloat(splitted[5]));
            builder.setPickupLongitude(Float.parseFloat(splitted[6]));
            builder.setPickupLatitude(Float.parseFloat(splitted[7]));
            builder.setDropoffLongitude(Float.parseFloat(splitted[8]));
            builder.setDropoffLatitude(Float.parseFloat(splitted[9]));
            builder.setPaymentType(splitted[10]);
            builder.setFareAmount(Float.parseFloat(splitted[11]));
            builder.setSurcharge(Float.parseFloat(splitted[12]));
            builder.setMtaTax(Float.parseFloat(splitted[13]));
            builder.setTipAmount(Float.parseFloat(splitted[14]));
            builder.setTollsAmount(Float.parseFloat(splitted[15]));
            builder.setTotalAmount(Float.parseFloat(splitted[16]));

            builder.build().writeDelimitedTo(out);
        }
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.google.code.fqueue.memcached.StartServer.java

/**
 * @param args/*  w  ww .  j a v a  2 s. c  o m*/
 */
public static void main(String[] args) {
    PropertyConfigurator.configureAndWatch("config/log4j.properties", 5000);
    StartNewQueue.newQueueInstance(Integer.parseInt(Config.getSetting("port")));
    log.info("running at port " + Config.getSetting("port"));
}