List of usage examples for java.util Scanner Scanner
public Scanner(ReadableByteChannel source)
From source file:com.github.xbn.examples.lang.non_xbn.VerifyUserInputIsANumberWithIsNumber.java
public static final void main(String[] ignored) { int num = -1; boolean isNum = false; do {//from w w w . j ava 2 s . com System.out.print("Number please: "); String strInput = (new Scanner(System.in)).next(); if (!NumberUtils.isNumber(strInput)) { System.out.println(strInput + " is not a number. Try again."); } else { //Safe to convert num = Integer.parseInt(strInput); isNum = true; } } while (!isNum); System.out.println("Number: " + num); }
From source file:ScanXan.java
public static void main(String[] args) throws IOException { Scanner s = null;//from w ww.j a v a 2s . com try { s = new Scanner(new BufferedReader(new FileReader("xanadu.txt"))); while (s.hasNext()) { System.out.println(s.next()); } } finally { if (s != null) { s.close(); } } }
From source file:bundestagswahl.benchmark.BWBenchmark.java
public static void main(String[] args) throws Exception { resultTime = new double[6]; Scanner scanner = new Scanner(System.in); System.out.print("Please enter URL: "); serverUrl = scanner.nextLine();//w w w .ja v a 2 s .c om System.out.print("Please enter number of terminals: "); numberTerminals = scanner.nextInt(); System.out.print("Please enter number of requests: "); numberRequests = scanner.nextInt(); System.out.print("Please enter delay between two requests in seconds: "); requestDelay = scanner.nextDouble(); scanner.close(); PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); cm.setMaxTotal(numberTerminals); HttpClient httpclient = new DefaultHttpClient(cm); httpclient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 300000) .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 300000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); try { final CountDownLatch latch = new CountDownLatch(numberTerminals); for (int i = 0; i < numberTerminals; i++) { BenchmarkTerminal terminal = new BenchmarkTerminal(httpclient, latch, serverUrl, numberRequests, requestDelay); terminal.start(); } latch.await(); httpclient.getConnectionManager().shutdown(); } finally { } printResultTimes(); System.out.println(" "); System.out.println("Done"); }
From source file:com.frederikam.fredboat.bootloader.Bootloader.java
public static void main(String[] args) throws IOException, InterruptedException { OUTER: while (true) { InputStream is = new FileInputStream(new File("./bootloader.json")); Scanner scanner = new Scanner(is); JSONObject json = new JSONObject(scanner.useDelimiter("\\A").next()); scanner.close();//from ww w . ja va2 s . c om command = json.getJSONArray("command"); jarName = json.getString("jarName"); Process process = boot(); process.waitFor(); System.out.println("[BOOTLOADER] Bot exited with code " + process.exitValue()); switch (process.exitValue()) { case ExitCodes.EXIT_CODE_UPDATE: System.out.println("[BOOTLOADER] Now updating..."); update(); break; case 130: case ExitCodes.EXIT_CODE_NORMAL: System.out.println("[BOOTLOADER] Now shutting down..."); break OUTER; //SIGINT received or clean exit default: System.out.println("[BOOTLOADER] Now restarting.."); break; } } }
From source file:com.balero.test.Wizard.java
public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("" + ".-. .-') ('-. ('-. _ .-') _ .-') .-') \n" + "\\ ( OO ) ( OO ).-. _( OO)( \\( -O ) ( '.( OO )_ ( OO ). \n" + " ;-----.\\ / . --. / ,--. (,------.,------. .-'),-----. .-----. ,--. ,--.)(_)---\\_) \n" + " | .-. | | \\-. \\ | |.-') | .---'| /`. '( OO' .-. ' ' .--./ | `.' | / _ | \n" + " | '-' /_).-'-' | | | | OO ) | | | / | |/ | | | | | |('-. | | \\ :` `. \n" + " | .-. `. \\| |_.' | | |`-' |(| '--. | |_.' |\\_) | |\\| | /_) |OO )| |'.'| | '..`''.) \n" + " | | \\ | | .-. |(| '---.' | .--' | . '.' \\ | | | | || |`-'| | | | | .-._) \\ \n" + " | '--' / | | | | | | | `---.| |\\ \\ `' '-' ' (_' '--'\\ | | | | \\ / \n" + " `------' `--' `--' `------' `------'`--' '--' `-----' `-----' `--' `--' `-----' \n" + " Enterprise Edition\n"); System.out.println("Welcome to Balero CMS Setup Wizard\n"); System.out.println("Provide your Database configuration.\n"); String dbuser;//from w w w . j a v a2s.co m System.out.print("Insert MySQL Username\n"); dbuser = sc.nextLine(); String dbpass; System.out.print("Insert MySQL Password\n"); dbpass = sc.nextLine(); String opt; System.out.println("The MIT License (MIT)\n" + "\n" + "Copyright (c) 2014 Balero CMS Enterprise Edition.\n" + "\n" + "Permission is hereby granted, free of charge, to any person obtaining a copy\n" + "of this software and associated documentation files (the \"Software\"), to deal\n" + "in the Software without restriction, including without limitation the rights\n" + "to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n" + "copies of the Software, and to permit persons to whom the Software is\n" + "furnished to do so, subject to the following conditions:\n" + "\n" + "The above copyright notice and this permission notice shall be included in\n" + "all copies or substantial portions of the Software.\n" + "\n" + "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n" + "IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n" + "FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n" + "AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n" + "LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n" + "OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n" + "THE SOFTWARE.\n" + "Agree: Enter Decline: e"); opt = sc.nextLine(); exitWizard(opt); System.out.print("Setup wizard will create database tables\n" + "Continue: Enter or Exit: e\n"); opt = sc.nextLine(); exitWizard(opt); try { System.out.println("" + " _( )_ _ Mounting CMS...\n" + " _( )_ _( )_\n" + " (_________) _( )_\n" + " (_________)\n" + " 0 1 0 \n" + " 1 0 0 1 0\n" + " 1 1 0"); ; for (double progressPercentage = 0.0; progressPercentage < 1.0; progressPercentage += 0.01) { updateProgress(progressPercentage); Thread.sleep(100); } } catch (InterruptedException e) { } }
From source file:com.chargebee.Application.DateFormat.java
public static void main(String[] args) throws IOException, Exception { Scanner sc = new Scanner(System.in); System.out.println("Input CSV File: "); String source = sc.nextLine(); System.out.println("Input JSON File: "); String requirements = sc.nextLine(); System.out.println("Output CSV File: "); String output = sc.nextLine(); DateFormat df = new DateFormat(); JSONObject jobj = MethodBank.readJsonObjectData(requirements); CSVParser parser = MethodBank.parserInitializer(source); CSVPrinter printer = MethodBank.printerInitializer(output); df.formatter(parser, printer, jobj); parser.close();//from ww w. j av a 2 s . co m printer.close(); }
From source file:com.thinkbiganalytics.kerberos.TestKerberosKinit.java
public static void main(String[] args) throws Exception { final TestKerberosKinit testKerberosKinit = new TestKerberosKinit(); Scanner scanner = new Scanner(System.in); System.out.println(" "); System.out.print("Which environment are you in? Enter 1 for HDP or 2 for Cloudera: "); String environmentCode = scanner.nextLine(); if (StringUtils.isEmpty(environmentCode)) { environmentCode = "1"; }//w w w .jav a2s. com String environment; switch (environmentCode) { case "1": environment = ENVIRONMENT_HDP; break; case "2": environment = ENVIRONMENT_CLOUDERA; break; default: throw new Exception("Invalid environment code"); } System.out.println(" "); System.out.println( "Hit enter to default to: /etc/hadoop/conf/core-site.xml,/etc/hadoop/conf/hdfs-site.xml,/usr/hdp/current/hive-client/conf/hive-site.xml"); System.out.print("Please enter the list of configuration resources: "); String configResources = scanner.nextLine(); if (StringUtils.isEmpty(configResources)) { configResources = "/etc/hadoop/conf/core-site.xml,/etc/hadoop/conf/hdfs-site.xml,/usr/hdp/current/hive-client/conf/hive-site.xml"; } System.out.println(" "); System.out.println("Hit enter to default to: /etc/security/keytabs/hive-thinkbig.headless.keytab"); System.out.print("Please enter the keytab file location: "); String keytab = scanner.nextLine(); if (StringUtils.isEmpty(keytab)) { keytab = "/etc/security/keytabs/hive-thinkbig.headless.keytab"; } System.out.println(" "); System.out.println("Hit enter to default to: hive/sandbox.hortonworks.com@sandbox.hortonworks.com"); System.out.print("Please enter the real user principal name: "); String realUserPrincipal = scanner.nextLine(); if (StringUtils.isEmpty(realUserPrincipal)) { realUserPrincipal = "hive/sandbox.hortonworks.com@sandbox.hortonworks.com"; } System.out.println(" "); System.out.println("Please enter Y/N (default is N)"); System.out.print("Do you want to test with a proxy user: "); String proxyUser = scanner.nextLine(); if (StringUtils.isEmpty(realUserPrincipal)) { proxyUser = "N"; } System.out.println(" "); System.out.println("Hit enter to default to: hdfs://sandbox.hortonworks.com:8020"); System.out.print("Please enter the HDFS URL: "); String hdfsUrl = scanner.nextLine(); if (StringUtils.isEmpty(hdfsUrl)) { hdfsUrl = "hdfs://sandbox.hortonworks.com:8020"; } System.out.println(" "); System.out.println("Hit enter to default to: jdbc:hive2://localhost:10000/default"); System.out.print("Please enter the Hive base connection string: "); String hiveHost = scanner.nextLine(); if (StringUtils.isEmpty(hiveHost)) { hiveHost = "jdbc:hive2://localhost:10000/default"; } String proxyUserName = null; if ("Y".equalsIgnoreCase(proxyUser)) { System.out.println(" "); System.out.print("Please enter the proxy user: "); proxyUserName = scanner.next(); } System.out.println(" "); System.out.println("Executing Kinit to generate a kerberos ticket"); if ("Y".equalsIgnoreCase(proxyUser)) { System.out.println("Testing with the proxy user: " + proxyUserName); testKerberosKinit.testHdfsWithUserImpersonation(configResources, keytab, realUserPrincipal, proxyUserName, environment, hdfsUrl); //testKerberosKinit.testHiveJdbcConnectionWithUserImpersonation(configResources, keytab, realUserPrincipal, proxyUserName); testKerberosKinit.testHiveJdbcConnection(configResources, keytab, realUserPrincipal, proxyUserName, hiveHost); } else { System.out.println("No Proxy User"); testKerberosKinit.testHdfsAsKerberosUser(configResources, keytab, realUserPrincipal, environment, hdfsUrl); testKerberosKinit.testHiveJdbcConnection(configResources, keytab, realUserPrincipal, null, hiveHost); } }
From source file:drpc.BptiEnsembleQuery.java
public static void main(final String[] args) throws IOException, TException, DRPCExecutionException { if (args.length < 3) { System.err.println("Where are the arguments? args -- DrpcServer DrpcFunctionName folder"); return;/* w w w.j a v a 2s. co m*/ } final DRPCClient client = new DRPCClient(args[0], 3772, 1000000 /*timeout*/); final Queue<String> featureFiles = new ArrayDeque<String>(); SpoutUtils.listFilesForFolder(new File(args[2]), featureFiles); Scanner scanner = new Scanner(featureFiles.peek()); int i = 0; while (scanner.hasNextLine() && i++ < 1) { List<Map<String, List<Double>>> dict = SpoutUtils.pythonDictToJava(scanner.nextLine()); for (Map<String, List<Double>> map : dict) { final Double[] features = map.get("chi1").toArray(new Double[0]); final Double[] moreFeatures = map.get("chi2").toArray(new Double[0]); final Double[] both = (Double[]) ArrayUtils.addAll(features, moreFeatures); final String parameters = serializeFeatureVector(ArrayUtils.toPrimitive(both)); Logger.getAnonymousLogger().log(Level.INFO, runQuery(args[1], parameters, client)); } } client.close(); }
From source file:de.dakror.scpuller.SCPuller.java
public static void main(String[] args) { new File(System.getProperty("user.home") + "/.dakror/SCPuller").mkdirs(); new File(System.getProperty("user.home") + "/.dakror/SCPuller/download").mkdir(); Scanner scanner = new Scanner(System.in); loadDownloadedSongs();// w w w . j a va2s. com try { while (true) { String line = scanner.nextLine().trim(); download(line); saveDownloadedSongs(); } } finally { scanner.close(); } }
From source file:com.haythem.integration.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments//from w w w .ja va 2s . c o m */ public static void main(final String... args) { final Scanner scanner = new Scanner(System.in); System.out.println("\n=========================================================" + "\n " + "\n Welcome to the Spring Integration " + "\n TCP-Client-Server Sample! " + "\n " + "\n For more information please visit: " + "\n http://www.springintegration.org/ " + "\n " + "\n========================================================="); final GenericXmlApplicationContext context = Main.setupContext(); final SimpleGateway gateway = context.getBean(SimpleGateway.class); final AbstractServerConnectionFactory crLfServer = context.getBean(AbstractServerConnectionFactory.class); System.out.print("Waiting for server to accept connections..."); TestingUtilities.waitListening(crLfServer, 10000L); System.out.println("running.\n\n"); System.out.println("Please enter some text and press <enter>: "); System.out.println("\tNote:"); System.out.println("\t- Entering FAIL will create an exception"); System.out.println("\t- Entering q will quit the application"); System.out.print("\n"); System.out.println("\t--> Please also check out the other samples, " + "that are provided as JUnit tests."); System.out.println("\t--> You can also connect to the server on port '" + crLfServer.getPort() + "' using Telnet.\n\n"); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { break; } else { final String result = gateway.send(input); System.out.println(result); } } System.out.println("Exiting application...bye."); System.exit(0); }