List of usage examples for java.util Scanner hasNext
public boolean hasNext()
From source file:ch.cyberduck.core.importer.FlashFxpBookmarkCollection.java
@Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try {// w w w . j av 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:Javafile.java
void readWords(HashMap<String, Integer> words) { try {//from w ww . j a va 2 s .c om Scanner me = new Scanner(new File("E:/Sample Projects/ValidateWords/words.txt")); String word; while (me.hasNext()) { word = me.next(); words.put(word, word.length()); } } catch (Exception e) { } }
From source file:eu.scape_project.archiventory.identifiers.UnixFileIdentification.java
@Override public HashMap<String, List<String>> identifyFileList(DualHashBidiMap fileRecidBidiMap) throws IOException { HashMap<String, List<String>> resultMap = new HashMap<String, List<String>>(); String ufidRes = this.identify(fileRecidBidiMap.values()); Scanner s = new Scanner(ufidRes); // one file identification result per line s.useDelimiter("\n"); while (s.hasNext()) { // output syntax of the unix-tool 'file' is ${fileName} : ${mimeType} StringTokenizer st = new StringTokenizer(s.next(), ":"); String fileName = st.nextToken().trim(); // output key String key = (String) fileRecidBidiMap.getKey(fileName); if (key != null) { String containerFileName = key.substring(0, key.indexOf("/")); String containerIdentifier = key.substring(key.indexOf("/") + 1); String outputKey = String.format(outputKeyFormat, containerFileName, containerIdentifier); // output value String property = "mime"; String value = st.nextToken().trim(); String outputValue = String.format(outputValueFormat, tool, property, value); List<String> valueLineList = new ArrayList<String>(); valueLineList.add(outputValue); resultMap.put(outputKey, valueLineList); } else {// w w w. ja v a2 s .c o m } } return resultMap; }
From source file:org.envirocar.harvest.TrackPublisher.java
protected String readContent(InputStream content) throws IOException { Scanner sc = new Scanner(content); StringBuilder sb = new StringBuilder(content.available()); while (sc.hasNext()) { sb.append(sc.nextLine());/* ww w .j a v a2 s. c o m*/ } sc.close(); return sb.toString(); }
From source file:hu.ppke.itk.nlpg.purepos.POSTagger.java
@Override public void tag(Scanner scanner, PrintStream ps, int maxResultsNumber) { String line;/*from www .j a v a 2 s . c o m*/ while (scanner.hasNext()) { line = scanner.nextLine(); String sentString = tagAndFormat(line, maxResultsNumber); ps.println(sentString); } }
From source file:com.frankdye.marvelgraphws2.MarvelGraphView.java
private void processLine(String nextLine, Map<String, List<String>> map1, Set<String> set1) { // TODO Auto-generated method stub // use a second Scanner to parse the content of each line Scanner scanner = new Scanner(nextLine); scanner.useDelimiter("\t"); if (scanner.hasNext()) { // assumes the line has a certain structure String first = scanner.next(); first = first.replaceAll("^\"|\"$", ""); String last = scanner.next(); last = last.replaceAll("^\"|\"$", ""); // Query map to see if we have an entry for this comic issue List<String> l = map1.get(last); if (l == null) // No entry for this issue so create it. {/*from w w w .j a v a2 s. c o m*/ map1.put(last, l = new ArrayList<String>()); } // Issue exists or is created so append the characters name to the // map entry for that issue l.add(first); // Add the characters name to our set to maintain a list of each // unique character set1.add(first); } else { log("Empty or invalid line. Unable to process."); } scanner.close(); }
From source file:com.team3637.service.ScheduleServiceMySQLImpl.java
@Override public void initDB(String initScript) { String script = ""; try {//from w ww. j av a 2 s . c o 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:org.activiti.engine.impl.bpmn.helper.NGSISubscribeContextClient.java
private void readHTTPResponse() throws IllegalStateException, IOException, XmlException { InputStream input = httpresponse.getEntity().getContent(); java.util.Scanner s = new java.util.Scanner(input).useDelimiter("\\A"); String string = s.hasNext() ? s.next() : ""; System.out.println("NGSI response:\n" + string); SubscribeContextResponseDocument responseDoc = SubscribeContextResponseDocument.Factory.parse(string); subscribeContextResponse = responseDoc.getSubscribeContextResponse(); if (!subscribeContextResponse.validate()) throw new ActivitiException("Response from NGSI server is not valid"); }
From source file:org.whispersystems.bithub.tests.controllers.GithubControllerTest.java
protected String payload(String path) { InputStream is = this.getClass().getResourceAsStream(path); Scanner s = new Scanner(is).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; }
From source file:com.loopj.android.http.sample.CustomCASample.java
/** * Returns contents of `custom_ca.txt` file from assets as CharSequence. * * @return contents of custom_ca.txt file *///from w w w . j ava 2 s. c o m private CharSequence getReadmeText() { String rtn = ""; try { InputStream stream = getResources().openRawResource(R.raw.custom_ca); java.util.Scanner s = new java.util.Scanner(stream).useDelimiter("\\A"); rtn = s.hasNext() ? s.next() : ""; } catch (Resources.NotFoundException e) { Log.e(LOG_TAG, "License couldn't be retrieved", e); } return rtn; }