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:com.redhat.poc.jdg.bankofchina.performance.TestCase531RemoteMultiThreads.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;/*ww  w .j av  a 2  s. c om*/
    Options options = new Options();
    options.addOption("n", true, "The read thread numbers option");
    options.addOption("t", true, "The thread read times option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("n")) {
            String numbers = commandLine.getOptionValue("n");
            if (numbers != null && numbers.length() > 0) {
                readThreadNumbers = Integer.parseInt(numbers);
            }
        }
        if (commandLine.hasOption("t")) {
            String times = commandLine.getOptionValue("t");
            if (times != null && times.length() > 0) {
                threadReadTimes = Integer.parseInt(times);
            }
        }
    }

    System.out.println();
    System.out.println("%%%%%%%%%  userid.csv  %%%%%%%%%");
    LoadUserIdList();
    randomPoolSize = userIdList.size();
    System.out.println(
            "%%%%%%%%% ? userid.csv ,  " + randomPoolSize + " ?? %%%%%%%%%");
    randomPoolSizeByThread = randomPoolSize / readThreadNumbers;

    System.out.println();
    System.out.println(
            "%%%%%%%%% ?, " + readThreadNumbers + " ,, ???, "
                    + threadReadTimes + " ,?, ?(ms)," + new Date().getTime());

    for (int i = 0; i < readThreadNumbers; i++) {
        new TestCase531RemoteMultiThreads(i * randomPoolSizeByThread).start();
    }
}

From source file:com.redhat.poc.jdg.bankofchina.performance.TestCase532RemoteMultiThreads.java

public static void main(String[] args) throws Exception {
    CommandLine commandLine;/*from  w w  w.  j av a  2  s .  com*/
    Options options = new Options();
    options.addOption("n", true, "The read thread numbers option");
    options.addOption("t", true, "The thread read times option");
    BasicParser parser = new BasicParser();
    parser.parse(options, args);
    commandLine = parser.parse(options, args);
    if (commandLine.getOptions().length > 0) {
        if (commandLine.hasOption("n")) {
            String numbers = commandLine.getOptionValue("n");
            if (numbers != null && numbers.length() > 0) {
                writeThreadNumbers = Integer.parseInt(numbers);
            }
        }
        if (commandLine.hasOption("t")) {
            String times = commandLine.getOptionValue("t");
            if (times != null && times.length() > 0) {
                threadWriteTimes = Integer.parseInt(times);
            }
        }
    }
    System.out.println();
    System.out.println("%%%%%%%%%  userid.csv  %%%%%%%%%");
    LoadUserIdList();
    randomPoolSize = userIdList.size();
    System.out.println(
            "%%%%%%%%% ? userid.csv ,  " + randomPoolSize + " ?? %%%%%%%%%");
    randomPoolSizeByThread = randomPoolSize / writeThreadNumbers;

    System.out.println();
    System.out.println(
            "%%%%%%%%% ?, " + writeThreadNumbers + ", , ??, "
                    + threadWriteTimes + ", ?, ?(ms)," + new Date().getTime());

    for (int i = 0; i < writeThreadNumbers; i++) {
        new TestCase532RemoteMultiThreads(i * randomPoolSizeByThread).start();
    }
}

From source file:dhtaccess.tools.Remove.java

public static void main(String[] args) {
    int ttl = 3600;

    // parse properties
    Properties prop = System.getProperties();
    String gateway = prop.getProperty("dhtaccess.gateway");
    if (gateway == null || gateway.length() <= 0) {
        gateway = DEFAULT_GATEWAY;/*from  www .ja v a  2s  .co m*/
    }

    // parse options
    Options options = new Options();
    options.addOption("h", "help", false, "print help");
    options.addOption("g", "gateway", true, "gateway URI, list at http://opendht.org/servers.txt");
    options.addOption("t", "ttl", true, "how long (in seconds) to store the value");

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        System.out.println("There is an invalid option.");
        e.printStackTrace();
        System.exit(1);
    }

    String optVal;
    if (cmd.hasOption('h')) {
        usage(COMMAND);
        System.exit(1);
    }
    optVal = cmd.getOptionValue('g');
    if (optVal != null) {
        gateway = optVal;
    }
    optVal = cmd.getOptionValue('t');
    if (optVal != null) {
        ttl = Integer.parseInt(optVal);
    }

    args = cmd.getArgs();

    // parse arguments
    if (args.length < 3) {
        usage(COMMAND);
        System.exit(1);
    }

    byte[] key = null, value = null, secret = null;
    try {
        key = args[0].getBytes(ENCODE);
        value = args[1].getBytes(ENCODE);
        secret = args[2].getBytes(ENCODE);
    } catch (UnsupportedEncodingException e1) {
        // NOTREACHED
    }

    // prepare for RPC
    DHTAccessor accessor = null;
    try {
        accessor = new DHTAccessor(gateway);
    } catch (MalformedURLException e) {
        e.printStackTrace();
        System.exit(1);
    }

    // RPC
    int res = accessor.remove(key, value, ttl, secret);

    String resultString;
    switch (res) {
    case 0:
        resultString = "Success";
        break;
    case 1:
        resultString = "Capacity";
        break;
    case 2:
        resultString = "Again";
        break;
    default:
        resultString = "???";
    }
    System.out.println(resultString);
}

