List of usage examples for java.util Scanner next
public String next()
From source file:org.grouter.core.readers.FtpReaderJob.java
/** * Parses comma separated string of paths. * * @param pathIncludingFiles a list with comma separated strings, e.g /tmp/kalle.xml,nisse.xml * @return paths// ww w. j av a 2 s . c o m */ private List<String> getPathIncludingFile(String pathIncludingFiles) { List<String> paths = new ArrayList<String>(); Scanner scanner = new Scanner(pathIncludingFiles); try { scanner.useDelimiter(","); while (scanner.hasNext()) { String pathInclFile = scanner.next(); logger.debug(pathInclFile); paths.add(pathInclFile); } } catch (Exception e) { logger.warn(e, e); } finally { scanner.close(); } return paths; }
From source file:ch.cyberduck.core.importer.S3BrowserBookmarkCollection.java
@Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try {//from www.java 2 s . co m 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("[account_")) { current = new Host(protocols.forType(Protocol.Type.s3)); } 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 ("name".equals(name)) { current.setNickname(value); } else if ("comment".equals(name)) { current.setComment(value); } else if ("access_key".equals(name)) { current.getCredentials().setUsername(value); } else if ("secret_key".equals(name)) { current.getCredentials().setPassword(value); } } } } finally { IOUtils.closeQuietly(in); } } catch (IOException e) { throw new AccessDeniedException(e.getMessage(), e); } }
From source file:csns.importer.parser.csula.RosterParserImpl.java
/** * This parser handles the format under Self Service -> Faculty Center -> My * Schedule on GET. A sample record is as follows: * "Doe,John M 302043188 3.00 Engr, Comp Sci, & Tech CS MS". Again, not all * fields may be present.//from w w w .j av a2 s .c o m */ private List<ImportedUser> parse2(String text) { List<ImportedUser> students = new ArrayList<ImportedUser>(); Stack<String> stack = new Stack<String>(); Scanner scanner = new Scanner(text); scanner.useDelimiter("\\s+|\\r\\n|\\r|\\n"); while (scanner.hasNext()) { String name = ""; do { String token = scanner.next(); if (!isName(token)) stack.push(token); else { name = token; while (!stack.isEmpty() && !isDegree(stack.peek())) name = stack.pop() + " " + name; break; } } while (scanner.hasNext()); String cin = ""; boolean cinFound = false; while (scanner.hasNext()) { cin = scanner.next(); if (isCin(cin)) { cinFound = true; break; } else name += " " + cin; } if (cinFound) { ImportedUser student = new ImportedUser(); student.setCin(cin); student.setName(name); students.add(student); } } scanner.close(); return students; }
From source file:eu.skillpro.ams.pscm.connector.amsservice.ui.AutomaticOrdersProcessingHandler.java
protected String loadFile(String filename) { InputStream inputStream = this.getClass().getResourceAsStream("/resources/" + filename); if (inputStream != null) { Scanner s = new Scanner(inputStream).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; } else {//from www . j ava 2s .co m return ""; } }
From source file:reittienEtsinta.tiedostonKasittely.GeoJsonLukija.java
/** * Lukee GeoJson tiedoston ja muodostaa sen pohjalta polygoni taulukon * Polygonit on tallennettu joukkona koordinaattipisteita * * @param polku/*from w ww. ja va 2s. co m*/ * @return */ private JSONObject lataaJsonObject(File tiedosto) { Scanner lukija = null; try { lukija = new Scanner(tiedosto); } catch (FileNotFoundException ex) { Logger.getLogger(GeoJsonLukija.class.getName()).log(Level.SEVERE, null, ex); } lukija.useDelimiter("\\Z"); String data = lukija.next(); return new JSONObject(data); }
From source file:ch.cyberduck.core.importer.FlashFxpBookmarkCollection.java
@Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try {/*from www .jav a 2 s . c o m*/ 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("[")) { 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 (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 ("ip".equals(name)) { current.setHostname(StringUtils.substringBefore(value, "\u0001")); } else if ("port".equals(name)) { try { current.setPort(Integer.parseInt(value)); } catch (NumberFormatException e) { log.warn("Invalid Port:" + e.getMessage()); } } else if ("path".equals(name)) { current.setDefaultPath(value); } else if ("notes".equals(name)) { current.setComment(value); } else if ("user".equals(name)) { current.getCredentials().setUsername(value); } } } } finally { IOUtils.closeQuietly(in); } } catch (IOException e) { throw new AccessDeniedException(e.getMessage(), e); } }
From source file:eu.project.ttc.resources.DictionaryResource.java
private Set<Entry<String, String>> parse(InputStream inputStream) throws IOException { Scanner scanner = null; try {//w w w. j av a2s . c om Set<Entry<String, String>> entries = new HashSet<Entry<String, String>>(); scanner = new Scanner(inputStream, "UTF-8"); scanner.useDelimiter("\\r?\\n"); while (scanner.hasNext()) { String line = scanner.next(); String[] items = line.split("\t"); String source = items[0]; if (source != null) { String target = items[1]; if (target != null) { Entry<String, String> entry = new SimpleEntry<String, String>(source, target); entries.add(entry); } } } return entries; } finally { IOUtils.closeQuietly(scanner); } }
From source file:eu.project.ttc.resources.PrefixTree.java
@Override public void load(DataResource data) throws ResourceInitializationException { InputStream inputStream = null; try {//from w ww . j ava 2 s. c om inputStream = data.getInputStream(); Scanner scanner = null; try { String line; scanner = new Scanner(inputStream, "UTF-8"); scanner.useDelimiter(TermSuiteConstants.LINE_BREAK); while (scanner.hasNext()) { line = scanner.next().split(TermSuiteConstants.DIESE)[0].trim(); if (line.startsWith("#")) continue; else if (line.isEmpty()) continue; else if (line.endsWith("-")) { if (line.length() == 1) continue; else line = line.substring(0, line.length() - 1); } rootNode.indexString(toCharQueue(line)); } } catch (Exception e) { e.printStackTrace(); throw new ResourceInitializationException(e); } finally { IOUtils.closeQuietly(scanner); } } catch (IOException e) { LOGGER.error("Could not load file {}", data.getUrl()); throw new ResourceInitializationException(e); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:replicatedstackjgroups.ReplSet.java
private void eventLoop() { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); Scanner input = new Scanner(System.in); JSONObject json_obj = new JSONObject(); while (true) { try {//from ww w. j av a2s .c o m System.out.print("> "); System.out.flush(); // String line = in.readLine().toLowerCase(); String line = input.next().toLowerCase(); if (line.startsWith("quit") || line.startsWith("exit")) break; else if (line.startsWith("set_add")) { T packet = (T) input.nextLine(); json_obj.put("mode", "set_add"); json_obj.put("body", packet); } else if (line.startsWith("set_contains")) { T packet = (T) input.nextLine(); json_obj.put("mode", "set_contains"); json_obj.put("body", packet); } else if (line.startsWith("set_remove")) { T packet = (T) input.nextLine(); json_obj.put("mode", "set_remove"); json_obj.put("body", packet); } else if (line.startsWith("set_print")) { printSet(); json_obj.put("mode", "print"); json_obj.put("body", ""); } Message msg = new Message(null, null, json_obj); channel.send(msg); json_obj.clear(); } catch (Exception e) { } } }
From source file:eu.project.ttc.resources.SimpleWordSet.java
public void load(DataResource data) throws ResourceInitializationException { InputStream inputStream = null; this.elements = Sets.newHashSet(); try {//from www . j av a 2s .co m inputStream = data.getInputStream(); Scanner scanner = null; try { String word, line; String[] str, wordTranslations; scanner = new Scanner(inputStream, "UTF-8"); scanner.useDelimiter(TermSuiteConstants.LINE_BREAK); while (scanner.hasNext()) { line = scanner.next().split(TermSuiteConstants.DIESE)[0].trim(); str = line.split(TermSuiteConstants.TAB); word = str[0]; if (str.length > 0) this.elements.add(word); if (str.length > 1) { // Set the second line as the translation wordTranslations = str[1].split(TermSuiteConstants.COMMA); for (String translation : wordTranslations) { translations.put(word, translation); } } } this.elements = ImmutableSet.copyOf(this.elements); } catch (Exception e) { e.printStackTrace(); throw new ResourceInitializationException(e); } finally { IOUtils.closeQuietly(scanner); } } catch (IOException e) { LOGGER.error("Could not load file {}", data.getUrl()); throw new ResourceInitializationException(e); } finally { IOUtils.closeQuietly(inputStream); } }