List of usage examples for java.util Scanner next
public String next()
From source file:nl.esciencecenter.xenon.adaptors.schedulers.gridengine.GridEngineXmlParserTest.java
private static String readFile(String pathName) { InputStream is = GridEngineXmlParserTest.class.getResourceAsStream(pathName); // we read until end of file, delimited by \\A Scanner s = new Scanner(is, "UTF-8").useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; }
From source file:formatMessage.VerifyInputScanner.java
/** * Ga naar https://commons.apache.org/proper/commons-validator/download_validator.cgi * download de bin file// w w w . j a v a 2 s .co m * Ga naar libraries in netbeans rechtermuisknop workshop1 properties * Druk op libraries * add library * create * dan add the file commons-validator-1.5.0 aan de classpath * * @return */ public static String verifyEmail() { Scanner input = new Scanner(System.in); while (true) { try { String verified = input.next(); EmailValidator emailVal = EmailValidator.getInstance(); if (emailVal.isValid(verified)) { return verified; } } catch (InputMismatchException e) { System.out.println("Geen juiste invoer probeer opnieuw"); } } }
From source file:Main.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 Pair<String, String> NameValuePairs} a=1, b=2, and c=3 to the * list of parameters.//from w w w . ja v a2 s . c o m * * @param parameters * List to add parameters to. * @param scanner * Input that contains the parameters to parse. * @param encoding * Encoding to use when decoding the parameters. */ public static void parse(final List<Pair<String, String>> parameters, final Scanner scanner, final String encoding) { scanner.useDelimiter(PARAMETER_SEPARATOR); while (scanner.hasNext()) { final String[] nameValue = scanner.next().split(NAME_VALUE_SEPARATOR); if (nameValue.length == 0 || nameValue.length > 2) throw new IllegalArgumentException("bad parameter"); final String name = decode(nameValue[0], encoding); String value = null; if (nameValue.length == 2) value = decode(nameValue[1], encoding); parameters.add(new Pair<String, String>(name, value)); } }
From source file:net.sf.jaceko.mock.resource.BasicSetupResource.java
static Map<String, String> parseHeadersToPrime(String headersToPrime) { Map<String, String> headersMap = new HashMap<String, String>(); if (headersToPrime != null) { Scanner headersScanner = new Scanner(headersToPrime).useDelimiter(HEADERS_DELIMITER); while (headersScanner.hasNext()) { String header = headersScanner.next(); String[] headerPart = header.split(HEADER_DELIMITER); String headerName = headerPart[HEADER_KEY_INDEX]; String headerValue = headerPart[HEADER_VALUE_INDEX]; headersMap.put(headerName, headerValue); }//from w w w .j a v a2 s.c o m } return headersMap; }
From source file:org.jenkinsci.test.acceptance.docker.fixtures.JavaContainerTest.java
@BeforeClass public static void cleanOldImages() throws Exception { Process dockerImages;//from w ww . j a v a 2 s . c om try { dockerImages = new ProcessBuilder("docker", "images", "--format", "{{.Repository}}:{{.Tag}}").start(); } catch (IOException x) { throw new AssumptionViolatedException("could not run docker", x); } Scanner scanner = new Scanner(dockerImages.getInputStream()); List<String> toRemove = new ArrayList<>(); while (scanner.hasNext()) { String image = scanner.next(); if (image.startsWith("jenkins/")) { toRemove.add(image); } } dockerImages.waitFor(); if (!toRemove.isEmpty()) { toRemove.add(0, "docker"); toRemove.add(1, "rmi"); Process dockerRmi = new ProcessBuilder(toRemove).redirectErrorStream(true).start(); // Cannot use inheritIO from Surefire. IOUtils.copy(dockerRmi.getInputStream(), System.err); dockerRmi.waitFor(); } }
From source file:org.hancel.http.HttpUtils.java
private static JSONObject execute(String base, List<NameValuePair> params, String method) throws IOException, JSONException { URL url;/*from w ww .j a v a 2 s .co m*/ HttpURLConnection urlConnection = null; if (method.equals("GET")) { url = new URL(base + getQuery(params)); urlConnection = (HttpURLConnection) url.openConnection(); } try { InputStream in = new BufferedInputStream(urlConnection.getInputStream()); Scanner s = new Scanner(in).useDelimiter("\\A"); String parseString = s.hasNext() ? s.next() : ""; in.close(); return new JSONObject(parseString); } finally { urlConnection.disconnect(); } }
From source file:xored.vpn.fixer.TokenDetector.java
public static String execCmd(String cmd) throws java.io.IOException, InterruptedException { Process p = Runtime.getRuntime().exec(cmd); p.waitFor();/* w ww .j a va 2 s . co m*/ InputStream io; if (p.exitValue() == 0) { io = p.getInputStream(); } else { io = p.getErrorStream(); } Scanner s = new Scanner(io).useDelimiter("\\A"); return s.hasNext() ? s.next() : ""; }
From source file:org.lightcouch.CouchDbUtil.java
public static String streamToString(InputStream in) { Scanner s = new Scanner(in).useDelimiter("\\A"); String str = s.hasNext() ? s.next() : null; close(in);//from w w w. j a v a 2 s .c o m return str; }
From source file:app.sunstreak.yourpisd.net.LoginDebugger.java
static void debug(String[] args) throws MalformedURLException, IOException, InterruptedException, ExecutionException, JSONException { if (args.length == 2) { mEmail = args[0];/*from w ww .j a va 2 s.c om*/ mPassword = args[1]; System.out.println("|" + mEmail + "|" + mPassword + "|"); } else { Scanner sc = new Scanner(System.in); System.out.print("Please enter username:\t"); mEmail = sc.next(); System.out.print("Please enter password:\t"); mPassword = sc.next(); sc.close(); } session = Session.createSession(mEmail, mPassword); int loginSuccess = session.login(); if (loginSuccess == 1) System.out.println("Successful login!"); else { System.out.println("Login failed."); System.exit(-1); } session.tryLoginGradebook(); for (Student st : session.getStudents()) { st.loadGradeSummary(); for (int i = 0; i < 8; i++) System.out.println(st.getClassesForTerm(i)); for (int i = 0; i < st.getClassMatch().length; i++) { System.out.printf("%20s", st.getClassList().optJSONObject(st.getClassMatch()[i]).getString("title")); System.out.print(" "); JSONArray classGrade = st.getClassList().optJSONObject(st.getClassMatch()[i]).optJSONArray("terms"); if (classGrade.optJSONObject(0).getString("description").equals("4th Six Weeks")) System.out.printf("%20s", ""); for (int j = 0; j < classGrade.length(); j++) { int score = classGrade.optJSONObject(j).optInt("average", -1); System.out.printf("%5s", displayScore(score)); } if (classGrade.length() == 4 && classGrade.optJSONObject(0).getString("description").equals("1st Six Weeks")) System.out.printf("%20s", ""); System.out.printf(" S1:%5s", displayScore( st.getClassList().optJSONObject(st.getClassMatch()[i]).optInt("firstSemesterAverage", -1))); System.out.printf(" S2:%5s\n", displayScore(st.getClassList().optJSONObject(st.getClassMatch()[i]) .optInt("secondSemesterAverage", -1))); } boolean attendanceLoaded = false; while (!attendanceLoaded) { try { st.loadAttendanceSummary(); attendanceLoaded = true; } catch (Exception e) { e.printStackTrace(); } } /* String[] classNames = st.getAttendanceSummaryClassNames(); int[][] attendanceSummary = st.getAttendanceSummary(); for (int j = 0; j < Parser.AttendanceData.COLS.length; j++) { System.out.printf("%20s", ""); System.out.printf("%5s", Parser.AttendanceData.COLS[j]); System.out.println(); } for (int i = 0; i < classNames.length; i++) { System.out.printf("%20s", classNames[i]); for (int j = 0; j < attendanceSummary[i].length; j++) { System.out.printf("%5d", attendanceSummary[i][j]); } System.out.println(); } */ } }
From source file:net.ftb.util.AppUtils.java
/** * Reads all of the data from the given stream and returns it as a string. * @param stream the stream to read from. * @return the data read from the given stream as a string. *//*from w w w. j a v a 2 s . c o m*/ public static String readString(InputStream stream) { Scanner scanner = new Scanner(stream).useDelimiter("\\A"); return scanner.hasNext() ? scanner.next() : ""; }