List of usage examples for java.util Scanner close
public void close()
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 w w. j a v a 2s . c o m 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:de.ifgi.mosia.wpswfs.Util.java
public static Set<String> readConfigFilePerLine(String resourcePath) throws IOException { URL resURL = Util.class.getResource(resourcePath); URLConnection resConn = resURL.openConnection(); resConn.setUseCaches(false);//from w w w. java2 s .com InputStream contents = resConn.getInputStream(); Scanner sc = new Scanner(contents); Set<String> result = new HashSet<String>(); String line; while (sc.hasNext()) { line = sc.nextLine(); if (line != null && !line.isEmpty() && !line.startsWith("#")) { result.add(line.trim()); } } sc.close(); return result; }
From source file:io.github.felsenhower.stine_calendar_bot.main.CallLevelWrapper.java
/** * Gets the password from stdin//from w w w . jav a 2 s . c o m * * @param query * the query to the user * @param errorMsg * the message to display when the input gets somehow redirected * and System.console() becomes null. * @return the entered password */ private static String readPassword(String query, String errorMsg) { final String result; if (System.console() != null) { System.err.print(query); result = new String(System.console().readPassword()); } else { System.err.println(errorMsg); System.err.print(query); Scanner scanner = new Scanner(System.in); result = scanner.nextLine(); scanner.close(); } System.err.println(); return result; }
From source file:org.eclipse.lyo.testsuite.server.trsutils.TestCore.java
/** * This method is used to read the contents * of a file as a String/* www .jav a2 s .c o m*/ * @param f * @return */ protected static String readFileAsString(File f) { StringBuilder stringBuilder = new StringBuilder(); Scanner scanner = null; try { scanner = new Scanner(f); } catch (FileNotFoundException e) { return null; } try { while (scanner.hasNextLine()) { stringBuilder.append(scanner.nextLine() + "\n"); } } finally { scanner.close(); } return stringBuilder.toString(); }
From source file:export.FormCrawler.java
public static JSONObject parse(InputStream in) throws JSONException { final Scanner s = new Scanner(in); final JSONObject o = new JSONObject(s.useDelimiter("\\A").next()); s.close(); return o;//from w w w. jav a2s .c o m }
From source file:export.FormCrawler.java
public static JSONObject parse(Reader in) throws JSONException { final Scanner s = new Scanner(in); final JSONObject o = new JSONObject(s.useDelimiter("\\A").next()); s.close(); return o;//from w w w. ja v a 2 s . co m }
From source file:org.lightcouch.CouchDbUtil.java
public static String readFile(String path) { InputStream instream = CouchDbUtil.class.getResourceAsStream(path); StringBuilder content = new StringBuilder(); Scanner scanner = null; try {//from w ww .j ava 2 s .c o m scanner = new Scanner(instream); while (scanner.hasNextLine()) { content.append(scanner.nextLine() + LINE_SEP); } } finally { scanner.close(); } return content.toString(); }
From source file:at.gv.egiz.bku.slcommands.impl.CreateXMLSignatureCommandImpl.java
private static void loadXAdES14Blacklist() { XADES_1_4_BLACKLIST_TS = System.currentTimeMillis(); XADES_1_4_BLACKLIST.clear();/*from w w w .j a v a 2s. c o m*/ try { URLConnection blc = new URL(ConfigurationFacade.XADES_1_4_BLACKLIST_URL).openConnection(); blc.setUseCaches(false); InputStream in = blc.getInputStream(); Scanner s = new Scanner(in); while (s.hasNext()) { XADES_1_4_BLACKLIST.add(s.next()); } s.close(); } catch (Exception e) { log.error("Blacklist load error", e); } }
From source file:Main.java
/** * This API compares if two files content is identical. It ignores extra * spaces and new lines while comparing/*from w ww . j ava2 s .c o m*/ * * @param sourceFile * @param destFile * @return * @throws Exception */ public static boolean isFilesIdentical(URL sourceFile, File destFile) throws Exception { try { Scanner sourceFileScanner = new Scanner(sourceFile.openStream()); Scanner destFileScanner = new Scanner(destFile); while (sourceFileScanner.hasNext()) { /* * If source file is having next token then destination file * also should have next token, else they are not identical. */ if (!destFileScanner.hasNext()) { destFileScanner.close(); sourceFileScanner.close(); return false; } if (!sourceFileScanner.next().equals(destFileScanner.next())) { sourceFileScanner.close(); destFileScanner.close(); return false; } } /* * Handling the case where source file is empty and destination file * is having text */ if (destFileScanner.hasNext()) { destFileScanner.close(); sourceFileScanner.close(); return false; } else { destFileScanner.close(); sourceFileScanner.close(); return true; } } catch (Exception e) { e.printStackTrace(); throw e; } /*finally { sourceFile.close(); }*/ }
From source file:ec.edu.ucuenca.dcc.sld.HttpUtils.java
public static synchronized String Http2_(String s, Map<String, String> mp) throws SQLException, IOException { String resp = ""; HttpClient client = new HttpClient(); PostMethod method = new PostMethod(s); method.getParams().setContentCharset("utf-8"); //Add any parameter if u want to send it with Post req. for (Entry<String, String> mcc : mp.entrySet()) { method.addParameter(mcc.getKey(), mcc.getValue()); }/*from w ww . j av a 2s .co m*/ int statusCode = client.executeMethod(method); if (statusCode != -1) { InputStream in = method.getResponseBodyAsStream(); final Scanner reader = new Scanner(in, "UTF-8"); while (reader.hasNextLine()) { final String line = reader.nextLine(); resp += line + "\n"; } reader.close(); } return resp; }