From source file:MainServer.java

public static void main(String[] args) {
    int port = 1234;
    String filepath = "";
    String complete_path = "";
    String connection_type = "";
    String ip_address = "";
    int port_out = 0;
    int delay = 20; //20 by default

    //parse commands using getOpt (cli)
    //add Options
    Options options = new Options();

    options.addOption("p", true, "port_to_listen_on");
    options.addOption("d", true, "directory");
    options.addOption("T", false, "TCP mode");
    options.addOption("U", false, "UDP mode");
    options.addOption("s", true, "iPAddress");
    options.addOption("P", true, "port_to_connect_to");
    options.addOption("D", true, "delay");

    CommandLineParser clp = new DefaultParser();
    try {/* w w  w  . ja  v  a 2 s . c o m*/
        CommandLine cl = clp.parse(options, args);

        //options for the server
        if (cl.hasOption("p")) {
            port = Integer.parseInt(cl.getOptionValue("p"));
        } else {
            System.err.println("No valid port selected.");
            return;
        }

        if (cl.hasOption("d")) {
            filepath = cl.getOptionValue("d");
            //if there a '/' in front, remove it to make it a valid directory
            if (filepath.substring(0, 1).equalsIgnoreCase("/")) {
                filepath = filepath.substring(1);
            }
        } else {
            System.err.println("No valid directory given.");
            return;
        }

        if (cl.hasOption("D")) {
            delay = Integer.parseInt(cl.getOptionValue("D"));
        }

        //options for the client
        if (cl.hasOption("T")) {
            connection_type = "T";
        } else if (cl.hasOption("U")) {
            connection_type = "U";
        }

        if (cl.hasOption("s")) {
            ip_address = cl.getOptionValue("s");
        }

        if (cl.hasOption("P")) {
            port_out = Integer.parseInt(cl.getOptionValue("P"));
        }

    } catch (ParseException e) {
        //TODO: handle exception
    }

    //create directory (if it doesn't already exist)
    try {
        Files.createDirectories(Paths.get(filepath));
    } catch (Exception e) {
        //TODO: handle exception
        System.err.println("Couldn't create directory");
        System.err.println(filepath);
    }

    //read in required files (create them if they dont already exist)
    try {
        Files.createFile(Paths.get(filepath + "/gossip.txt"));
        Files.createFile(Paths.get(filepath + "/peers.txt"));
    } catch (Exception e) {
        //TODO: handle exception
    }
    WriteToFiles.readFiles(filepath);

    //start the servers
    TCPServerSock tcpServer = new TCPServerSock(port, filepath, delay);
    UDPServer udpServer = new UDPServer(port, filepath);

    Thread tcpThread = new Thread(tcpServer);
    Thread udpThread = new Thread(udpServer);

    tcpThread.start();
    udpThread.start();

    //start the client
    if (!connection_type.equals("") && port_out != 0 && !ip_address.equals("")) {
        Client client = new Client(ip_address, port_out, connection_type);
        Thread clientThread = new Thread(client);
        clientThread.start();
    }

    //Start thread to forget peers
    ForgetPeer forgetPeer = new ForgetPeer(filepath + "/peers.txt", delay);
    Thread forgetPeerThread = new Thread(forgetPeer);
    forgetPeerThread.start();
}

From source file:akori.Impact.java

