List of usage examples for java.io DataOutputStream DataOutputStream
public DataOutputStream(OutputStream out)
From source file:Main.java
public static void RunRootCmd(String cmd) { try {/*from w ww. j ava 2s. com*/ // // run our command using 'su' to gain root // Process process = Runtime.getRuntime().exec("su"); DataOutputStream outputStream = new DataOutputStream(process.getOutputStream()); outputStream.writeBytes(cmd + "\n"); outputStream.flush(); outputStream.writeBytes("exit\n"); outputStream.flush(); process.waitFor(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:MainClass.java
public static byte[] makeBytes(long t, double q) { try {//from w ww . j ava 2s. c o m ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(byteOut); dataOut.writeLong(t); dataOut.writeDouble(q); return byteOut.toByteArray(); } catch (IOException e) { return new byte[0]; } }
From source file:Main.java
public static void remountSystemRO() throws IOException { Process p = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(p.getOutputStream()); os.writeBytes(CMD_REMOUNT_RO + "\n"); os.writeBytes("exit\n"); os.flush();//from ww w. j a v a 2s .com }
From source file:Main.java
public static boolean runRootCommand(Context context, String command) { Process process = null;//from www .j a va2s . c om DataOutputStream os = null; try { process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(command + "\n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); } catch (Exception e) { Log.d("*** DEBUG ***", "Error - " + e.getMessage()); return false; } finally { try { if (os != null) { os.close(); } process.destroy(); } catch (Exception e) { } } return true; }
From source file:Main.java
public static boolean tempRunRootCommand(Context context, String command) { Process process = null;/*from ww w . j a v a2s .c om*/ DataOutputStream os = null; try { process = Runtime.getRuntime().exec("su1"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(command + "\n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); } catch (Exception e) { Log.d("*** DEBUG ***", "Error - " + e.getMessage()); return false; } finally { try { if (os != null) { os.close(); } process.destroy(); } catch (Exception e) { } } return true; }
From source file:Main.java
/** * Run command as root.//w w w. ja va 2 s.c o m * * @param command * @return true, if command was successfully executed */ private static boolean runAsRoot(final String command) { try { Process pro = Runtime.getRuntime().exec("su"); DataOutputStream outStr = new DataOutputStream(pro.getOutputStream()); outStr.writeBytes(command); outStr.writeBytes("\nexit\n"); outStr.flush(); int retval = pro.waitFor(); return (retval == 0); } catch (Exception e) { return false; } }
From source file:TestPipes.java
public static void writeData(OutputStream os) { try {//from ww w .j ava 2s.c om DataOutputStream out = new DataOutputStream(new BufferedOutputStream(os)); int[] numArray = { 1, 2, 3, 4, 5 }; for (int i = 0; i < numArray.length; i++) { out.writeInt(numArray[i]); } out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void secSet(Context context, String key, String val) { //long now = System.currentTimeMillis(); FileOutputStream fos = null;/*from w ww . ja v a2 s. co m*/ try { DataOutputStream dos = new DataOutputStream( (fos = context.openFileOutput(key + ".mits", android.content.Context.MODE_PRIVATE))); dos.writeUTF(val); } catch (FileNotFoundException e1) { //e1.printStackTrace(); } catch (IOException e1) { //e1.printStackTrace(); } finally { if (fos != null) try { fos.close(); } catch (IOException ignored) { } } }
From source file:Main.java
public static void execCmd(String cmd) { DataOutputStream dos = null;//from w w w . ja v a 2 s . c o m DataInputStream dis = null; try { Process p = Runtime.getRuntime().exec("su"); dos = new DataOutputStream(p.getOutputStream()); cmd += "\n"; dos.writeBytes(cmd); dos.flush(); dos.writeBytes("exit\n"); dos.flush(); p.waitFor(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } finally { try { if (dos != null) dos.close(); if (dis != null) dis.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:Main.java
public static void ExecuteNoReturn(String command, Boolean useroot, boolean forcenew) throws Exception { Process p;// w w w.j av a 2s . c o m DataOutputStream os; p = getProcess(useroot, forcenew); os = new DataOutputStream(p.getOutputStream()); os.writeBytes(command + "\n"); if (forcenew) { os.writeBytes("exit\n"); os.flush(); os.close(); } //p.waitFor(); }