List of usage examples for java.io DataInputStream readLine
@Deprecated public final String readLine() throws IOException
readLine
method of DataInput
. From source file:Main.java
public static String execRootCmd(String[] cmds) { String result = ""; DataOutputStream dos = null;/* ww w.java2s. co m*/ DataInputStream dis = null; try { Process p = Runtime.getRuntime().exec("su"); dos = new DataOutputStream(p.getOutputStream()); dis = new DataInputStream(p.getInputStream()); for (String cmd : cmds) { Log.i("CmdUtils", cmd); dos.writeBytes(cmd + "\n"); dos.flush(); } dos.writeBytes("exit\n"); dos.flush(); String line; while ((line = dis.readLine()) != null) { Log.d("result", line); result += line; } p.waitFor(); } catch (Exception e) { e.printStackTrace(); } finally { if (dos != null) { try { dos.close(); } catch (IOException e) { e.printStackTrace(); } } if (dis != null) { try { dis.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; }
From source file:com.meterware.httpunit.HttpUnitUtils.java
/** * parse an InputStream to a string (for debugging) * @param is//from w ww .jav a2 s .co m * @return the string gotten from the inputString */ public static String parseISToString(java.io.InputStream is) { java.io.DataInputStream din = new java.io.DataInputStream(is); StringBuffer sb = new StringBuffer(); try { String line = null; while ((line = din.readLine()) != null) { sb.append(line + "\n"); } } catch (Exception ex) { // TODO handle exception properly here ex.getMessage(); } finally { try { is.close(); } catch (Exception ex) { } } return sb.toString(); }
From source file:eu.learnpad.simulator.mon.utils.Manager.java
/** * It reads text from file and provides it on string * * //w w w . java 2 s . c om * @param filePath the file to read path * @return a String containing all the file text */ @SuppressWarnings("deprecation") public static String ReadTextFromFile(String filePath) { File file = new File(filePath); FileInputStream fis = null; BufferedInputStream bis = null; DataInputStream dis = null; StringBuilder strB = new StringBuilder(); try { fis = new FileInputStream(file); // Here BufferedInputStream is added for fast reading. bis = new BufferedInputStream(fis); dis = new DataInputStream(bis); while (dis.available() != 0) { // this statement reads the line from the file and print it to // the console. strB.append(dis.readLine()); } // dispose all the resources after using them. fis.close(); bis.close(); dis.close(); } catch (IOException e) { e.printStackTrace(); } return strB.toString(); }
From source file:com.sinpo.xnfc.nfc.Util.java
public static String execRootCmd(String cmd) { String result = ""; DataOutputStream dos = null;/* ww w . ja v a 2 s .c o m*/ DataInputStream dis = null; try { Process p = Runtime.getRuntime().exec("su"); dos = new DataOutputStream(p.getOutputStream()); dis = new DataInputStream(p.getInputStream()); dos.writeBytes(cmd + "\n"); dos.flush(); dos.writeBytes("exit\n"); dos.flush(); String line = null; while ((line = dis.readLine()) != null) { result += line + "\r\n"; } p.waitFor(); } catch (Exception e) { e.printStackTrace(); } finally { if (dos != null) { try { dos.close(); } catch (IOException e) { e.printStackTrace(); } } if (dis != null) { try { dis.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; }
From source file:Main.java
public static String runCommand(String[] commands) { DataOutputStream outStream = null; DataInputStream responseStream; try {// w ww . j ava 2 s . com ArrayList<String> logs = new ArrayList<String>(); Process process = Runtime.getRuntime().exec("su"); Log.i(TAG, "Executed su"); outStream = new DataOutputStream(process.getOutputStream()); responseStream = new DataInputStream(process.getInputStream()); for (String single : commands) { Log.i(TAG, "Command = " + single); outStream.writeBytes(single + "\n"); outStream.flush(); if (responseStream.available() > 0) { Log.i(TAG, "Reading response"); logs.add(responseStream.readLine()); Log.i(TAG, "Read response"); } else { Log.i(TAG, "No response available"); } } outStream.writeBytes("exit\n"); outStream.flush(); String log = ""; for (int i = 0; i < logs.size(); i++) { log += logs.get(i) + "\n"; } Log.i(TAG, "Execution compeleted"); return log; } catch (IOException e) { Log.d(TAG, e.getMessage()); } return null; }
From source file:eu.learnpad.simulator.mon.utils.Manager.java
@SuppressWarnings("deprecation") public static Properties Read(String fileName) { Properties readedProps = new Properties(); File file = new File(fileName); FileInputStream fis = null;//from w w w. ja v a 2 s . c om BufferedInputStream bis = null; DataInputStream dis = null; try { fis = new FileInputStream(file); // Here BufferedInputStream is added for fast reading. bis = new BufferedInputStream(fis); dis = new DataInputStream(bis); // dis.available() returns 0 if the file does not have more lines. String property = ""; String key = ""; String value = ""; while (dis.available() != 0) { // this statement reads the line from the file and print it to // the console. property = dis.readLine().trim(); if (property.length() > 0) { key = property.substring(0, property.indexOf("=")); value = property.substring(property.indexOf("=") + 1, property.length()); readedProps.put(key.trim(), value.trim()); } } // dispose all the resources after using them. fis.close(); bis.close(); dis.close(); } catch (IOException e) { e.printStackTrace(); } return readedProps; }
From source file:nl.systemsgenetics.cellTypeSpecificAlleleSpecificExpression.ReadGenoAndAsFromIndividual.java
/** * * @param individual_names//from www . j av a2s . c o m * @param coupling_location * @return * @throws FileNotFoundException * @throws IOException * */ public static HashMap convert_individual_names(String[] individual_names, String coupling_location) throws FileNotFoundException, IOException { String coupling_loc = coupling_location; //This will be filled while reading the file ArrayList<String> sample_names_in_file = new ArrayList<String>(); ArrayList<String> individual_names_in_file = new ArrayList<String>(); //This will be the one that is later returned HashMap ordered_sample_names = new HashMap(); File coupling_file = new File(coupling_loc); FileInputStream fis; BufferedInputStream bis; DataInputStream dis; fis = new FileInputStream(coupling_file); // Here BufferedInputStream is added for fast reading. bis = new BufferedInputStream(fis); dis = new DataInputStream(bis); // dis.available() returns 0 if the file does not have more lines. int i = 0; while (dis.available() != 0) { String[] curr_line = dis.readLine().split("\t"); individual_names_in_file.add(i, curr_line[0]); sample_names_in_file.add(i, curr_line[1]); //print the individual al line for checking. //System.out.println("line: " + " " + curr_line[0] +" " + curr_line[1] ); } // dispose all the resources after using them. fis.close(); bis.close(); dis.close(); i = 0; for (String i_name : individual_names) { int index = individual_names_in_file.indexOf(i_name); if (index >= 0) { //We find a name in the genotype folder in the individual names stuff. ordered_sample_names.put(sample_names_in_file.get(index), i); } i++; } return (ordered_sample_names); }
From source file:org.wso2.carbon.build.tools.AetherManager.java
public static String getLatestVersion(org.wso2.carbon.build.tools.dto.Dependency dependency) { String latestVersion = ""; UrlValidate urlValidate = new UrlValidate(); String url = urlValidate.checkUrl(dependency.getArtifactId(), dependency.getGroupId(), dependency.getVersion());/*from w w w . ja v a 2 s .c o m*/ String repository; URL newUrl; InputStream inStream = null; DataInputStream dataInStream; String line; BufferedWriter bufferedWriter; if (url != null) { try { if (url.contains("org/wso2")) { repository = "org/wso2"; } else { repository = "maven"; } newUrl = new URL(url); try { inStream = newUrl.openStream(); } catch (Exception ex) { logger.error("Exception occurred : " + ex.getMessage()); } dataInStream = new DataInputStream(new BufferedInputStream(inStream)); bufferedWriter = new BufferedWriter(new FileWriter("out.txt")); while ((line = dataInStream.readLine()) != null) { bufferedWriter.write(line); bufferedWriter.newLine(); bufferedWriter.flush(); } //Read out.txt file PatternMatch patternMatch = new PatternMatch(); latestVersion = patternMatch.getMAtchDetails(dependency.getGroupId(), dependency.getVersion(), url, repository); } catch (Exception ex) { logger.error("Exception occurred : " + ex.getMessage()); } } return latestVersion; }
From source file:TestGetXMLClient.java
public void testXML() throws Exception { Collection<Class> classList = getClasses(); String serverUrl = "@SERVER_URL@"; for (Class klass : classList) { System.out.println("Searching for " + klass.getName()); try {// ww w .j ava2 s . c om String searchUrl = serverUrl + "/GetXML?query=" + klass.getName() + "&" + klass.getName(); URL url = new URL(searchUrl); URLConnection conn = url.openConnection(); //Uncomment following two lines for secured system and provide proper username and password //String base64 = "userId" + ":" + "password"; //conn.setRequestProperty("Authorization", "Basic " + new String(Base64.encodeBase64(base64.getBytes()))); File myFile = new File("./output/" + klass.getName() + "_test-getxml.xml"); FileWriter myWriter = new FileWriter(myFile); DataInputStream dis = new DataInputStream(conn.getInputStream()); String s = null; while ((s = dis.readLine()) != null) myWriter.write(s); myWriter.close(); } catch (Exception e) { System.out.println("Exception caught: " + e.getMessage()); e.printStackTrace(); } break; } }
From source file:SecurityManagerTest.java
private boolean accessOK() { int c;//from w w w . j a v a 2s . co m DataInputStream in = new DataInputStream(System.in); String response; System.out.println("What's the secret password?"); try { response = in.readLine(); if (response.equals(password)) return true; else return false; } catch (IOException e) { return false; } }