static public void main(String[] args) throws IOException {
    String PATH = "E:\\Trabajos\\AKORI\\datosmatrizgino\\";
    String PATHIMG = "E:\\NetBeansProjects\\AKORI\\Proccess_1\\ImagesPages\\";
    for (int i = 1; i <= 32; ++i) {
        for (int k = 1; k <= 15; ++k) {
            System.out.println("Matrix " + i + "-" + k);
            BufferedImage img = null;
            try {
                img = ImageIO.read(new File(PATHIMG + i + ".png"));
            } catch (IOException ex) {
                ex.getStackTrace();//ww w.  jav a 2 s .c  o  m
            }

            int ymax = img.getHeight();
            int xmax = img.getWidth();

            double[][] imagen = new double[ymax][xmax];

            BufferedReader in = null;
            try {
                in = new BufferedReader(new FileReader(PATH + i + "-" + k + ".txt"));
            } catch (FileNotFoundException ex) {
                ex.getStackTrace();
            }

            String linea;
            ArrayList<String> lista = new ArrayList<String>();
            HashMap<String, String> lista1 = new HashMap<String, String>();
            try {
                for (int j = 0; (linea = in.readLine()) != null; ++j) {
                    String[] datos = linea.split(",");
                    int x = (int) Double.parseDouble(datos[1]);
                    int y = (int) Double.parseDouble(datos[2]);
                    if (x >= xmax || y >= ymax || x <= 0 || y <= 0) {
                        continue;
                    }
                    lista.add(x + "," + y);
                }
            } catch (Exception ex) {
                ex.getStackTrace();
            }

            try {
                in.close();
            } catch (IOException ex) {
                ex.getStackTrace();
            }

            Iterator iter = lista.iterator();
            int[][] matrix = new int[lista.size()][2];

            for (int j = 0; iter.hasNext(); ++j) {
                String xy = (String) iter.next();
                String[] datos = xy.split(",");
                matrix[j][0] = Integer.parseInt(datos[0]);
                matrix[j][1] = Integer.parseInt(datos[1]);
            }

            for (int j = 0; j < matrix.length; ++j) {

                int std = 50;
                int x = matrix[j][0];
                int y = matrix[j][1];
                imagen[y][x] += 1;
                double aux;
                normalMatrix(imagen, y, x, std);

            }

            FileWriter fw = new FileWriter(PATH + "Matrix" + i + "-" + k + ".txt");
            BufferedWriter bw = new BufferedWriter(fw);
            for (int j = 0; j < imagen.length; ++j) {
                for (int t = 0; t < imagen[j].length; ++t) {
                    if (t + 1 == imagen[j].length)
                        bw.write(imagen[j][t] + "");
                    else
                        bw.write(imagen[j][t] + ",");
                }
                bw.write("\n");
            }
            bw.close();
        }
    }
}

From source file:com.dumontierlab.pdb2rdf.cluster.ClusterServer.java

public static void main(String[] args) {

    Options options = createOptions();/*w  w w  . ja v a2  s.c o  m*/
    CommandLineParser parser = createCliParser();

    try {
        CommandLine cmd = parser.parse(options, args);

        if (!cmd.hasOption("dir")) {
            LOG.fatal("You need to specify the input directory");
            System.exit(1);
        }
        File inputDir = new File(cmd.getOptionValue("dir"));
        if (!inputDir.exists() || !inputDir.isDirectory()) {
            LOG.fatal("The specified input directory is not a valid directory");
            System.exit(1);
        }

        int port = DEFAULT_PORT;
        if (cmd.hasOption("port")) {
            try {
                port = Integer.parseInt(cmd.getOptionValue("port"));
            } catch (NumberFormatException e) {
                LOG.fatal("Invalid port number", e);
                System.exit(1);
            }
        }
        boolean gzip = cmd.hasOption("gzip");

        try {
            startServer(inputDir, gzip, port);
        } catch (Exception e) {
            LOG.fatal("Unable to start the server.", e);
            System.exit(1);
        }

    } catch (ParseException e) {
        LOG.fatal("Unable understand your command.");
        printUsage();
        System.exit(1);
    }

}

From source file:com.k42b3.quantum.Entry.java

