List of usage examples for java.util Scanner next
public String next()
From source file:org.openinfinity.sso.common.ss.sp.SpringAuthenticationMessageConverter.java
private String valueFrom(String line) { Scanner resultLineScanner = new Scanner(line).useDelimiter("="); resultLineScanner.next(); return resultLineScanner.next(); }
From source file:br.com.sicoob.cro.cop.batch.core.FileReadTasklet.java
@Override public void process() { try {//from www . j av a 2 s . c om List<Operation> operacoes = new ArrayList(); InputStream source = this.getClass() .getResourceAsStream(this.context.getParameters().get("nomeArquivo").toString()); Scanner scan = new Scanner(source); while (scan.hasNext()) { String[] dados = scan.next().split(";"); Operation operacao = new Operation(dados[0], new BigDecimal(dados[1]), dados[2], new BigDecimal(dados[3])); operacoes.add(operacao); } // calcula o percentual de provisionamento for (Operation operacao : operacoes) { LOG.info(operacao.toString()); } scan.close(); source.close(); } catch (IOException ex) { Logger.getLogger(FileReadTasklet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.unitedinternet.cosmo.dav.impl.DavCard.java
protected void populateItem(DavInputContext inputContext) throws CosmoDavException { super.populateItem(inputContext); Item file = getItem();// w ww . j av a2s . c om Scanner scanner = new Scanner(inputContext.getInputStream()).useDelimiter("\\A"); file.setCalendar(scanner.next()); converter.convertCard(file); }
From source file:KnowledgeBooksNlpGenerateRdfPropertiesFromWebPages.java
public KnowledgeBooksNlpGenerateRdfPropertiesFromWebPages(String config_file_path, PrintWriter out) throws IOException { this.out = out; extractNames = new ExtractNames(); autoTagger = new AutoTagger(); List<String> lines = (List<String>) FileUtils.readLines(new File(config_file_path)); for (String line : lines) { Scanner scanner = new Scanner(line); scanner.useDelimiter(" "); try {//from w w w .ja va2 s. c o m String starting_url = scanner.next(); int spider_depth = Integer.parseInt(scanner.next()); spider(starting_url, spider_depth); } catch (Exception ex) { ex.printStackTrace(); } } this.out.close(); }
From source file:flens.input.GraphiteInput.java
@Override //metric_path value timestamp\n //http://graphite.wikidot.com/getting-your-data-into-graphite public void readAndProcess(Pair<String, BufferedReader> inx) throws IOException { BufferedReader in = inx.getRight(); String host = inx.getLeft();/*from ww w. j a va 2s . com*/ String line = in.readLine(); if (line == null) throw new IOException("connection lost"); Scanner st = new Scanner(line); try { String metricName = st.next(); String metric = st.next(); long time = st.nextLong(); Map<String, Object> tags = new HashMap<String, Object>(); tags.put(Constants.METRIC, metricName); tags.put(Constants.VALUE, metric); Record r = Record.createWithTimeHostAndValues(time * 1000, host, tags); dispatch(r); } catch (NoSuchElementException e) { warn("line too short", line); } }
From source file:com.wandrell.example.swss.client.console.ConsoleClient.java
/** * Runs the main application loop./* ww w. ja va 2 s . co m*/ * <p> * This is what keeps the client running and living. It can be stopped by * the user through a specific console command. * * @param output * output where all the information will be printed * @param clients * an {@code EntityClient} instance for each security method * @param uris * an endpoint URI for each security method */ private static final void runMainLoop(final PrintStream output, final Map<Security, EntityClient> clients, final Map<Security, String> uris) { final Scanner scanner; // Scanner for reading the input Security security; // Selected security method EntityClient client; // Client for the selected security String uri; // Endpoint for the selected security String command; // Current user command scanner = new Scanner(System.in, "UTF-8"); // The main loop // Stops when the 'exit' command is received do { // Prints options output.println(); printClientOptions(output); output.println(); // Reads command output.print("Pick an option: "); command = scanner.next(); output.println(); // Loads security from the command switch (command) { case "1": security = Security.UNSECURE; break; case "2": security = Security.PASSWORD_PLAIN_XWSS; break; case "3": security = Security.PASSWORD_PLAIN_WSS4J; break; case "4": security = Security.PASSWORD_DIGEST_XWSS; break; case "5": security = Security.PASSWORD_DIGEST_WSS4J; break; case "6": security = Security.SIGNATURE_XWSS; break; case "7": security = Security.SIGNATURE_WSS4J; break; case "8": security = Security.ENCRYPTION_XWSS; break; case "9": security = Security.ENCRYPTION_WSS4J; break; default: security = null; break; } // Checks if it was a valid option if (security != null) { // Valid option // The client and URI are acquired client = clients.get(security); uri = uris.get(security); // The endpoint is queried printQueryHeader(uri, security, output); callEndpoint(client, uri, output, scanner); } } while (!"exit".equalsIgnoreCase(command)); scanner.close(); }
From source file:EntityToD2RHelpers.java
public EntityToD2RHelpers(String uri, String config_file, List<String> people, List<String> places, PrintWriter out) throws Exception { // In this example, I am assuming that the D2R server is running on localhost:2020 //out.println("PREFIX vocab: <http://localhost:2020/vocab/resource/>"); List<String> lines = (List<String>) FileUtils.readLines(new File(config_file)); String d2r_host_and_port = lines.remove(0); String[] info = d2r_host_and_port.split(" "); System.out.println("D2R host = |" + info[0] + "| and port = |" + info[1] + "|"); for (String line : lines) { Scanner scanner = new Scanner(line); scanner.useDelimiter(" "); String d2r_type = scanner.next(); System.out.println("* d2r_type = " + d2r_type); while (scanner.hasNext()) { String term = scanner.next(); String[] property_and_entity_type = term.split("/"); System.out.println(" property: " + property_and_entity_type[0] + " entity type: " + property_and_entity_type[1]); if (property_and_entity_type[1].equals("person")) { for (String person : people) { // perform SPARQL queries to D2R server: String sparql = "PREFIX vocab: <http://localhost:2020/vocab/resource/>\n" + "SELECT ?subject ?name WHERE {\n" + " ?subject " + property_and_entity_type[0] + " ?name \n" + " FILTER regex(?name, \"" + person + "\") .\n" + "}\n" + "LIMIT 10\n"; SparqlClient test = new SparqlClient("http://localhost:2020/sparql", sparql); for (Map<String, String> bindings : test.variableBindings()) { System.out.print("D2R result:" + bindings); if (bindings.keySet().size() > 0) { String blank_node = blankNodeURI("person"); out.println(blank_node + " <http://knowledgebooks.com/rdf/personName> \"" + person.replaceAll("\"", "'") + "\" ."); out.println("<" + uri + "> <http://knowledgebooks.com/rdf/containsPerson> " + blank_node + " ."); out.println(blank_node + " <http://knowledgebooks.com/rdf/d2r_uri> \"" + bindings.get("subject") + "\" ."); }/*from w ww . j a va 2s .c om*/ } } } else if (property_and_entity_type[1].equals("place")) { for (String place : places) { // perform SPARQL queries to D2R server: String sparql = "PREFIX vocab: <http://localhost:2020/vocab/resource/>\n" + "SELECT ?subject ?name WHERE {\n" + " ?subject " + property_and_entity_type[0] + " ?name \n" + " FILTER regex(?name, \"" + place + "\") .\n" + "}\n" + "LIMIT 10\n"; SparqlClient test = new SparqlClient("http://localhost:2020/sparql", sparql); for (Map<String, String> bindings : test.variableBindings()) { System.out.print("D2R result:" + bindings); if (bindings.keySet().size() > 0) { String blank_node = blankNodeURI("place"); out.println(blank_node + " <http://knowledgebooks.com/rdf/placeName> \"" + place.replaceAll("\"", "'") + "\" ."); out.println("<" + uri + "> <http://knowledgebooks.com/rdf/containsPlace> " + blank_node + " ."); out.println(blank_node + " <http://knowledgebooks.com/rdf/d2r_uri> \"" + bindings.get("subject") + "\" ."); } } } } } } 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:Vdisk.java
public void get_access_token() { Scanner in = new Scanner(System.in); this.access_token = in.next(); }
From source file:key.access.manager.HttpHandler.java
public String connect(String url, ArrayList data) throws IOException { try {/*from w w w . j av a 2 s . co m*/ // 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"; } }