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
/** * Locte the tun.ko driver on the filesystem * @return a String with the path of the tun.ko driver *///from w w w . ja va 2 s .c o m public static String findTunDriverPath() { String tunDriverPath = ""; String find_str; try { Process find_proc = Runtime.getRuntime().exec("find /sdcard /system /data -name tun.ko"); DataInputStream find_in = new DataInputStream(find_proc.getInputStream()); try { while ((find_str = find_in.readLine()) != null) { tunDriverPath = find_str; } } catch (IOException e) { System.exit(0); } } catch (IOException e1) { Log.e("OpenVpnSettings_Util", e1.toString()); } // if (new File(tunDriverPath).exists()) // System.out.println(tunDriverPath); // else System.out.println("ERROR file does not exist: " + tunDriverPath); return tunDriverPath; }
From source file:Yak_Hax.Yak_Hax_Mimerme.PostRequest.java
public static String PostBodyRequest(String URL, String JSONRaw, String UserAgent) throws IOException { String type = "application/json"; URL u = new URL(URL); HttpURLConnection conn = (HttpURLConnection) u.openConnection(); conn.setDoOutput(true);/*from w w w. j a va 2s . c om*/ conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", type); conn.setRequestProperty("User-Agent", UserAgent); OutputStream os = conn.getOutputStream(); os.write(JSONRaw.getBytes()); os.flush(); os.close(); String response = null; DataInputStream input = new DataInputStream(conn.getInputStream()); while (null != ((response = input.readLine()))) { input.close(); return response; } return null; }
From source file:Main.java
public static String execCmd(String cmd) { String result = ""; DataInputStream dis = null; try {//from w w w.j a va 2 s . c om Process p = Runtime.getRuntime().exec(cmd); dis = new DataInputStream(p.getInputStream()); String line = null; while ((line = dis.readLine()) != null) { line += "\n"; result += line; } p.waitFor(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } return result; }
From source file:Main.java
private static boolean isRootOk(DataOutputStream output, DataInputStream input, final DataInputStream errInput) { if (output != null) { try {//from w ww . j ava 2 s. c o m output.writeBytes("id\n"); output.flush(); String a = input.readLine(); if (a.contains("root") || a.contains("uid=0")) { return true; } new Thread() { @Override public void run() { try { errInput.read(); } catch (IOException e) { e.printStackTrace(); } }; }.start(); } catch (IOException e) { e.printStackTrace(); } } return false; }
From source file:org.wso2.carbon.registry.handler.test.HandlerAddTestCase.java
public static String fileReader(String fileName) { String fileContent = ""; try {// www . java2 s .c o m // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream(fileName); // Convert our input stream to a // DataInputStream DataInputStream in = new DataInputStream(fstream); // Continue to read lines while // there are still some left to read while (in.available() != 0) { fileContent = fileContent + (in.readLine()); } in.close(); } catch (Exception e) { System.err.println("File input error"); } return fileContent; }
From source file:Main.java
public static String execRootCmd(String cmd) { String result = "result : "; try {// w w w. j a va 2 s .c om Process p = Runtime.getRuntime().exec("su "); OutputStream outStream = p.getOutputStream(); DataOutputStream dOutStream = new DataOutputStream(outStream); InputStream inStream = p.getInputStream(); DataInputStream dInStream = new DataInputStream(inStream); String str1 = String.valueOf(cmd); String str2 = str1 + "\n"; dOutStream.writeBytes(str2); dOutStream.flush(); String str3 = null; String line = ""; while ((line = dInStream.readLine()) != null) { Log.d("result", str3); str3 += line; } dOutStream.writeBytes("exit\n"); dOutStream.flush(); p.waitFor(); return result; } catch (Exception e) { e.printStackTrace(); return result; } }
From source file:com.chintans.venturebox.util.Utils.java
private static String getStreamLines(final InputStream is) { String out = null;// w ww .j a va 2 s .co m StringBuffer buffer = null; final DataInputStream dis = new DataInputStream(is); try { if (dis.available() > 0) { buffer = new StringBuffer(dis.readLine()); while (dis.available() > 0) { buffer.append("\n").append(dis.readLine()); } } dis.close(); } catch (Exception ex) { ex.printStackTrace(); } if (buffer != null) { out = buffer.toString(); } return out; }
From source file:com.flexdesktop.connections.restfulConnection.java
public static ArrayList<ArrayList<String>> getRESTful(String RESTfull_URL, ArrayList<String> columnasTabla) { try {/*from w ww. j a v a2s.c o m*/ URL url; URLConnection urlConnection; DataInputStream readString; url = new URL(RESTfull_URL); urlConnection = url.openConnection(); urlConnection.setDoInput(true); urlConnection.setUseCaches(false); readString = new DataInputStream(urlConnection.getInputStream()); String s; String getRequest = ""; while ((s = readString.readLine()) != null) { getRequest += s; } readString.close(); if (!"".equals(getRequest)) { return completeArray(getRequest, columnasTabla); } } catch (Exception ex) { Logger.getLogger(com.flexdesktop.connections.restfulConnection.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:flexpos.restfulConnection.java
public static ArrayList<ArrayList<String>> getRESTful(String RESTfull_URL, ArrayList<String> columnasTabla) { try {/*from www. j a va 2 s.co m*/ URL url; URLConnection urlConnection; DataInputStream readString; url = new URL(RESTfull_URL); urlConnection = url.openConnection(); urlConnection.setDoInput(true); urlConnection.setUseCaches(false); readString = new DataInputStream(urlConnection.getInputStream()); String s; String getRequest = ""; while ((s = readString.readLine()) != null) { getRequest += s; } readString.close(); if (!"".equals(getRequest)) { return completeArray(getRequest, columnasTabla); } } catch (Exception ex) { Logger.getLogger(restfulConnection.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:Main.java
public static int execRootCmdForExitCode(String[] cmds) { int result = -1; DataOutputStream dos = null;// w w w . j a v a 2 s .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); } p.waitFor(); result = p.exitValue(); } 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; }