public static void main(String[] args) throws Exception {
    // logging/*from  w  ww .  ja v a2s.  c  om*/
    Layout layout = new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN);

    Logger.getLogger("com.k42b3.quantum").addAppender(new WriterAppender(layout, System.out));

    // options
    Options options = new Options();
    options.addOption("p", "port", false, "Port for the web server default is 8080");
    options.addOption("i", "interval", false,
            "The interval how often each worker gets triggered in minutes default is 2");
    options.addOption("d", "database", false, "Path to the sqlite database default is \"quantum.db\"");
    options.addOption("l", "log", false,
            "Defines the log level default is ERROR possible is (ALL, TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF)");
    options.addOption("v", "version", false, "Shows the current version");
    options.addOption("h", "help", false, "Shows the help");

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = parser.parse(options, args);

    // start app
    Quantum app = new Quantum();

    if (cmd.hasOption("p")) {
        try {
            int port = Integer.parseInt(cmd.getOptionValue("p"));

            app.setPort(port);
        } catch (NumberFormatException e) {
            Logger.getLogger("com.k42b3.quantum").info("Port must be an integer");
        }
    }

    if (cmd.hasOption("i")) {
        try {
            int pollInterval = Integer.parseInt(cmd.getOptionValue("i"));

            app.setPollInterval(pollInterval);
        } catch (NumberFormatException e) {
            Logger.getLogger("com.k42b3.quantum").info("Interval must be an integer");
        }
    }

    if (cmd.hasOption("d")) {
        String dbPath = cmd.getOptionValue("d");

        if (!dbPath.isEmpty()) {
            app.setDbPath(dbPath);
        }
    }

    if (cmd.hasOption("l")) {
        Logger.getLogger("com.k42b3.quantum").setLevel(Level.toLevel(cmd.getOptionValue("l")));
    } else {
        Logger.getLogger("com.k42b3.quantum").setLevel(Level.ERROR);
    }

    if (cmd.hasOption("v")) {
        System.out.println("Version: " + Quantum.VERSION);
        System.exit(0);
    }

    if (cmd.hasOption("h")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("quantum.jar", options);
        System.exit(0);
    }

    app.run();
}

From source file:de.jackwhite20.japs.server.Main.java

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

    Config config = null;/*from   w  w  w .  j a v  a2  s  . co m*/

    if (args.length > 0) {
        Options options = new Options();
        options.addOption("h", true, "Address to bind to");
        options.addOption("p", true, "Port to bind to");
        options.addOption("b", true, "The backlog");
        options.addOption("t", true, "Worker thread count");
        options.addOption("d", false, "If debug is enabled or not");
        options.addOption("c", true, "Add server as a cluster");
        options.addOption("ci", true, "Sets the cache check interval");
        options.addOption("si", true, "Sets the snapshot interval");

        CommandLineParser commandLineParser = new BasicParser();
        CommandLine commandLine = commandLineParser.parse(options, args);

        if (commandLine.hasOption("h") && commandLine.hasOption("p") && commandLine.hasOption("b")
                && commandLine.hasOption("t")) {

            List<ClusterServer> clusterServers = new ArrayList<>();

            if (commandLine.hasOption("c")) {
                for (String c : commandLine.getOptionValues("c")) {
                    String[] splitted = c.split(":");
                    clusterServers.add(new ClusterServer(splitted[0], Integer.parseInt(splitted[1])));
                }
            }

            config = new Config(commandLine.getOptionValue("h"),
                    Integer.parseInt(commandLine.getOptionValue("p")),
                    Integer.parseInt(commandLine.getOptionValue("b")), commandLine.hasOption("d"),
                    Integer.parseInt(commandLine.getOptionValue("t")), clusterServers,
                    (commandLine.hasOption("ci")) ? Integer.parseInt(commandLine.getOptionValue("ci")) : 300,
                    (commandLine.hasOption("si")) ? Integer.parseInt(commandLine.getOptionValue("si")) : -1);
        } else {
            System.out.println(
                    "Usage: java -jar japs-server.jar -h <Host> -p <Port> -b <Backlog> -t <Threads> [-c IP:Port IP:Port] [-d]");
            System.out.println(
                    "Example (with debugging enabled): java -jar japs-server.jar -h localhost -p 1337 -b 100 -t 4 -d");
            System.out.println(
                    "Example (with debugging enabled and cluster setup): java -jar japs-server.jar -h localhost -p 1337 -b 100 -t 4 -c localhost:1338 -d");
            System.exit(-1);
        }
    } else {
        File configFile = new File("config.json");
        if (!configFile.exists()) {
            try {
                Files.copy(JaPS.class.getClassLoader().getResourceAsStream("config.json"), configFile.toPath(),
                        StandardCopyOption.REPLACE_EXISTING);
            } catch (IOException e) {
                System.err.println("Unable to load default config!");
                System.exit(-1);
            }
        }

        try {
            config = new Gson().fromJson(
                    Files.lines(configFile.toPath()).map(String::toString).collect(Collectors.joining(" ")),
                    Config.class);
        } catch (IOException e) {
            System.err.println("Unable to load 'config.json' in current directory!");
            System.exit(-1);
        }
    }

    if (config == null) {
        System.err.println("Failed to create a Config!");
        System.err.println("Please check the program parameters or the 'config.json' file!");
    } else {
        System.err.println("Using Config: " + config);

        JaPS jaPS = new JaPS(config);
        jaPS.init();
        jaPS.start();
        jaPS.stop();
    }
}

