List of usage examples for java.util Scanner nextLine
public String nextLine()
From source file:com.team3637.service.ScheduleServiceMySQLImpl.java
@Override public void initDB(String initScript) { String script = ""; try {/*from w w w .j ava 2 s. co m*/ Scanner sc = new Scanner(new File(initScript)); while (sc.hasNext()) script += sc.nextLine(); } catch (FileNotFoundException e) { e.printStackTrace(); } jdbcTemplateObject.execute(script); }
From source file:com.att.voice.AmazonEchoApi.java
public boolean checkItemId(String itemId) throws IOException { File file = new File("Items.txt"); boolean ret = false; try {// ww w. j ava 2s. c om if (!file.exists()) { file.createNewFile(); } Scanner scanner = new Scanner(file); int lineNum = 0; while (scanner.hasNextLine()) { String line = scanner.nextLine(); lineNum++; if (line.contains(itemId)) { ret = true; } } } catch (Exception e) { ret = false; } return ret; }
From source file:com.joliciel.talismane.en.TalismaneEnglish.java
@Override public TransitionSystem getDefaultTransitionSystem() { TransitionSystem transitionSystem = this.getParserService().getArcEagerTransitionSystem(); InputStream inputStream = getInputStreamFromResource("pennDependencyLabels.txt"); Scanner scanner = new Scanner(inputStream, "UTF-8"); List<String> dependencyLabels = new ArrayList<String>(); while (scanner.hasNextLine()) { String dependencyLabel = scanner.nextLine(); if (!dependencyLabel.startsWith("#")) { if (dependencyLabel.indexOf('\t') > 0) dependencyLabel = dependencyLabel.substring(0, dependencyLabel.indexOf('\t')); dependencyLabels.add(dependencyLabel); }/*from w w w .j a v a2s .com*/ } transitionSystem.setDependencyLabels(dependencyLabels); return transitionSystem; }
From source file:com.joliciel.talismane.machineLearning.TextFileMultivaluedResource.java
public TextFileMultivaluedResource(File file) { try {//from w w w. java2 s.c o m this.name = file.getName(); Scanner scanner = new Scanner(file); int numParts = -1; int i = 1; while (scanner.hasNextLine()) { String line = scanner.nextLine(); if (line.length() > 0 && !line.startsWith("#")) { StringBuilder sb = new StringBuilder(); String[] parts = line.split("\t"); if (parts.length == 1 && line.startsWith("Name: ")) { this.name = line.substring("Name: ".length()); i++; continue; } if (parts.length == 1 && line.startsWith("Multivalued: ")) { boolean multivalued = line.substring("Multivalued: ".length()).equalsIgnoreCase("true"); if (!multivalued) throw new JolicielException("Expected multivalued resource"); i++; continue; } if (numParts < 0) numParts = parts.length; if (parts.length != numParts) throw new JolicielException( "Wrong number of elements on line " + i + " in file: " + file.getName()); for (int j = 0; j < numParts - 2; j++) { sb.append(parts[j]); sb.append("|"); } String key = sb.toString(); List<WeightedOutcome<String>> resultList = resultsMap.get(key); if (resultList == null) { resultList = new ArrayList<WeightedOutcome<String>>(1); resultsMap.put(key, resultList); } String outcome = parts[numParts - 2]; double weight = Double.parseDouble(parts[numParts - 1]); resultList.add(new WeightedOutcome<String>(outcome, weight)); } i++; } } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }
From source file:hu.sztaki.incremental.ml.streaming.imsr.MatrixVectorPairSource.java
private void readMatricesSideBySide(Scanner scanner, RealMatrix... matrices) { for (int i = 0; i < matrices[0].getRowDimension(); i++) { if (!scanner.hasNextLine()) { return; //there will be some 0 rows }/* w w w . j a v a 2 s .c om*/ String line = scanner.nextLine(); Scanner lineScanner = initCsvScanner(new Scanner(line)); for (RealMatrix m : matrices) { for (int j = 0; j < m.getColumnDimension(); j++) { double d = lineScanner.nextDouble(); m.setEntry(i, j, d); } } lineScanner.close(); } }
From source file:org.eclipse.hono.example.ExampleSender.java
/** * Reads user input from the console and sends it to the Hono server. *//*w w w . j a v a2 s . co m*/ @EventListener(classes = { ApplicationReadyEvent.class }) public void readMessagesFromStdin() { Runnable reader = new Runnable() { public void run() { try { // give Spring Boot some time to log its startup messages Thread.sleep(50); } catch (InterruptedException e) { } LOG.info("sender for tenant [{}] created successfully", tenantId); LOG.info("Enter some message(s) (hit return to send, ctrl-c to quit)"); String input; Scanner scanner = new Scanner(System.in); do { input = scanner.nextLine(); final String msg = input; if (!msg.isEmpty()) { final Map<String, Object> properties = new HashMap<>(); properties.put("my_prop_string", "I'm a string"); properties.put("my_prop_int", 10); final CountDownLatch latch = new CountDownLatch(1); Future<Boolean> sendTracker = Future.future(); sendTracker.setHandler(s -> { if (s.failed()) { LOG.info(s.cause().getMessage()); } }); getRegistrationAssertion().compose(token -> { return send(msg, properties, token); }).compose(sent -> { latch.countDown(); sendTracker.complete(); }, sendTracker); try { if (!latch.await(2, TimeUnit.SECONDS)) { sendTracker.fail("cannot connect to server"); } } catch (InterruptedException e) { // nothing to do } } } while (!input.isEmpty()); scanner.close(); }; }; new Thread(reader).start(); }
From source file:com.btobits.automator.fix.utils.FileMessageFactory.java
public void loadInternal(ITcpProccesor inProcessor, int repeatDelay, String nameClient, int inTimeOut) throws Exception { try {//from ww w. j a va 2 s . c o m Scanner scanner = new Scanner(new FileInputStream(file)); //scanner.useDelimiter(delimeter); while (scanner.hasNextLine()) { final String line = scanner.nextLine(); inProcessor.sendMessage(new ITcpMessage() { public byte[] toRawMessage() { return line.getBytes(); } public String getMessageAsString() { return line; } }, inTimeOut); inProcessor.log(line, false); if (repeatDelay > 0) { try { Thread.sleep(repeatDelay); } catch (Exception e) { } } } } catch (SocketException ex) { throw new BuildException(ex.getMessage()); } catch (Exception ex) { throw new Exception("Error send data from file, error: " + ex.getMessage(), ex); } }
From source file:com.grayfox.server.Program.java
public void run(ApplicationContext applicationContext, Scanner input) { PoiService poiService = applicationContext.getBean(PoiService.class); programmLoop: while (true) { System.out.println(Messages.get("program.usage")); String[] arguments = input.nextLine().split(" "); switch (arguments[0]) { case "add": String[] locationStrs = arguments[1].split(";"); Location[] locations = new Location[locationStrs.length]; for (int i = 0; i < locations.length; i++) locations[i] = Location.parse(locationStrs[i]); poiService.addPois(locations); System.out.println(Messages.get("program.op.ok")); break; case "update": if (arguments.length == 2) { switch (arguments[1]) { case "pois": poiService.updatePois(); System.out.println(Messages.get("program.op.ok")); break; case "categories": poiService.updateCategories(); System.out.println(Messages.get("program.op.ok")); break; case "all": poiService.updateAll(); System.out.println(Messages.get("program.op.ok")); break; default: System.out.println(Messages.get("program.invalid.option")); break; }/*from w w w . j a va 2 s . c o m*/ } else System.out.println(Messages.get("program.invalid.option")); break; case "delete": if (arguments.length == 2) { switch (arguments[1]) { case "pois": poiService.deletePois(); System.out.println(Messages.get("program.op.ok")); break; case "categories": poiService.deleteCategories(); System.out.println(Messages.get("program.op.ok")); break; case "all": poiService.deleteAll(); System.out.println(Messages.get("program.op.ok")); break; default: System.out.println(Messages.get("program.invalid.option")); break; } } else System.out.println(Messages.get("program.invalid.option")); break; case "quit": System.out.println(Messages.get("program.finish")); break programmLoop; default: System.out.println(Messages.get("program.invalid.option")); break; } } }
From source file:com.mapr.db.utils.ImportCSV.java
public void readSchema(String path) { String schemaLine = ""; StringTokenizer st;/*from w ww. j a va2s. com*/ String column = "", datatype = ""; countColumnsInSchema = 0; try { Scanner scan = new Scanner(new FileReader(path)); while (scan.hasNextLine()) { schemaLine = scan.nextLine().trim(); if (schemaLine.startsWith("#")) continue; st = new StringTokenizer(schemaLine, " "); while (st.hasMoreTokens()) { column = st.nextToken(); datatype = st.nextToken(); valueTypesInSchema.add(countColumnsInSchema, datatype); columnNamesInSchema.add(countColumnsInSchema, column); } countColumnsInSchema++; } scan.close(); } catch (Exception e) { System.out.println("Error reading schema: " + schemaLine + "\n(Column Name:" + column + "\tData type:" + datatype + ")"); e.printStackTrace(); System.exit(-1); } }
From source file:com.intel.hadoop.graphbuilder.demoapps.wikipedia.docwordgraph.WordCountGraphTokenizer.java
private void loadDictionary(String path) throws IOException { FileStatus[] stats = fs.listStatus(new Path(path)); dictionary = new HashSet<String>(); for (FileStatus stat : stats) { LOG.debug(("Load dictionary: " + stat.getPath().getName())); Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(fs.open(stat.getPath())))); while (sc.hasNextLine()) { String line = sc.nextLine(); dictionary.add(line);/*from www . j a v a2 s. c o m*/ } } }