List of usage examples for java.util Scanner next
public String next()
From source file:business.Klant.java
public void setEmail(String email) { EmailValidator emailValidator = EmailValidator.getInstance(); Scanner input = new Scanner(System.in); while (emailValidator.isValid(email) == false) { System.out.println("Incorrecte email. Voer uw emailadres opnieuw in"); email = input.next(); }//from ww w .ja va 2 s .c o m this.email = email; }
From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnJavaFieldCutter.java
public void subsetFile(InputStream in, String outfile, Set<Integer> columns, Long numCases, String delimiter) { try {/*from ww w.j av a2 s . co m*/ Scanner scanner = new Scanner(in); dbgLog.fine("outfile=" + outfile); BufferedWriter out = new BufferedWriter(new FileWriter(outfile)); scanner.useDelimiter("\\n"); for (long caseIndex = 0; caseIndex < numCases; caseIndex++) { if (scanner.hasNext()) { String[] line = (scanner.next()).split(delimiter, -1); List<String> ln = new ArrayList<String>(); for (Integer i : columns) { ln.add(line[i]); } out.write(StringUtils.join(ln, "\t") + "\n"); } else { throw new RuntimeException("Tab file has fewer rows than the determined number of cases."); } } while (scanner.hasNext()) { if (!"".equals(scanner.next())) { throw new RuntimeException( "Tab file has extra nonempty rows than the determined number of cases."); } } scanner.close(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.cyclop.service.importer.intern.ParallelQueryImporter.java
private ImmutableList<CqlQuery> parse(Scanner scanner) { StopWatch timer = null;//from ww w .j a v a2s . c o m if (LOG.isDebugEnabled()) { timer = new StopWatch(); timer.start(); } ImmutableList.Builder<CqlQuery> build = ImmutableList.builder(); while (scanner.hasNext()) { String nextStr = StringUtils.trimToNull(scanner.next()); if (nextStr == null) { continue; } CqlQuery query = new CqlQuery(CqlQueryType.UNKNOWN, nextStr); build.add(query); } ImmutableList<CqlQuery> res = build.build(); if (LOG.isDebugEnabled()) { timer.stop(); LOG.debug("Parsed {} queries in {}", res.size(), timer.toString()); } return res; }
From source file:ddf.catalog.transformer.csv.common.CsvTransformerTest.java
private void validate(Scanner scanner, String[] expectedValues) { for (String expectedValue : expectedValues) { assertThat("Expected next value to be " + expectedValue + " but scanner.hasNext() returned false", scanner.hasNext(), is(true)); assertThat(scanner.next(), is(expectedValue)); }//from ww w. ja v a2 s . c o m }
From source file:ch.cyberduck.core.importer.FireFtpBookmarkCollection.java
private void read(final ProtocolFactory protocols, final String entry) { final Host current = new Host(protocols.forScheme(Scheme.ftp)); current.getCredentials().setUsername(PreferencesFactory.get().getProperty("connection.login.anon.name")); for (String attribute : entry.split(", ")) { Scanner scanner = new Scanner(attribute); scanner.useDelimiter(":"); if (!scanner.hasNext()) { log.warn("Missing key in line:" + attribute); continue; }//from w w w .j ava2 s . c om String name = scanner.next().toLowerCase(Locale.ROOT); if (!scanner.hasNext()) { log.warn("Missing value in line:" + attribute); continue; } String value = scanner.next().replaceAll("\"", StringUtils.EMPTY); 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 ("remotedir".equals(name)) { current.setDefaultPath(value); } else if ("webhost".equals(name)) { current.setWebURL(value); } else if ("encoding".equals(name)) { current.setEncoding(value); } else if ("notes".equals(name)) { current.setComment(value); } else if ("account".equals(name)) { current.setNickname(value); } else if ("privatekey".equals(name)) { current.getCredentials().setIdentity(LocalFactory.get(value)); } else if ("pasvmode".equals(name)) { if (Boolean.TRUE.toString().equals(value)) { current.setFTPConnectMode(FTPConnectMode.passive); } if (Boolean.FALSE.toString().equals(value)) { current.setFTPConnectMode(FTPConnectMode.active); } } else if ("login".equals(name)) { current.getCredentials().setUsername(value); } else if ("password".equals(name)) { current.getCredentials().setPassword(value); } else if ("anonymous".equals(name)) { if (Boolean.TRUE.toString().equals(value)) { current.getCredentials() .setUsername(PreferencesFactory.get().getProperty("connection.login.anon.name")); } } else if ("security".equals(name)) { if ("authtls".equals(value)) { current.setProtocol(protocols.forScheme(Scheme.ftps)); // Reset port to default current.setPort(-1); } if ("sftp".equals(value)) { current.setProtocol(protocols.forScheme(Scheme.sftp)); // Reset port to default current.setPort(-1); } } } this.add(current); }
From source file:org.molasdin.wbase.xml.parser.light.basic.BasicParser.java
private Pair<String, List<Pair<String, String>>> extractTag(String value) { Scanner scanner = new Scanner(value); scanner.useDelimiter("\\s+"); String tag = null;/* ww w . j a v a2 s .c o m*/ if (scanner.hasNext()) { tag = scanner.next(); if (!isValidTag(tag)) { return null; } } else { return null; } if (tag.contains("/")) { return null; } List<Pair<String, String>> attributes = new ArrayList<Pair<String, String>>(); while (scanner.hasNext()) { String part = scanner.next().trim(); Matcher matcher = attributePattern.matcher(part); if (!matcher.matches()) { return null; } Pair<String, String> attribute = Pair.of(matcher.group(1), matcher.group(2)); attributes.add(attribute); } return Pair.of(tag, attributes); }
From source file:com.google.payments.InAppBillingV3.java
private JSONObject getManifestContents() { if (manifestObject != null) return manifestObject; Context context = this.cordova.getActivity(); InputStream is;/* www . jav a 2 s .co m*/ try { is = context.getAssets().open("www/manifest.json"); Scanner s = new Scanner(is).useDelimiter("\\A"); String manifestString = s.hasNext() ? s.next() : ""; manifestObject = new JSONObject(manifestString); } catch (IOException e) { Log.d(TAG, "Unable to read manifest file:" + e.toString()); manifestObject = null; } catch (JSONException e) { Log.d(TAG, "Unable to parse manifest file:" + e.toString()); manifestObject = null; } return manifestObject; }
From source file:ch.cyberduck.core.importer.TotalCommanderBookmarkCollection.java
@Override protected void parse(final ProtocolFactory protocols, final Local file) throws AccessDeniedException { try {// w ww.j a v a 2s .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("[")) { 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:eu.project.ttc.resources.GeneralLanguageResource.java
public void load(InputStream inputStream) throws ResourceInitializationException { words = Sets.newHashSet();/*w ww . j a v a2 s .c o m*/ Scanner scanner = null; try { scanner = new Scanner(inputStream, "UTF-8"); scanner.useDelimiter("\n"); int index = 0; while (scanner.hasNext()) { index++; String line = scanner.next(); String[] items = line.split("::"); if (items.length == 3) { String key = items[0].trim(); if (!key.contains(" ")) this.words.add(key); Integer value = Integer.valueOf(items[2].trim()); this.cumulatedFrequency += value.intValue(); String lemma = key; this.frequencies.put(lemma, new Entry(lemma, items[1], new Integer(value.intValue()))); } else { throw new IOException("Wrong general language format at line " + index + ": " + line); } } this.words = ImmutableSet.copyOf(this.words); if (this.frequencies.containsKey(PARAM_NB_CORPUS_WORDS)) this.nbCorpusWords = this.frequencies.get(PARAM_NB_CORPUS_WORDS).iterator().next().getFrequency(); else { LOGGER.warn("No such key for in GeneralLanguage resource {}", PARAM_NB_CORPUS_WORDS); LOGGER.warn("Switch to cumulatedFrequency mode"); this.cumulatedFrequencyMode = true; } } catch (Exception e) { throw new ResourceInitializationException(e); } finally { IOUtils.closeQuietly(scanner); } }
From source file:DynamiskDemo2.java
/** * Constructs a new demonstration application. * * @param title the frame title.//from w w w .j a v a 2 s.c o m */ public DynamiskDemo2(final String title) { super(title); this.series = new XYSeries(title, false, false); final XYSeriesCollection dataset = new XYSeriesCollection(this.series); final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); final JButton button = new JButton("Add New Data Item"); button.setActionCommand("ADD_DATA"); button.addActionListener(this); final JPanel content = new JPanel(new BorderLayout()); content.add(chartPanel); content.add(button, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); String fil = "C:" + File.separator + "Users" + File.separator + "madso" + File.separator + "Documents" + File.separator + "!Privat" + File.separator + "DTU 2016-2020" + File.separator + "MATLAB"; String filnavn = "EKGdata"; try { Scanner sc = new Scanner(new FileReader(fil + File.separator + filnavn)); Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { if (sc.hasNext()) { final double newItem = Double.parseDouble(sc.next()); series.add(x, newItem); x += 10; } } }, 100, 2); } catch (IOException e) { e.printStackTrace(); } }