From source file:com.github.jasmo.Bootstrap.java

public static void main(String[] args) {
    Options options = new Options().addOption("h", "help", false, "Print help message")
            .addOption("v", "verbose", false, "Increase verbosity")
            .addOption("c", "cfn", true,
                    "Enable 'crazy fucking names and set name length (large names == large output size)'")
            .addOption("p", "package", true, "Move obfuscated classes to this package")
            .addOption("k", "keep", true, "Don't rename this class");
    try {//  w w w.  j a va 2 s  . c om
        CommandLineParser clp = new DefaultParser();
        CommandLine cl = clp.parse(options, args);
        if (cl.hasOption("help")) {
            help(options);
            return;
        }
        if (cl.hasOption("verbose")) {
            LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
            Configuration config = ctx.getConfiguration();
            LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
            loggerConfig.setLevel(Level.DEBUG);
            ctx.updateLoggers();
        }
        String[] keep = cl.getOptionValues("keep");
        if (cl.getArgList().size() < 2) {
            throw new ParseException("Expected at-least two arguments");
        }
        log.debug("Input: {}, Output: {}", cl.getArgList().get(0), cl.getArgList().get(1));
        Obfuscator o = new Obfuscator();
        try {
            o.supply(Paths.get(cl.getArgList().get(0)));
        } catch (Exception e) {
            log.error("An error occurred while reading the source target", e);
            return;
        }
        try {
            UniqueStringGenerator usg;
            if (cl.hasOption("cfn")) {
                int size = Integer.parseInt(cl.getOptionValue("cfn"));
                usg = new UniqueStringGenerator.Crazy(size);
            } else {
                usg = new UniqueStringGenerator.Default();
            }
            o.apply(new FullAccessFlags());
            o.apply(new ScrambleStrings());
            o.apply(new ScrambleClasses(usg, cl.getOptionValue("package", ""),
                    keep == null ? new String[0] : keep));
            o.apply(new ScrambleFields(usg));
            o.apply(new ScrambleMethods(usg));
            o.apply(new InlineAccessors());
            o.apply(new RemoveDebugInfo());
            o.apply(new ShuffleMembers());
        } catch (Exception e) {
            log.error("An error occurred while applying transform", e);
            return;
        }
        try {
            o.write(Paths.get(cl.getArgList().get(1)));
        } catch (Exception e) {
            log.error("An error occurred while writing to the destination target", e);
            return;
        }
    } catch (ParseException e) {
        log.error("Failed to parse command line arguments", e);
        help(options);
    }
}

From source file:org.apache.nutch.webui.NutchUiServer.java

public static void main(String[] args) throws Exception {
    CommandLineParser parser = new GnuParser();
    Options options = createWebAppOptions();
    CommandLine commandLine = null;// w  ww .j a va  2 s.  c  om
    HelpFormatter formatter = new HelpFormatter();
    try {
        commandLine = parser.parse(options, args);
    } catch (Exception e) {
        formatter.printHelp("NutchUiServer", options, true);
        StringUtils.stringifyException(e);
    }

    if (commandLine.hasOption("help")) {
        formatter.printHelp("NutchUiServer", options, true);
        return;
    }
    if (commandLine.hasOption(CMD_PORT)) {
        port = Integer.parseInt(commandLine.getOptionValue(CMD_PORT));
    }
    startServer();
}