List of usage examples for java.util Scanner next
public String next()
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 ww w.jav a2s . co m*/ 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:com.mycompany.celltableexmaple.server.GreetingServiceImpl.java
/** * Grabbing data from gallery's remote server. * Note: the parameter start and length aren't used here. *///w w w. j a v a2 s. c o m public List<GalleryApp> getApps(int start, int length) { final String galleryURL = "http://usf-appinventor-gallery.appspot.com/rpc?tag=all:0:50"; try { // Line below only valid at the server side. Cannot do it at client. URLConnection connection = new URL(galleryURL).openConnection(); //connection.setRequestProperty("Accept-Charset", charset); // Capture the returned data from server. InputStream response = connection.getInputStream(); java.util.Scanner s = new java.util.Scanner(response).useDelimiter("\\A"); ArrayList<GalleryApp> list = parseAppList(s.next()); return list; } catch (IOException e) { //return "exception opening gallery"; return new ArrayList<GalleryApp>(); } }
From source file:slina.mb.utils.LogFileReaderImpl.java
/** * readFileTest is faster// w w w . j a v a 2 s . c o m * @param fileName * @return * @throws IOException */ public List<String> readnio(String fileName) throws IOException { List<String> lines = new ArrayList<String>(); long before = System.currentTimeMillis(); Scanner scanner = new Scanner(new FileReader(fileName)); while (scanner.hasNext()) { lines.add(scanner.next()); } long after = System.currentTimeMillis(); System.out.println("nio run took " + (after - before) + " ms"); return lines; }
From source file:com.muzima.service.HTMLFormObservationCreatorTest.java
public String readFile() { InputStream fileStream = getClass().getClassLoader().getResourceAsStream("html/dispensary.json"); Scanner s = new Scanner(fileStream).useDelimiter("\\A"); return s.hasNext() ? s.next() : "{}"; }
From source file:RdfDataGenerationApplication.java
public RdfDataGenerationApplication(String web_sites_config_file, String database_config_file, PrintWriter out) throws Exception { this.out = out; this.database_config_file = database_config_file; // process web sites: List<String> lines = (List<String>) FileUtils.readLines(new File(web_sites_config_file)); for (String line : lines) { Scanner scanner = new Scanner(line); scanner.useDelimiter(" "); try {// w ww . jav a 2s . co m String starting_url = scanner.next(); int spider_depth = Integer.parseInt(scanner.next()); spider(starting_url, spider_depth); } catch (Exception ex) { ex.printStackTrace(); } } // after processing all 4 data sources, add more RDF statements for inter-source properties: process_interpage_shared_properties(); out.close(); }
From source file:opennlp.tools.parse_thicket.apps.MostFrequentWordsFromPageGetter.java
public List<String> getMostFrequentWordsInText(String input) { int maxRes = 4; Scanner in = new Scanner(input); in.useDelimiter("\\s+"); Map<String, Integer> words = new HashMap<String, Integer>(); while (in.hasNext()) { String word = in.next(); if (!StringUtils.isAlpha(word) || word.length() < 4) continue; if (!words.containsKey(word)) { words.put(word, 1);/*from w w w . j a va 2 s .c o m*/ } else { words.put(word, words.get(word) + 1); } } words = ValueSortMap.sortMapByValue(words, false); List<String> results = new ArrayList<String>(words.keySet()); if (results.size() > maxRes) results = results.subList(0, maxRes); // get maxRes elements return results; }
From source file:org.openmrs.module.eidinterface.web.controller.PatientStatusController.java
@ResponseBody @RequestMapping(value = "module/eidinterface/getPatientStatus", method = RequestMethod.POST) public String getPatientStatus(HttpServletResponse response, @RequestBody String identifiers) throws IOException { StringWriter sw = new StringWriter(); CSVWriter csv = new CSVWriter(sw); String[] header = { "Identifier", "Status", "CCC Number" }; csv.writeNext(header);//from ww w . j a v a 2s . c o m StringReader sr = new StringReader(identifiers); Scanner s = new Scanner(sr); // iterate through identifiers while (s.hasNext()) { String identifier = s.next().trim(); String status; String ccc = ""; String[] parts = identifier.split("-"); String validIdentifier = new LuhnIdentifierValidator().getValidIdentifier(parts[0]); if (!OpenmrsUtil.nullSafeEquals(identifier, validIdentifier)) { status = "INVALID IDENTIFIER"; } else { List<Patient> patients = Context.getPatientService().getPatients(null, identifier, null, true); if (patients != null && patients.size() == 1) { Patient p = patients.get(0); PatientIdentifier pi = p.getPatientIdentifier(CCC_NUMBER_PATIENT_IDENTIFIER_ID); if (pi != null) { status = "ENROLLED"; ccc = pi.getIdentifier(); } else { status = "NOT ENROLLED"; } } else if (patients != null && patients.size() > 1) { status = "MULTIPLE FOUND"; } else { status = "NOT FOUND"; } } csv.writeNext(new String[] { identifier, status, ccc }); } // flush the string writer sw.flush(); // set the information response.setContentType("text/plain"); response.setCharacterEncoding("UTF-8"); // respond with it return sw.toString(); }
From source file:com.github.woonsan.katharsis.invoker.KatharsisInvoker.java
private RequestBody inputStreamToBody(InputStream is) throws IOException { if (is == null) { return null; }//from w w w .j a v a2 s. c o m Scanner s = new Scanner(is).useDelimiter("\\A"); String requestBody = s.hasNext() ? s.next() : ""; if (requestBody == null || requestBody.isEmpty()) { return null; } return objectMapper.readValue(requestBody, RequestBody.class); }
From source file:org.fcrepo.modeshape.ModeshapeServer.java
private void start(boolean benchEnabled, int num, long size, int threads) throws Exception { RepositoryConfiguration cfg = RepositoryConfiguration .read(this.getClass().getClassLoader().getResourceAsStream("repository.json"), "repo"); ModeShapeEngine engine = new ModeShapeEngine(); engine.start();/*from w ww .j av a 2s. c o m*/ Repository repo = engine.deploy(cfg); repo.login(); while (engine.getRepositoryState("repo") != ModeShapeEngine.State.RUNNING) { Thread.yield(); } System.out.println("Modeshape is up and running."); if (benchEnabled) { System.out.println("Enter 'S' to start the tests:"); Scanner scan = new Scanner(System.in); while (!scan.hasNextLine()) { Thread.yield(); } String input = scan.next(); if (input.equalsIgnoreCase("s")) { System.out.println("starting tests"); BenchTool tool = new BenchTool(); tool.runBenchMark(repo, num, size, threads); } else { System.out.println("stopping server"); } } }
From source file:org.seedstack.w20.internal.MasterpageServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (!req.getRequestURI().endsWith("/")) { String queryString = req.getQueryString(); if (queryString != null) { resp.sendRedirect(req.getRequestURI() + "/" + queryString); } else {/*from w w w .j ava 2 s . c om*/ resp.sendRedirect(req.getRequestURI() + "/"); } } else { URL masterpageURL = classLoader.getResource(masterpagePath); if (masterpageURL == null) { throw new RuntimeException("Unable to generate W20 masterpage, template not found"); } Scanner scanner = new Scanner(masterpageURL.openStream()).useDelimiter("\\A"); String template = scanner.next(); scanner.close(); String contextPath = req.getContextPath(); Map<String, Object> variables = new HashMap<String, Object>(); variables.put("applicationTitle", StringUtils.isBlank(applicationTitle) ? application.getName() : applicationTitle); variables.put("applicationSubtitle", applicationSubtitle); variables.put("applicationVersion", StringUtils.isBlank(applicationVersion) ? application.getVersion() : applicationVersion); variables.put("timeout", timeout); variables.put("corsWithCredentials", corsWithCredentials); variables.put("basePath", PathUtils.removeTrailingSlash(contextPath)); variables.put("restPath", PathUtils.buildPath(contextPath, restPath)); if (webResourcesPath != null) { variables.put("webResourcesPath", PathUtils.buildPath(contextPath, webResourcesPath)); } if (componentsPath == null) { if (webResourcesPath != null) { variables.put("componentsPath", PathUtils.buildPath(contextPath, webResourcesPath, "bower_components")); } } else { variables.put("componentsPath", PathUtils.removeTrailingSlash(componentsPath)); } String result = replaceTokens(template, variables); resp.setContentLength(result.length()); resp.setContentType("text/html"); resp.getWriter().write(result); } }