List of usage examples for java.util Scanner hasNext
public boolean hasNext()
From source file:com.intel.cosbench.driver.handler.TriggerHandler.java
private String getTrigger(Scanner scanner) { if (!scanner.hasNext()) LOGGER.error("bad request exception"); String trigger = scanner.next(); if (trigger == null) LOGGER.error("no found exception"); return trigger; }
From source file:ch.cyberduck.core.importer.TotalCommanderBookmarkCollection.java
@Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try {/*from ww w . j a v a 2 s . c om*/ final BufferedReader in = new BufferedReader( new InputStreamReader(file.getInputStream(), Charset.forName("UTF-8"))); try { Host current = null; String line; while ((line = in.readLine()) != null) { if (line.startsWith("[")) { if (current != null) { this.add(current); } current = new Host(protocols.forScheme(Scheme.ftp)); current.getCredentials() .setUsername(PreferencesFactory.get().getProperty("connection.login.anon.name")); Pattern pattern = Pattern.compile("\\[(.*)\\]"); Matcher matcher = pattern.matcher(line); if (matcher.matches()) { current.setNickname(matcher.group(1)); } } else { if (null == current) { log.warn("Failed to detect start of bookmark"); continue; } final Scanner scanner = new Scanner(line); scanner.useDelimiter("="); if (!scanner.hasNext()) { log.warn("Missing key in line:" + line); continue; } final String name = scanner.next().toLowerCase(Locale.ROOT); if (!scanner.hasNext()) { log.warn("Missing value in line:" + line); continue; } final String value = scanner.next(); if ("host".equals(name)) { current.setHostname(value); } else if ("directory".equals(name)) { current.setDefaultPath(value); } else if ("username".equals(name)) { current.getCredentials().setUsername(value); } else { log.warn(String.format("Ignore property %s", name)); } } } if (current != null) { this.add(current); } } finally { IOUtils.closeQuietly(in); } } catch (IOException e) { throw new AccessDeniedException(e.getMessage(), e); } }
From source file:csns.importer.parser.MFTScoreParser.java
public void parse(MFTScoreImporter importer) { Department department = importer.getDepartment(); Date date = importer.getDate(); Scanner scanner = new Scanner(importer.getText()); scanner.useDelimiter("\\s+|\\r\\n|\\r|\\n"); while (scanner.hasNext()) { // last name String lastName = scanner.next(); while (!lastName.endsWith(",")) lastName += " " + scanner.next(); lastName = lastName.substring(0, lastName.length() - 1); // first name String firstName = scanner.next(); // score/*from w w w .ja v a 2 s .c o m*/ Stack<String> stack = new Stack<String>(); String s = scanner.next(); while (!isScore(s)) { stack.push(s); s = scanner.next(); } int value = Integer.parseInt(s); // authorization code stack.pop(); // cin String cin = null; if (!stack.empty() && isCin(stack.peek())) cin = stack.pop(); // user User user = null; if (cin != null) user = userDao.getUserByCin(cin); else { List<User> users = userDao.getUsers(lastName, firstName); if (users.size() == 1) user = users.get(0); } if (user != null) { MFTScore score = mftScoreDao.getScore(department, date, user); if (score == null) { score = new MFTScore(); score.setDepartment(department); score.setDate(date); score.setUser(user); } else { logger.info(user.getId() + ": " + score.getValue() + " => " + value); } score.setValue(value); importer.getScores().add(score); } else { User failedUser = new User(); failedUser.setLastName(lastName); failedUser.setFirstName(firstName); failedUser.setCin(cin); importer.getFailedUsers().add(failedUser); } logger.debug(lastName + "," + firstName + "," + cin + "," + value); } scanner.close(); }
From source file:org.apache.uima.ruta.resource.CSVTable.java
private void buildTable(InputStream stream) { Scanner sc = new Scanner(stream, Charset.forName("UTF-8").name()); sc.useDelimiter("\\n"); tableData = new ArrayList<List<String>>(); while (sc.hasNext()) { String line = sc.next().trim(); line = line.replaceAll(";;", "; ;"); String[] lineElements = line.split(";"); List<String> row = Arrays.asList(lineElements); tableData.add(row);/*from w w w . j a v a2 s . c om*/ } sc.close(); }
From source file:org.apache.nutch.indexer.html.HtmlIndexingFilter.java
private NutchDocument addRawContent(NutchDocument doc, WebPage page, String url) { ByteBuffer raw = page.getContent(); if (raw != null) { if (LOG.isInfoEnabled()) { LOG.info("Html indexing for: " + url.toString()); }//w w w. j a v a2 s .c om ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(raw.array(), raw.arrayOffset() + raw.position(), raw.remaining()); Scanner scanner = new Scanner(arrayInputStream); scanner.useDelimiter("\\Z");//To read all scanner content in one String String data = ""; if (scanner.hasNext()) { data = scanner.next(); } doc.add("rawcontent", StringUtil.cleanField(data)); } return doc; }
From source file:ch.cyberduck.core.importer.WsFtpBookmarkCollection.java
private boolean parse(final ProtocolFactory protocols, final Host current, final String line) { final Scanner scanner = new Scanner(line); scanner.useDelimiter("="); if (!scanner.hasNext()) { log.warn("Missing key in line:" + line); return false; }/*from ww w.j a v a 2 s.co m*/ String name = scanner.next().toLowerCase(Locale.ROOT); if (!scanner.hasNext()) { log.warn("Missing value in line:" + line); return false; } String value = scanner.next().replaceAll("\"", StringUtils.EMPTY); if ("conntype".equals(name)) { try { switch (Integer.parseInt(value)) { case 4: current.setProtocol(protocols.forScheme(Scheme.sftp)); break; case 5: current.setProtocol(protocols.forScheme(Scheme.ftps)); break; } // Reset port to default current.setPort(-1); } catch (NumberFormatException e) { log.warn("Unknown Protocol:" + e.getMessage()); } } else if ("host".equals(name)) { current.setHostname(value); } else if ("port".equals(name)) { try { current.setPort(Integer.parseInt(value)); } catch (NumberFormatException e) { log.warn("Invalid Port:" + e.getMessage()); } } else if ("dir".equals(name)) { current.setDefaultPath(value); } else if ("comment".equals(name)) { current.setComment(value); } else if ("uid".equals(name)) { current.getCredentials().setUsername(value); } return true; }
From source file:EntityToD2RHelpers.java
public EntityToD2RHelpers(String uri, String config_file, List<String> people, List<String> places, PrintWriter out) throws Exception { // In this example, I am assuming that the D2R server is running on localhost:2020 //out.println("PREFIX vocab: <http://localhost:2020/vocab/resource/>"); List<String> lines = (List<String>) FileUtils.readLines(new File(config_file)); String d2r_host_and_port = lines.remove(0); String[] info = d2r_host_and_port.split(" "); System.out.println("D2R host = |" + info[0] + "| and port = |" + info[1] + "|"); for (String line : lines) { Scanner scanner = new Scanner(line); scanner.useDelimiter(" "); String d2r_type = scanner.next(); System.out.println("* d2r_type = " + d2r_type); while (scanner.hasNext()) { String term = scanner.next(); String[] property_and_entity_type = term.split("/"); System.out.println(" property: " + property_and_entity_type[0] + " entity type: " + property_and_entity_type[1]); if (property_and_entity_type[1].equals("person")) { for (String person : people) { // perform SPARQL queries to D2R server: String sparql = "PREFIX vocab: <http://localhost:2020/vocab/resource/>\n" + "SELECT ?subject ?name WHERE {\n" + " ?subject " + property_and_entity_type[0] + " ?name \n" + " FILTER regex(?name, \"" + person + "\") .\n" + "}\n" + "LIMIT 10\n"; SparqlClient test = new SparqlClient("http://localhost:2020/sparql", sparql); for (Map<String, String> bindings : test.variableBindings()) { System.out.print("D2R result:" + bindings); if (bindings.keySet().size() > 0) { String blank_node = blankNodeURI("person"); out.println(blank_node + " <http://knowledgebooks.com/rdf/personName> \"" + person.replaceAll("\"", "'") + "\" ."); out.println("<" + uri + "> <http://knowledgebooks.com/rdf/containsPerson> " + blank_node + " ."); out.println(blank_node + " <http://knowledgebooks.com/rdf/d2r_uri> \"" + bindings.get("subject") + "\" ."); }//from w ww . j a va2 s. c om } } } else if (property_and_entity_type[1].equals("place")) { for (String place : places) { // perform SPARQL queries to D2R server: String sparql = "PREFIX vocab: <http://localhost:2020/vocab/resource/>\n" + "SELECT ?subject ?name WHERE {\n" + " ?subject " + property_and_entity_type[0] + " ?name \n" + " FILTER regex(?name, \"" + place + "\") .\n" + "}\n" + "LIMIT 10\n"; SparqlClient test = new SparqlClient("http://localhost:2020/sparql", sparql); for (Map<String, String> bindings : test.variableBindings()) { System.out.print("D2R result:" + bindings); if (bindings.keySet().size() > 0) { String blank_node = blankNodeURI("place"); out.println(blank_node + " <http://knowledgebooks.com/rdf/placeName> \"" + place.replaceAll("\"", "'") + "\" ."); out.println("<" + uri + "> <http://knowledgebooks.com/rdf/containsPlace> " + blank_node + " ."); out.println(blank_node + " <http://knowledgebooks.com/rdf/d2r_uri> \"" + bindings.get("subject") + "\" ."); } } } } } } out.close(); }
From source file:com.liferay.arquillian.container.LiferayContainer.java
private String getBodyAsString(HttpResponse response) throws IOException { HttpEntity responseEntity = response.getEntity(); InputStream content = responseEntity.getContent(); Header contentEncoding = responseEntity.getContentEncoding(); String encoding = contentEncoding != null ? contentEncoding.getValue() : "ISO-8859-1"; Scanner scanner = new Scanner(content, encoding).useDelimiter("\\A"); return scanner.hasNext() ? scanner.next() : ""; }
From source file:org.opendaylight.usecpluginaaa.impl.ParsingLog.java
public void callData() { workingDir = System.getProperty("user.dir"); String fileName = workingDir + File.separator + "data" + File.separator + "log" + File.separator + "karaf.log"; WatchedDir = workingDir + File.separator + "data" + File.separator + "log"; try {//from w w w . j av a 2s. c o m LOG.info("log enabled ..."); Thread.sleep(10000); infile = new File(theNewestFile.toString()); LOG.info("karaf file ..." + theNewestFile); Thread.sleep(1000); LOG.info("parsing karaf file ..."); Thread.sleep(9000); Scanner scanner = new Scanner(infile); while (scanner.hasNext()) { line = scanner.nextLine(); if (line.contains("DEBUG") && line.contains("from")) { String phrase1 = line; String delims = "[,]+"; String[] tokens = phrase1.split(delims); String phrase2 = line; String delims2 = "[|]+"; String[] tokens2 = phrase2.split(delims2); time = tokens[0]; attempt = tokens2[5]; String phrase3 = line; String[] parts = phrase3.split(" "); srcIP = parts[parts.length - 1]; usecpluginAAAstore.addData(time, srcIP, attempt); LOG.info("Information stored in datastore is" + time + " " + srcIP + " " + attempt); } } PublishNotif publishNotif = new PublishNotif(); publishNotif.setdataBroker(dataBroker); publishNotif.Notify(); } catch (Exception e) { e.printStackTrace(); } }
From source file:ch.cyberduck.core.importer.WinScpBookmarkCollection.java
@Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try {//www . j a va 2s .c om final BufferedReader in = new BufferedReader( new InputStreamReader(file.getInputStream(), Charset.forName("UTF-8"))); try { Host current = null; String line; while ((line = in.readLine()) != null) { if (line.startsWith("[Sessions\\")) { current = new Host(protocols.forScheme(Scheme.sftp)); current.getCredentials() .setUsername(PreferencesFactory.get().getProperty("connection.login.anon.name")); Pattern pattern = Pattern.compile("\\[Session\\\\(.*)\\]"); Matcher matcher = pattern.matcher(line); if (matcher.matches()) { current.setNickname(matcher.group(1)); } } else if (StringUtils.isBlank(line)) { this.add(current); current = null; } else { if (null == current) { log.warn("Failed to detect start of bookmark"); continue; } Scanner scanner = new Scanner(line); scanner.useDelimiter("="); if (!scanner.hasNext()) { log.warn("Missing key in line:" + line); continue; } String name = scanner.next().toLowerCase(Locale.ROOT); if (!scanner.hasNext()) { log.warn("Missing value in line:" + line); continue; } String value = scanner.next(); if ("hostname".equals(name)) { current.setHostname(value); } else if ("username".equals(name)) { current.getCredentials().setUsername(value); } else if ("portnumber".equals(name)) { try { current.setPort(Integer.parseInt(value)); } catch (NumberFormatException e) { log.warn("Invalid Port:" + e.getMessage()); } } else if ("fsprotocol".equals(name)) { try { switch (Integer.parseInt(value)) { case 0: case 1: case 2: current.setProtocol(protocols.forScheme(Scheme.sftp)); break; case 5: current.setProtocol(protocols.forScheme(Scheme.ftp)); break; } // Reset port to default current.setPort(-1); } catch (NumberFormatException e) { log.warn("Unknown Protocol:" + e.getMessage()); } } } } } finally { IOUtils.closeQuietly(in); } } catch (IOException e) { throw new AccessDeniedException(e.getMessage(), e); } }