private Vector readlinesfromfile(String fname) { // trims lines and removes comments Vector v = new Vector(); try { BufferedReader br = new BufferedReader(new FileReader(new File(fname))); while (br.ready()) { String tmp = br.readLine(); // Strip comments while (tmp.indexOf("/*") >= 0) { int i = tmp.indexOf("/*"); v.add(tmp.substring(0, i)); String rest = tmp.substring(i + 2); while (tmp.indexOf("*/") == -1) { tmp = br.readLine(); } tmp = tmp.substring(tmp.indexOf("*/") + 2); } if (tmp.indexOf("//") >= 0) tmp = tmp.substring(0, tmp.indexOf("//")); // Strip spaces tmp = tmp.trim(); v.add(tmp); // System.out.println("Read line "+tmp); } br.close(); } catch (Exception e) { System.out.println("Exception " + e + " occured"); } return v; }
protected static synchronized String getVRMLreply(int queryno) { String req = "0"; String rep = ""; // This waits for the correct event toe be returned. Note that // sendevents dont wait, so there is the possibility that // we will have to while away a bit of time waiting... while (queryno != Integer.parseInt(req)) { try { req = BrowserfromEAI.readLine(); } catch (IOException ie) { System.out.println("EAI: caught " + ie); return rep; } if (queryno != Integer.parseInt(req)) { System.out.println( "EAI: getVRMLreply - REPLIES MIXED UP!!! Expecting " + queryno + " got " + req); } try { rep = BrowserfromEAI.readLine(); } catch (IOException ie) { System.out.println("EAI: getVRMLreply failed"); return null; } } return rep; }
/** * Gets a String. * * @return the string */ public String getString() { if (string == null) { StringBuffer buffer = new StringBuffer(); try { BufferedReader in = new BufferedReader(openReader()); String line = in.readLine(); while (line != null) { buffer.append(line + XML.NEW_LINE); line = in.readLine(); } in.close(); } catch (IOException ex) { ex.printStackTrace(); } string = buffer.toString(); } return string; }
public static String getWindows() { String cmd1 = "netsh wlan show profiles"; String cmd2 = "netsh wlan export profile name="; String keyword1 = "User profiles"; String wlanProfileArr[]; String wlanProfileName; int match = 0; int count = 0; ArrayList<String> profileList = new ArrayList<String>(); try { // Get wlan profile names Process p1 = Runtime.getRuntime().exec(cmd1); BufferedReader in1 = new BufferedReader(new InputStreamReader(p1.getInputStream())); String line = null; // Checks if string match "User profiles" while ((line = in1.readLine()) != null) { // Checks if string match "User profiles" if (match == 0) { if (line.toLowerCase().contains(keyword1.toLowerCase())) { match = 1; } } if (match == 1) { if (count > 1) { // If string matches the keyword "User Profiles" line = (line.replaceAll("\\s+$", "").replaceAll("^\\s+", "")); if (line.length() > 0) { wlanProfileName = (line.split(":")[1]).replaceAll("\\s+$", "").replaceAll("^\\s+", ""); ; profileList.add(wlanProfileName); } } count += 1; } } in1.close(); } catch (IOException e) { } try { String tmpDir = System.getProperty("java.io.tmpdir"); if (!(tmpDir.endsWith("/") || tmpDir.endsWith("\\"))) tmpDir = tmpDir + System.getProperty("file.separator"); // Export WLAN Profile to XML file for (Iterator iterator = profileList.iterator(); iterator.hasNext(); ) { String profileName = iterator.next().toString(); Process p2 = Runtime.getRuntime().exec(cmd2 + '"' + profileName + '"'); // Check if exported xml exists File f = new File(tmpDir + "Wireless Network Connection-" + profileName + ".xml"); if (f.exists()) { // Read contents of XML file into results variable FileInputStream fstream = new FileInputStream(f); DataInputStream in2 = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in2)); String xmlToStr; while ((xmlToStr = br.readLine()) != null) { result += xmlToStr; } in2.close(); } } } catch (IOException e) { } return result; }
public boolean test() { ExtendedService es = null; boolean ok = true; String tmpfilename = getParameter("tmpfile"); try { // Lookup the javax.jnlp.ExtendedService object es = (ExtendedService) ServiceManager.lookup("javax.jnlp.ExtendedService"); } catch (UnavailableServiceException ue) { System.out.println(ue); ue.printStackTrace(); // Service is not supported ok = false; } if (!ok) return false; // Open a specific file in the local machine File tmpfile = new File(tmpfilename); // Java Web Start will pop up a dialog asking the user to grant permission // to read/write the file 'tempfile' try { FileContents fc_tmpfile = es.openFile(tmpfile); if (!tmpfilename.equals(fc_tmpfile.getName())) { System.out.println( "\t tmpfile(out): " + tmpfilename + ", unequal to fc-filename: " + fc_tmpfile.getName() + " - info"); // ok=false; // return ok; } if (!fc_tmpfile.canWrite()) { System.out.println( "\t outfile: " + tmpfilename + ", no write access (may not exist yet) - info"); } // You can now use the FileContents object to read/write the file java.io.OutputStream sout = fc_tmpfile.getOutputStream(true); BufferedWriter bwsout = new BufferedWriter(new OutputStreamWriter(sout)); bwsout.write(datum, 0, datum.length()); bwsout.flush(); bwsout.close(); } catch (Exception e) { System.out.println(e); e.printStackTrace(); System.out.println("\t Error while IO write - failed"); ok = false; return ok; } // read back .. try { FileContents fc_tmpfile = es.openFile(tmpfile); if (!tmpfilename.equals(fc_tmpfile.getName())) { System.out.println( "\t tmpfile(in): " + tmpfilename + ", unequal to fc-filename: " + fc_tmpfile.getName() + " - info"); // ok=false; // return ok; } if (!fc_tmpfile.canRead()) { System.out.println("\t outfile: " + tmpfilename + ", read access failed"); ok = false; } // You can now use the FileContents object to read/write the file java.io.InputStream sin = fc_tmpfile.getInputStream(); BufferedReader brsin = new BufferedReader(new InputStreamReader(sin)); String in = brsin.readLine(); if (!in.equals(datum)) { System.out.println("\t file content <" + in + "> does not match <" + datum + "> - failed"); ok = false; } brsin.close(); } catch (Exception e) { System.out.println(e); e.printStackTrace(); System.out.println("\t Error while IO read - failed"); ok = false; return ok; } return ok; }