List of usage examples for java.util Scanner Scanner
public Scanner(ReadableByteChannel source)
From source file:cfappserver.Bot.java
public static String genData(String user, String pass, int semnum) { try {/*from www . ja va 2 s . c o m*/ String url = "https://home-access.cfisd.net/HomeAccess/Account/LogOn?ReturnUrl=%2fhomeaccess%2f"; final HttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setSoTimeout(httpParams, 10000); HttpConnectionParams.setConnectionTimeout(httpParams, 10000); HttpClient client = new DefaultHttpClient(httpParams); CookieStore httpCookieStore = new BasicCookieStore(); HttpClientBuilder builder = HttpClientBuilder.create().setDefaultCookieStore(httpCookieStore); HttpPost post = new HttpPost(url); Scanner kk = new Scanner(System.in); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); urlParameters.add(new BasicNameValuePair("Database", "10")); urlParameters.add(new BasicNameValuePair("LogOnDetails.UserName", user)); urlParameters.add(new BasicNameValuePair("LogOnDetails.Password", pass)); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { } response = client.execute(new HttpGet("https://home-access.cfisd.net/HomeAccess/Classes/Classwork")); rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); result = new StringBuffer(); line = ""; ClssPkg classpack = null; while ((line = rd.readLine()) != null) { if (line.contains("<li class=\"sg-banner-menu-element sg-menu-element-identity\">")) { classpack = new ClssPkg(rd.readLine().split("<|>")[2],semnum); } } if (classpack == null) { return "Wrong login"; } getReport(client, classpack); getLunch(client, classpack); getAssignments(client, classpack); getAbsences(client, classpack, urlParameters); return classpack.toString(); } catch (Exception ex) { Logger.getLogger(Bot.class.getName()).log(Level.SEVERE, null, ex); } return "Wrong login"; }
From source file:csns.importer.parser.csula.RosterParserImpl.java
@Override public List<ImportedUser> parse(String text) { Scanner scanner = new Scanner(text); scanner.useDelimiter("\\s+|\\r\\n|\\r|\\n"); String first = scanner.next(); scanner.close();/* w w w .j av a2s.co m*/ return first.equals("1") ? parse1(text) : parse2(text); }
From source file:com.grayfox.server.ProgramTest.java
@Test public void testProgramExecution() { String commands = "add 19.054369,-98.283627\n" + "update pois\n" + "update categories\n" + "update all\n" + "delete pois\n" + "delete categories\n" + "delete all\n" + "\n" + "invalid command\n" + "update invalidOption\n" + "update\n" + "quit\n"; Scanner mockInput = new Scanner(commands); new Program().run(applicationContext, mockInput); InOrder inOrder = inOrder(poiService); inOrder.verify(poiService).addPois(anyVararg()); inOrder.verify(poiService).updatePois(); inOrder.verify(poiService).updateCategories(); inOrder.verify(poiService).updateAll(); inOrder.verify(poiService).deletePois(); inOrder.verify(poiService).deleteCategories(); inOrder.verify(poiService).deleteAll(); inOrder.verifyNoMoreInteractions();/* w w w . j ava2 s.co m*/ }
From source file:de.document.service.MedikamentService.java
public List<Medikament> readAllRoteListe() { List<Medikament> medicamentList = new ArrayList<>(); try (Scanner s = new Scanner( (Thread.currentThread().getContextClassLoader().getResourceAsStream("MedicamentList.txt")))) { while (s.hasNextLine()) { medicamentList.add(new Medikament(s.nextLine())); }//from w w w. j a v a 2s.c o m } return medicamentList; }
From source file:com.opentangerine.clean.Replace.java
/** * Apply replace transformation on selected line only if matching * function returned true.//from w w w.ja v a 2 s.c o m * * @param matching Closure that returns true if line has been matched. * @param transformation Closure with line transformation. * @return Replace object. */ public Replace replace(final Function<String, Boolean> matching, final Function<String, String> transformation) { final StrBuilder out = new StrBuilder(); try (Scanner scanner = new Scanner(this.text)) { while (scanner.hasNextLine()) { final String line = scanner.nextLine(); if (matching.apply(line)) { out.append(transformation.apply(line)); } else { out.append(line); } out.appendNewLine(); } } return new Replace(out.build()); }
From source file:com.box.restclientv2.httpclientsupport.HttpClientURLEncodedUtils.java
/** * Returns a list of {@link NameValuePair NameValuePairs} as built from the URI's query portion. For example, a URI of * http://example.org/path/to/file?a=1&b=2&c=3 would return a list of three NameValuePairs, one for a=1, one for b=2, and one for c=3. * <p>/*from w ww.j ava 2 s.c o m*/ * This is typically useful while parsing an HTTP PUT. * * @param query * query to parse * @param encoding * encoding to use while parsing the query */ public static List<NameValuePair> parse(String query, final String encoding) { if (query != null && query.length() > 0) { List<NameValuePair> result = new ArrayList<NameValuePair>(); Scanner scanner = new Scanner(query); parse(result, scanner, encoding); return result; } else { return Collections.emptyList(); } }
From source file:de.phip1611.apps.numbered_filenames_with_leading_zeros.CommandLineTool.java
/** * Initialisiert die Kommandozeilen-Schnittstelle zum Tool. * @param config JSON-Objekt mit Konfigurationseintrgen. *///from w ww .j a v a 2 s. c om public CommandLineTool(JSONObject config) { this.scanner = new Scanner(System.in); this.config = config; this.alzTool = new AddLeadingZeros(); this.run(); }
From source file:org.sasabus.export2Freegis.network.SubscriptionManager.java
public boolean subscribe() throws IOException { for (int i = 0; i < SUBFILEARRAY.length; ++i) { Scanner sc = new Scanner(new File(SUBFILEARRAY[i])); String subscriptionstring = ""; while (sc.hasNextLine()) { subscriptionstring += sc.nextLine(); }/*from w w w. j a va 2s. c o m*/ sc.close(); SimpleDateFormat date_date = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat date_time = new SimpleDateFormat("HH:mm:ssZ"); Date d = new Date(); String timestamp = date_date.format(d) + "T" + date_time.format(d); timestamp = timestamp.substring(0, timestamp.length() - 2) + ":" + timestamp.substring(timestamp.length() - 2); Calendar c = Calendar.getInstance(); c.setTime(d); c.add(Calendar.DATE, 1); d = c.getTime(); String valid_until = date_date.format(d) + "T" + date_time.format(d); valid_until = valid_until.substring(0, valid_until.length() - 2) + ":" + valid_until.substring(valid_until.length() - 2); subscriptionstring = subscriptionstring.replaceAll(":timestamp_valid", valid_until); subscriptionstring = subscriptionstring.replaceAll(":timestamp", timestamp); String requestString = "http://" + this.address + ":" + this.portnumber_sender + "/TmEvNotificationService/gms/subscription.xml"; HttpPost subrequest = new HttpPost(requestString); StringEntity requestEntity = new StringEntity(subscriptionstring, ContentType.create("text/xml", "ISO-8859-1")); CloseableHttpClient httpClient = HttpClients.createDefault(); subrequest.setEntity(requestEntity); CloseableHttpResponse response = httpClient.execute(subrequest); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { try { System.out.println("Stauts Response: " + response.getStatusLine().getStatusCode()); System.out.println("Status Phrase: " + response.getStatusLine().getReasonPhrase()); HttpEntity responseEntity = response.getEntity(); if (responseEntity != null) { String responsebody = EntityUtils.toString(responseEntity); System.out.println(responsebody); } } finally { response.close(); httpClient.close(); } return false; } System.out.println("Subscription of " + SUBFILEARRAY[i]); } return true; }
From source file:eu.creatingfuture.propeller.blocklyprop.propeller.PropellerLoad.java
protected List<String> getPorts(String executable) { List<String> ports = new ArrayList<>(); try {//from w w w . ja v a2 s . c om CommandLine cmdLine = new CommandLine(executable); cmdLine.addArgument("-P"); DefaultExecutor executor = new DefaultExecutor(); //executor.setExitValues(new int[]{451, 301}); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); try { exitValue = executor.execute(cmdLine); } catch (ExecuteException ee) { exitValue = ee.getExitValue(); logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue); return ports; } finally { output = outputStream.toString(); } /* if (exitValue == 301) { return ports; } */ // System.out.println("output: " + output); Scanner scanner = new Scanner(output); while (scanner.hasNextLine()) { ports.add(scanner.nextLine()); } return ports; } catch (IOException ioe) { logger.log(Level.SEVERE, null, ioe); return null; } }
From source file:eu.creatingfuture.propeller.webLoader.propeller.PropellerLoad.java
protected List<String> getPorts(String executable) { List<String> ports = new ArrayList<String>(); try {// w ww . java2 s .co m CommandLine cmdLine = new CommandLine(executable); cmdLine.addArgument("-P"); DefaultExecutor executor = new DefaultExecutor(); //executor.setExitValues(new int[]{451, 301}); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); executor.setStreamHandler(streamHandler); try { exitValue = executor.execute(cmdLine); } catch (ExecuteException ee) { exitValue = ee.getExitValue(); logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue); return ports; } finally { output = outputStream.toString(); } /* if (exitValue == 301) { return ports; } */ // System.out.println("output: " + output); Scanner scanner = new Scanner(output); while (scanner.hasNextLine()) { ports.add(scanner.nextLine()); } return ports; } catch (IOException ioe) { logger.log(Level.SEVERE, null, ioe); return null; } }