List of usage examples for java.util Scanner hasNext
public boolean hasNext()
From source file:com.acme.TopTagsTupleTest.java
@Test public void tags() throws IOException { final Broadcaster<Object> broadcaster = SerializedBroadcaster.create(); Processor processor = new TopTags(1, 10); Stream<?> outputStream = processor.process(broadcaster); outputStream.consume(new Consumer<Object>() { @Override//from w ww . j a v a 2s .c o m public void accept(Object o) { System.out.println("processed : " + o); } //TODO - expect // processed : {"id":"55786760-7472-065d-8e62-eb83260948a4","timestamp":1422399628134,"hashtag":"AndroidGames","count":1} // processed : {"id":"bd99050f-abfa-a239-c09a-f2fe721daafb","timestamp":1422399628182,"hashtag":"Android","count":1} // processed : {"id":"10ce993c-fd57-322d-efa1-16f810918187","timestamp":1422399628184,"hashtag":"GameInsight","count":1} }); ClassPathResource resource = new ClassPathResource("tweets.json"); Scanner scanner = new Scanner(resource.getInputStream()); while (scanner.hasNext()) { String tweet = scanner.nextLine(); broadcaster.onNext(tweet); //simulateLatency(); } //System.in.read(); }
From source file:ng.logentries.logs.LogReader.java
public <T extends LogEntryData> List<T> readLogs(Class<? extends LogEntryData> cls, Account account, FilterOptions options) throws Exception { List<T> list = new ArrayList<>(); LogEntryData instance = cls.newInstance(); CloseableHttpClient httpClient = HttpClientBuilder.create().build(); try {/*from w ww . j av a2 s . co m*/ URIBuilder uriBuilder = new URIBuilder().setScheme("https").setHost("pull.logentries.com/") .setPath(account.getAccessKey() + "/hosts/" + account.getLogSetName() + "/" + account.getLogName() + "/"); if (options.getLimit() != -1) { uriBuilder.addParameter("limit", "" + options.getLimit()); } uriBuilder.addParameter("filter", instance.getPattern()); if (options.getsTime() != -1) { uriBuilder.addParameter("start", "" + options.getsTime()); } if (options.geteTime() != -1) { uriBuilder.addParameter("end", "" + options.geteTime()); System.out.println(options.geteTime()); } HttpGet get = new HttpGet(uriBuilder.build()); HttpResponse httpResponse = httpClient.execute(get); HttpEntity entity = httpResponse.getEntity(); Scanner in = new Scanner(entity.getContent()); while (in.hasNext()) { T parse = (T) LogDataMapper.parse(in.nextLine(), cls); list.add(parse); //System.out.println(parse); } } catch (Exception e) { System.out.println("Error while trying to read logs: " + e); } finally { if (httpClient != null) { httpClient.close(); } } return list; }
From source file:org.cyclop.service.importer.intern.SerialQueryImporter.java
@Override void execImport(Scanner scanner, ResultWriter resultWriter, StatsCollector status, ImportConfig config) { while (scanner.hasNext()) { String nextStr = StringUtils.trimToNull(scanner.next()); if (nextStr == null) { continue; }/*from www.j a va 2s.c om*/ CqlQuery query = new CqlQuery(CqlQueryType.UNKNOWN, nextStr); long startTime = System.currentTimeMillis(); try { LOG.debug("Executing: {}", query); queryService.executeSimple(query, config.isUpdateHistory()); resultWriter.success(query, System.currentTimeMillis() - startTime); status.success.getAndIncrement(); } catch (QueryException e) { status.error.getAndIncrement(); LOG.debug(e.getMessage()); LOG.trace(e.getMessage(), e); resultWriter.error(query, e, System.currentTimeMillis() - startTime); if (!config.isContinueWithErrors()) { LOG.debug("Breaking import due to an error"); break; } } } }
From source file:hu.sztaki.incremental.ml.streaming.imsr.MatrixVectorPairSource.java
@Override public void invoke(Collector<Tuple2<double[][], double[][]>> out) throws Exception { File f = new File(path); if (!f.exists()) { System.err.println(path + " does not exist."); System.exit(1);/* ww w .j a v a 2 s .c om*/ } Scanner s = initCsvScanner(new Scanner(f)); String firstLine = s.nextLine(); Scanner firstLineScanner = initCsvScanner(new Scanner(firstLine)); for (indepDim = 0; firstLineScanner.hasNext(); firstLineScanner.next(), indepDim++) ; indepDim--; while (s.hasNext()) { Array2DRowRealMatrix X = new Array2DRowRealMatrix(batchSize, indepDim); Array2DRowRealMatrix y = new Array2DRowRealMatrix(batchSize, 1); readMatricesSideBySide(s, X, y); out.collect(new Tuple2<double[][], double[][]>(X.getDataRef(), y.getDataRef())); } s.close(); out.close(); }
From source file:io.gumga.presentation.api.voice.VoiceReceiverAPI.java
private String convertStreamToString(java.io.InputStream is) { java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; }
From source file:key.access.manager.HttpHandler.java
public String connect(String url, ArrayList data) throws IOException { try {// ww w. j av a2s . com // open a connection to the site URL connectionUrl = new URL(url); URLConnection con = connectionUrl.openConnection(); // activate the output con.setDoOutput(true); PrintStream ps = new PrintStream(con.getOutputStream()); // send your parameters to your site for (int i = 0; i < data.size(); i++) { ps.print(data.get(i)); //System.out.println(data.get(i)); if (i != data.size() - 1) { ps.print("&"); } } // we have to get the input stream in order to actually send the request InputStream inStream = con.getInputStream(); Scanner s = new Scanner(inStream).useDelimiter("\\A"); String result = s.hasNext() ? s.next() : ""; System.out.println(result); // close the print stream ps.close(); return result; } catch (MalformedURLException e) { e.printStackTrace(); return "error"; } catch (IOException e) { e.printStackTrace(); return "error"; } }
From source file:org.mcxiaoke.commons.http.util.URIUtilsEx.java
/** * Adds all parameters within the Scanner to the list of * <code>parameters</code>, as encoded by <code>encoding</code>. For * example, a scanner containing the string <code>a=1&b=2&c=3</code> would * add the {@link NameValuePair NameValuePairs} a=1, b=2, and c=3 to the * list of parameters.//w ww. ja v a 2 s . co m * * @param parameters * List to add parameters to. * @param scanner * Input that contains the parameters to parse. * @param charset * Encoding to use when decoding the parameters. */ public static void parse2(final Map<String, String> parameters, final Scanner scanner, final String charset) { scanner.useDelimiter(PARAMETER_SEPARATOR); while (scanner.hasNext()) { String key = null; String value = null; String token = scanner.next(); int i = token.indexOf(NAME_VALUE_SEPARATOR); if (i != -1) { key = decodeFormFields(token.substring(0, i).trim(), charset); value = decodeFormFields(token.substring(i + 1).trim(), charset); } else { key = decodeFormFields(token.trim(), charset); } parameters.put(key, value); } }
From source file:com.sonicle.webtop.core.versioning.SqlScript.java
private void readFile(InputStreamReader readable) throws IOException { this.statements = new ArrayList<>(); String lines[] = null;/*from w ww . j a v a 2 s . c o m*/ StringBuilder sbsql = null; Scanner s = new Scanner(readable); s.useDelimiter("(;( )?(\r)?\n)"); while (s.hasNext()) { String block = s.next(); block = StringUtils.replace(block, "\r", ""); if (!StringUtils.isEmpty(block)) { // Remove remaining ; at the end of the block (only if this block is the last one) if (!s.hasNext() && StringUtils.endsWith(block, ";")) block = StringUtils.left(block, block.length() - 1); sbsql = new StringBuilder(); lines = StringUtils.split(block, "\n"); for (String line : lines) { if (CommentLine.matches(line)) continue; sbsql.append(StringUtils.trim(line)); sbsql.append(" "); } if (sbsql.length() > 0) statements.add(sbsql.toString()); } } }
From source file:com.currencyfair.minfraud.MinFraudImpl.java
private Map<String, String> parseValueMap(String responseValues) { Map<String, String> pairs = new LinkedHashMap<>(); Scanner scanner = new Scanner(responseValues).useDelimiter("[;=]"); try {/* w w w . j a v a 2 s . c o m*/ while (scanner.hasNext()) { pairs.put(scanner.next(), scanner.next()); } } catch (NoSuchElementException x) { LOG.warn("Unbalanced response received from remote: {}", responseValues); } return ValueUtils.removeEmptyValues(pairs); }
From source file:hammingcode.HammingCode.java
ArrayList<String> readFile(String filename) throws FileNotFoundException { Scanner input = new Scanner(new File(filename)); ArrayList<String> inputList = new ArrayList(); while (input.hasNext()) { inputList.add(input.nextLine()); }// ww w.j av a 2s. c o m return inputList; }