List of usage examples for java.lang Integer parseInt
public static int parseInt(String s) throws NumberFormatException
From source file:com.ricston.akka.matrix.Main.java
public static void main(String[] args) throws InterruptedException, NumberFormatException, IOException { CommandLineParser parser = new GnuParser(); int numberOfActors = -1; Options options = new Options(); // Set the command line options recognized by this program. setUpCLOptions(options);/*from w ww. j av a 2 s. co m*/ // Parse the command line arguments. CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { quitApp(options); } if (cmd.hasOption(ACTORS)) { // Set the number of actors to create if the user supplied this argument. numberOfActors = Integer.parseInt(cmd.getOptionValue(ACTORS)); } if (cmd.hasOption(GENERATE)) { // Generate a file containing two randomly generated matrices. String[] genArgs = cmd.getOptionValues(GENERATE); if (genArgs.length != 5) { quitApp(options); } MatrixFile.writeMatrixFile(genArgs[0], generateMatrix(Integer.parseInt(genArgs[1]), Integer.parseInt(genArgs[2])), generateMatrix(Integer.parseInt(genArgs[3]), Integer.parseInt(genArgs[4])), new ArrayList<List<Double>>()); } if (cmd.hasOption(COMPUTE)) { // Compute the matrix multiplication of the matrices in the files // given as argument. String[] compArgs = cmd.getOptionValues(COMPUTE); ActorRef managerRef = null; if (numberOfActors > 0) { final int actors = numberOfActors; managerRef = actorOf(new UntypedActorFactory() { public UntypedActor create() { return new ManagerActor(actors); } }); } else { managerRef = actorOf(ManagerActor.class); } // Start the manager actor. managerRef.start(); // Create and send an AllJobsMsg. managerRef.tell(new AllJobsMsg(compArgs)); } if (cmd.getArgs().length > 0 || args.length == 0) { // Handle unrecognized arguments. quitApp(options); } }
From source file:com.canyapan.randompasswordgenerator.cli.Main.java
public static void main(String[] args) { Options options = new Options(); options.addOption("h", false, "prints help"); options.addOption("def", false, "generates 8 character password with default options"); options.addOption("p", true, "password length (default 8)"); options.addOption("l", false, "include lower case characters"); options.addOption("u", false, "include upper case characters"); options.addOption("d", false, "include digits"); options.addOption("s", false, "include symbols"); options.addOption("lc", true, "minimum lower case character count (default 0)"); options.addOption("uc", true, "minimum upper case character count (default 0)"); options.addOption("dc", true, "minimum digit count (default 0)"); options.addOption("sc", true, "minimum symbol count (default 0)"); options.addOption("a", false, "avoid ambiguous characters"); options.addOption("f", false, "force every character type"); options.addOption("c", false, "continuous password generation"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = null;/*from ww w .j a v a 2 s . c o m*/ boolean printHelp = false; try { cmd = parser.parse(options, args); } catch (ParseException e) { printHelp = true; } if (printHelp || args.length == 0 || cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "java -jar RandomPasswordGenerator.jar [-p <arg>] [-l] [-u] [-s] [-d] [-dc <arg>] [-a] [-f]", options); return; } RandomPasswordGenerator rpg = new RandomPasswordGenerator(); if (cmd.hasOption("def")) { rpg.withDefault().withPasswordLength(Integer.parseInt(cmd.getOptionValue("p", "8"))); } else { rpg.withPasswordLength(Integer.parseInt(cmd.getOptionValue("p", "8"))) .withLowerCaseCharacters(cmd.hasOption("l")).withUpperCaseCharacters(cmd.hasOption("u")) .withDigits(cmd.hasOption("d")).withSymbols(cmd.hasOption("s")) .withAvoidAmbiguousCharacters(cmd.hasOption("a")) .withForceEveryCharacterType(cmd.hasOption("f")); if (cmd.hasOption("lc")) { rpg.withMinLowerCaseCharacterCount(Integer.parseInt(cmd.getOptionValue("lc", "0"))); } if (cmd.hasOption("uc")) { rpg.withMinUpperCaseCharacterCount(Integer.parseInt(cmd.getOptionValue("uc", "0"))); } if (cmd.hasOption("dc")) { rpg.withMinDigitCount(Integer.parseInt(cmd.getOptionValue("dc", "0"))); } if (cmd.hasOption("sc")) { rpg.withMinSymbolCount(Integer.parseInt(cmd.getOptionValue("sc", "0"))); } } Scanner scanner = new Scanner(System.in); try { do { final String password = rpg.generate(); final PasswordMeter.Result result = PasswordMeter.check(password); System.out.printf("%s%nScore: %s%%%nComplexity: %s%n%n", password, result.getScore(), result.getComplexity()); if (cmd.hasOption("c")) { System.out.print("Another? y/N: "); } } while (cmd.hasOption("c") && scanner.nextLine().matches("^(?i:y(?:es)?)$")); } catch (RandomPasswordGeneratorException e) { System.err.println(e.getMessage()); } catch (PasswordMeterException e) { System.err.println(e.getMessage()); } }
From source file:namespace.java
public static void main(String argv[]) { int msgnum = -1; int optind;/*from ww w. j ava 2s . c o m*/ for (optind = 0; optind < argv.length; optind++) { if (argv[optind].equals("-T")) { protocol = argv[++optind]; } else if (argv[optind].equals("-H")) { host = argv[++optind]; } else if (argv[optind].equals("-U")) { user = argv[++optind]; } else if (argv[optind].equals("-P")) { password = argv[++optind]; } else if (argv[optind].equals("-D")) { debug = true; } else if (argv[optind].equals("-L")) { url = argv[++optind]; } else if (argv[optind].equals("-p")) { port = Integer.parseInt(argv[++optind]); } else if (argv[optind].equals("-u")) { suser = argv[++optind]; } else if (argv[optind].equals("--")) { optind++; break; } else if (argv[optind].startsWith("-")) { System.out.println("Usage: namespace [-L url] [-T protocol] [-H host] [-p port] [-U user]"); System.out.println("\t[-P password] [-u other-user] [-D]"); System.exit(1); } else { break; } } try { // Get a Properties object Properties props = System.getProperties(); // Get a Session object Session session = Session.getInstance(props, null); session.setDebug(debug); // Get a Store object Store store = null; if (url != null) { URLName urln = new URLName(url); store = session.getStore(urln); store.connect(); } else { if (protocol != null) store = session.getStore(protocol); else store = session.getStore(); // Connect if (host != null || user != null || password != null) store.connect(host, port, user, password); else store.connect(); } printFolders("Personal", store.getPersonalNamespaces()); printFolders("User \"" + suser + "\"", store.getUserNamespaces(suser)); printFolders("Shared", store.getSharedNamespaces()); store.close(); } catch (Exception ex) { System.out.println("Oops, got exception! " + ex.getMessage()); ex.printStackTrace(); } System.exit(0); }
From source file:cnxchecker.Server.java
public static void main(String[] args) { Options options = new Options(); options.addOption("p", "port", true, "TCP port to bind to (random by default)"); options.addOption("h", "help", false, "Print help"); CommandLineParser parser = new GnuParser(); try {/* www . ja va 2s . co m*/ CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("server", options); System.exit(0); } int port = 0; if (cmd.hasOption("p")) { try { port = Integer.parseInt(cmd.getOptionValue("p")); } catch (NumberFormatException e) { printAndExit("Invalid port number " + cmd.getOptionValue("p")); } if (port < 0 || port > 65535) { printAndExit("Invalid port number " + port); } } Server server = new Server(port); server.doit(); } catch (ParseException e) { printAndExit("Failed to parse options: " + e.getMessage()); } }
From source file:net.forkwait.imageautomator.ImageAutomator.java
public static void main(String[] args) throws IOException { String inputImage = ""; Options options = new Options(); options.addOption("o", true, "output file name (e.g. thumb.jpg), default thumbnail.filename.ext"); options.addOption("q", true, "jpeg quality (e.g. 0.9, max 1.0), default 0.97"); options.addOption("s", true, "output max side length in px (e.g. 800), default 1200"); options.addOption("w", true, "watermark image file"); options.addOption("wt", true, "watermark transparency (e.g. 0.5, max 1.0), default 1.0"); options.addOption("wp", true, "watermark position (e.g. 0.9, max 1.0), default BOTTOM_RIGHT"); /*/*from ww w . ja va2s . c o m*/ TOP_LEFT TOP_CENTER TOP_RIGHT CENTER_LEFT CENTER CENTER_RIGHT BOTTOM_LEFT BOTTOM_CENTER BOTTOM_RIGHT */ CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.getArgs().length < 1) { throw new ParseException("Too few arguments"); } else if (cmd.getArgs().length > 1) { throw new ParseException("Too many arguments"); } inputImage = cmd.getArgs()[0]; } catch (ParseException e) { showHelp(options, e.getLocalizedMessage()); System.exit(-1); } Thumbnails.Builder<File> st = Thumbnails.of(inputImage); if (cmd.hasOption("q")) { st.outputQuality(Double.parseDouble(cmd.getOptionValue("q"))); } else { st.outputQuality(0.97f); } if (cmd.hasOption("s")) { st.size(Integer.parseInt(cmd.getOptionValue("s")), Integer.parseInt(cmd.getOptionValue("s"))); } else { st.size(1200, 1200); } if (cmd.hasOption("w")) { Positions position = Positions.BOTTOM_RIGHT; float trans = 0.5f; if (cmd.hasOption("wp")) { position = Positions.valueOf(cmd.getOptionValue("wp")); } if (cmd.hasOption("wt")) { trans = Float.parseFloat(cmd.getOptionValue("wt")); } st.watermark(position, ImageIO.read(new File(cmd.getOptionValue("w"))), trans); } if (cmd.hasOption("o")) { st.toFile(new File(cmd.getOptionValue("o"))); } else { st.toFiles(Rename.PREFIX_DOT_THUMBNAIL); } //.outputFormat("jpg") System.exit(0); }
From source file:com.github.zk1931.zabkv.Main.java
public static void main(String[] args) throws Exception { // Options for command arguments. Options options = new Options(); Option port = OptionBuilder.withArgName("port").hasArg(true).isRequired(true).withDescription("port number") .create("port"); Option ip = OptionBuilder.withArgName("ip").hasArg(true).isRequired(true) .withDescription("current ip address").create("ip"); Option join = OptionBuilder.withArgName("join").hasArg(true).withDescription("the addr of server to join.") .create("join"); Option help = OptionBuilder.withArgName("h").hasArg(false).withLongOpt("help") .withDescription("print out usages.").create("h"); options.addOption(port).addOption(ip).addOption(join).addOption(help); CommandLineParser parser = new BasicParser(); CommandLine cmd;/*from w w w .j a v a 2 s. c o m*/ try { cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("zabkv", options); return; } } catch (ParseException exp) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("zabkv", options); return; } int zabPort = Integer.parseInt(cmd.getOptionValue("port")); String myIp = cmd.getOptionValue("ip"); if (zabPort < 5000 && zabPort >= 5010) { System.err.println("port parameter can have value only between 5000 & 5010"); System.exit(1); } int serverPort = zabPort % 5000 + 8000; Database db = new Database(myIp, zabPort, cmd.getOptionValue("join")); Server server = new Server(serverPort); ServletHandler handler = new ServletHandler(); server.setHandler(handler); ServletHolder holder = new ServletHolder(new RequestHandler(db)); handler.addServletWithMapping(holder, "/*"); server.start(); server.join(); System.out.println("hi"); }
From source file:MainClass.java
public static void main(String argv[]) { boolean debug = false;// change to get more errors if (argv.length != 5) { System.out.println("usage: copier <urlname> <src folder>" + "<dest folder> <start msg #> <end msg #>"); return;//from w ww . j a v a2s.c o m } try { URLName url = new URLName(argv[0]); String src = argv[1]; // source folder String dest = argv[2]; // dest folder int start = Integer.parseInt(argv[3]); // copy from message # int end = Integer.parseInt(argv[4]); // to message # // Get the default Session object Session session = Session.getInstance(System.getProperties(), null); // session.setDebug(debug); // Get a Store object that implements // the protocol. Store store = session.getStore(url); store.connect(); System.out.println("Connected..."); // Open Source Folder Folder folder = store.getFolder(src); folder.open(Folder.READ_WRITE); System.out.println("Opened source..."); if (folder.getMessageCount() == 0) { System.out.println("Source folder has no messages .."); folder.close(false); store.close(); } // Open destination folder, create if needed Folder dfolder = store.getFolder(dest); if (!dfolder.exists()) // create dfolder.create(Folder.HOLDS_MESSAGES); Message[] msgs = folder.getMessages(start, end); System.out.println("Got messages..."); // Copy messages into destination, folder.copyMessages(msgs, dfolder); System.out.println("Copied messages..."); // Close the folder and store folder.close(false); store.close(); System.out.println("Closed folder and store..."); } catch (Exception e) { e.printStackTrace(); } System.exit(0); }
From source file:com.kantenkugel.discordbot.Main.java
public static void main(String[] args) { boolean isDbBot = false; if (args.length == 2 && Boolean.parseBoolean(args[1])) { isDbBot = true;/* ww w .jav a 2s.com*/ } else if (args.length < 4) { System.out.println("Missing arguments!"); return; } if (!BotConfig.load()) { System.out.println("Bot config created/updated. Please populate/check it before restarting the Bot"); System.exit(Statics.NORMAL_EXIT_CODE); } if (BotConfig.get("logToFiles", true)) { try { SimpleLog.addFileLogs(new File("logs/main.txt"), new File("logs/err.txt")); } catch (IOException e) { e.printStackTrace(); } } if (!isDbBot) { Statics.START_TIME = Long.parseLong(args[1]); Statics.VERSION = Integer.parseInt(args[3]); } if (!isDbBot && args.length > 4) { Statics.CHANGES = StringUtils.join(args, '\n', 4, args.length); } else { Statics.CHANGES = null; } if (isDbBot) { if ("".equals(BotConfig.get("historyBase"))) { Statics.LOG.fatal("Please specify a history-base in the config"); System.exit(Statics.NORMAL_EXIT_CODE); } if (!DbEngine.init()) { Statics.LOG.fatal("Could not connect to db! shutting down"); System.exit(Statics.NORMAL_EXIT_CODE); } } else { DocParser.init(); Module.init(); } try { JDABuilder jdaBuilder = new JDABuilder().setBotToken(args[0]).setAudioEnabled(false); if (isDbBot) jdaBuilder.addListener(new DbListener()); else jdaBuilder.addListener(new StatusListener()).addListener(new InviteListener()) .addListener(new MessageListener()); if (!isDbBot && !args[2].equals("-")) { boolean success = Boolean.parseBoolean(args[2]); if (success) { checker = UpdateValidator.getInstance(); checker.start(); } jdaBuilder.addListener(new UpdatePrintListener(success)); } Statics.jdaInstance = jdaBuilder.buildAsync(); if (!isDbBot) CommandRegistry.loadCommands(Statics.jdaInstance); new UpdateWatcher(Statics.jdaInstance); } catch (LoginException e) { Statics.LOG.fatal("Login informations were incorrect!"); System.err.flush(); } }
From source file:edu.scripps.fl.pubchem.app.AssayDownloader.java
public static void main(String[] args) throws Exception { CommandLineHandler clh = new CommandLineHandler() { public void configureOptions(Options options) { options.addOption(OptionBuilder.withLongOpt("data_url").withType("").withValueSeparator('=') .hasArg().create()); options.addOption(/*w ww . j a v a 2 s . c o m*/ OptionBuilder.withLongOpt("days").withType(0).withValueSeparator('=').hasArg().create()); options.addOption(OptionBuilder.withLongOpt("mlpcn").withType(false).create()); options.addOption(OptionBuilder.withLongOpt("notInDb").withType(false).create()); } }; args = clh.handle(args); String data_url = clh.getCommandLine().getOptionValue("data_url"); if (null == data_url) data_url = "ftp://ftp.ncbi.nlm.nih.gov/pubchem/Bioassay/CSV/"; // data_url = "file:///C:/Home/temp/PubChemFTP/"; AssayDownloader main = new AssayDownloader(); main.dataUrl = new URL(data_url); if (clh.getCommandLine().hasOption("days")) main.days = Integer.parseInt(clh.getCommandLine().getOptionValue("days")); if (clh.getCommandLine().hasOption("mlpcn")) main.mlpcn = true; if (clh.getCommandLine().hasOption("notInDb")) main.notInDb = true; if (args.length == 0) main.process(); else { Long[] list = (Long[]) ConvertUtils.convert(args, Long[].class); List<Long> l = (List<Long>) Arrays.asList(list); log.info("AID to process: " + l); main.process(new HashSet<Long>(Arrays.asList(list))); } }
From source file:evalita.q4faq.baseline.Index.java
/** * @param args the command line arguments *//*from ww w.j a va 2 s .c o m*/ public static void main(String[] args) { try { if (args.length > 1) { Reader in = new FileReader(args[0]); IndexWriterConfig config = new IndexWriterConfig(Version.LATEST, new ItalianAnalyzer()); IndexWriter writer = new IndexWriter(FSDirectory.open(new File(args[1])), config); Iterable<CSVRecord> records = CSVFormat.EXCEL.withHeader().withDelimiter(';').parse(in); for (CSVRecord record : records) { int id = Integer.parseInt(record.get("id")); String question = record.get("question"); String answer = record.get("answer"); String tag = record.get("tag"); Document doc = new Document(); doc.add(new StringField("id", String.valueOf(id), Field.Store.YES)); doc.add(new TextField("question", question, Field.Store.NO)); doc.add(new TextField("answer", answer, Field.Store.NO)); doc.add(new TextField("tag", tag.replace(",", " "), Field.Store.NO)); writer.addDocument(doc); } writer.close(); } else { throw new IllegalArgumentException("Number of arguments not valid"); } } catch (IOException | IllegalArgumentException ex) { Logger.getLogger(Index.class.getName()).log(Level.SEVERE, null, ex); } }