List of usage examples for java.util Scanner nextLine
public String nextLine()
From source file:com.test.sharksharding.use.resource.RedisResourceTest.java
public @Test void testInsert() { while (true) { System.out.println("input-->"); Scanner scan = new Scanner(System.in); final String uid = scan.nextLine(); JdbcTemplate jdbcTemlate = GetJdbcTemplate.getJdbcTemplate(); Map<String, Object> params = new HashMap<String, Object>(); params.put("uid", Long.valueOf(uid)); params.put("userName", "gaoxianglong"); final String sql = sqlTemplate.getSql("setUserInfo", params); jdbcTemlate.update(sql);//from ww w . j a va2 s. co m } }
From source file:TextFileTest.java
/** * Reads employee data from a buffered reader * @param in the scanner/*from w ww . java2 s. c o m*/ */ public void readData(Scanner in) { String line = in.nextLine(); String[] tokens = line.split("\\|"); name = tokens[0]; salary = Double.parseDouble(tokens[1]); int y = Integer.parseInt(tokens[2]); int m = Integer.parseInt(tokens[3]); int d = Integer.parseInt(tokens[4]); GregorianCalendar calendar = new GregorianCalendar(y, m - 1, d); hireDay = calendar.getTime(); }
From source file:DataSci.main.JsonRequestResponseController.java
/** * Read the API key and API URL of Azure ML request response REST API * //w ww . j a va2 s . c o m * @param filename fully qualified file name that contains API key and API URL */ public void readApiInfo(String filename) { try { File apiFile = new File(filename); Scanner sc = new Scanner(apiFile); apiurl = sc.nextLine(); apikey = sc.nextLine(); sc.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.wavemaker.spinup.web.VersionProvider.java
public String getVersion(ServletContext servletContext) throws IOException { String uploadDirName = servletContext.getRealPath(SpinupConstants.STUDIOD_UPLOAD_DIR); if (studioVersion != null) { return this.studioVersion; }/*from ww w . j av a 2 s. c o m*/ ZipArchive studioZip = new ZipArchive(new LocalFolder(uploadDirName).getFile(SpinupConstants.STUDIO_FILE)); InputStream configjs = studioZip.getFile("app/config.js").getContent().asInputStream(); Scanner s = new Scanner(configjs); while (s.hasNext()) { String ln = s.nextLine(); if (ln.contains("studioVersion:")) { this.studioVersion = ln.substring(ln.indexOf(":") + 1).replace(",", "").replace("'", "").trim(); break; } } if (log.isInfoEnabled()) { log.info("*** Studio version is: " + this.studioVersion + "***"); } configjs.close(); return this.studioVersion; }
From source file:me.mast3rplan.phantombot.HTTPResponse.java
HTTPResponse(String address, String request) throws IOException { Socket sock = new Socket(address, 80); Writer output = new StringWriter(); IOUtils.write(request, sock.getOutputStream(), "utf-8"); IOUtils.copy(sock.getInputStream(), output); com.gmt2001.Console.out.println(output.toString()); Scanner scan = new Scanner(sock.getInputStream()); String errorLine = scan.nextLine(); for (String line = scan.nextLine(); !line.equals(""); line = scan.nextLine()) { String[] keyval = line.split(":", 2); if (keyval.length == 2) { values.put(keyval[0], keyval[1].trim()); } else {//from w ww. j a v a2 s . com //? } } while (scan.hasNextLine()) { body += scan.nextLine(); } sock.close(); }
From source file:com.kscs.server.web.source.JavaSourceCode.java
public String readfile(String filename) { File file = new File("/home/sinhlk/myspace/tool/src/main/resources/" + filename); StringBuilder result = new StringBuilder(""); try {// w w w . java 2s. c o m Scanner scanner = new Scanner(file); while (scanner.hasNextLine()) { String line = scanner.nextLine(); result.append(line).append("\n"); } scanner.close(); } catch (IOException e) { e.printStackTrace(); } String sourceFile = result.toString(); return sourceFile; }
From source file:hu.sztaki.incremental.ml.streaming.imsr.MatrixVectorPairSource.java
@Override public void invoke(Collector<Tuple2<double[][], double[][]>> out) throws Exception { File f = new File(path); if (!f.exists()) { System.err.println(path + " does not exist."); System.exit(1);//w ww . ja va 2 s . co m } Scanner s = initCsvScanner(new Scanner(f)); String firstLine = s.nextLine(); Scanner firstLineScanner = initCsvScanner(new Scanner(firstLine)); for (indepDim = 0; firstLineScanner.hasNext(); firstLineScanner.next(), indepDim++) ; indepDim--; while (s.hasNext()) { Array2DRowRealMatrix X = new Array2DRowRealMatrix(batchSize, indepDim); Array2DRowRealMatrix y = new Array2DRowRealMatrix(batchSize, 1); readMatricesSideBySide(s, X, y); out.collect(new Tuple2<double[][], double[][]>(X.getDataRef(), y.getDataRef())); } s.close(); out.close(); }
From source file:com.chargebee.CSV.PhoneBook.PhoneBook2.PhoneBook.java
private void display(HashMap<String, ArrayList> map) { Scanner sc = new Scanner(System.in); System.out.println("Search by : name/number?"); String choice = sc.nextLine(); System.out.println("Enter the " + choice + " : "); String param = sc.nextLine(); if (choice.toLowerCase().equalsIgnoreCase("name")) { for (String key : map.keySet()) { if (key.toLowerCase().contains(param)) { ArrayList<Person> tempo = new ArrayList(); tempo = map.get(key);/*from w ww .j a v a2 s. c o m*/ for (Person p : tempo) { p.print(); } } } } else if (choice.toLowerCase().equalsIgnoreCase("number")) { for (Map.Entry<String, ArrayList> entry : map.entrySet()) { ArrayList<Person> tempo = new ArrayList(); tempo = entry.getValue(); for (Person p : tempo) { if (p.getPhone().getHomeNumber().equalsIgnoreCase(param) || p.getPhone().getMobileNumber().equalsIgnoreCase(param) || p.getPhone().getWorkNumber().equalsIgnoreCase(param)) { p.print(); break; } System.out.println("Phone Number not found!!"); } } } else { System.out.println("Invalid Choice!!"); } }
From source file:com.nextdoor.bender.Bender.java
protected static void invokeKinesisHandler(String stream_name, String source_file) throws HandlerException { String sourceArn = "arn:aws:kinesis:" + AWS_REGION + ":" + AWS_ACCOUNT + ":stream/" + stream_name; logger.info("Invoking the Kinesis Handler..."); TestContext ctx = getContext();/*from www. ja v a2s. co m*/ KinesisHandler handler = new KinesisHandler(); /* * Set the arrival timestamp as the function run time. */ Date approximateArrivalTimestamp = new Date(); approximateArrivalTimestamp.setTime(System.currentTimeMillis()); /* * Open up the source file for events */ Scanner scan = null; try { scan = new Scanner(new File(source_file)); } catch (FileNotFoundException e) { logger.error("Could not find source file (" + source_file + "): " + e); System.exit(1); } /* * Create a series of KinesisEvents from the source file. All of these events will be treated as * a single batch that was pushed to Kinesis, so they will all have the same Arrival Time. */ logger.info("Parsing " + source_file + "..."); List<KinesisEvent.KinesisEventRecord> events = new ArrayList<KinesisEvent.KinesisEventRecord>(); int r = 0; /* * Walk through the source file. For each line in the file, turn the line into a KinesisRecord. */ while (scan.hasNextLine()) { String line = scan.nextLine(); Record rec = new Record(); rec.withPartitionKey("1").withSequenceNumber(r + "").withData(ByteBuffer.wrap(line.getBytes())) .withApproximateArrivalTimestamp(approximateArrivalTimestamp); KinesisEventRecord krecord = new KinesisEventRecord(); krecord.setKinesis(rec); krecord.setEventSourceARN(sourceArn); krecord.setEventID("shardId-000000000000:" + UUID.randomUUID()); events.add(krecord); r += 1; } logger.info("Read " + r + " records"); /* * Create the main Kinesis Event object - this holds all of the data and records that will be * passed into the Kinesis Handler. */ KinesisEvent kevent = new KinesisEvent(); kevent.setRecords(events); /* * Invoke handler */ handler.handler(kevent, ctx); handler.shutdown(); }
From source file:edu.emory.bmi.medicurator.tcia.TciaQuery.java
public String getResult() { try {/*from w w w .ja v a2 s.c o m*/ HttpGet request = new HttpGet(getQuery()); HttpClient client = getInsecureClient(); HttpResponse response = client.execute(request); HttpEntity entity = response.getEntity(); Scanner s = new Scanner(entity.getContent()); String str = s.nextLine(); System.out.println(str); return str; } catch (Exception e) { System.out.println("[ERROR] when excute TCIA TESTful API " + getQuery() + " -- " + e); return ""; } }