List of usage examples for java.io DataOutputStream DataOutputStream
public DataOutputStream(OutputStream out)
From source file:Main.java
public static void GetSUAccess() { Thread su = new Thread(new Thread() { public void run() { try { Log.i("SU", "Trying to grant access to port..."); Process suProcess = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(suProcess.getOutputStream()); if (null != os) { os.writeBytes("chmod 666 /dev/ttymxc1 \n"); os.flush();//www. j av a 2s. c o m } Log.i("SU", "Granted Access to Port"); } catch (IOException e) { Log.e("SU", "Grant SuperUser Access Failed"); } } }); su.start(); }
From source file:Main.java
private static byte[] getBytesFromFile(File file) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); try {/*from ww w . j a va2 s . c o m*/ FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); } int maxBufferSize = 1024 * 1024; int bufferSize = (int) Math.min(file.getTotalSpace(), maxBufferSize); byte[] buffer = new byte[bufferSize]; // read file and write it into form... int bytesRead = 0; if (fileInputStream != null) { bytesRead = fileInputStream.read(buffer, 0, bufferSize); } while (bytesRead > 0) { dataOutputStream.write(buffer, 0, bufferSize); int bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); } } catch (Exception e) { e.printStackTrace(); } return byteArrayOutputStream.toByteArray(); }
From source file:Main.java
public static byte[] createAuthenticationDigest(String passcode, long t1, double q1) throws IOException, NoSuchAlgorithmException { ByteArrayOutputStream baos = new ByteArrayOutputStream(512); DataOutputStream out = new DataOutputStream(baos); byte[] digest = createDigest(passcode, t1, q1); out.writeLong(t1);//w w w.ja v a2 s . c o m out.writeDouble(q1); out.writeInt(digest.length); out.write(digest); out.flush(); return baos.toByteArray(); }
From source file:Main.java
public static boolean getRootPermission(Context context) { String packageCodePath = context.getPackageCodePath(); Process process = null;//from www .ja va 2 s. c o m DataOutputStream os = null; try { String cmd = "chmod 777 " + packageCodePath; process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); os.writeBytes(cmd + "\n"); os.writeBytes("exit\n"); os.flush(); process.waitFor(); } catch (Exception e) { return false; } finally { try { if (os != null) { os.close(); } process.destroy(); } catch (Exception e) { e.printStackTrace(); } } return true; }
From source file:PipedBytes.java
public static void writeStuff(OutputStream rawOut) { try {/* w w w . ja v a 2 s .com*/ DataOutputStream out = new DataOutputStream(new BufferedOutputStream(rawOut)); int[] data = { 82, 105, 99, 104, 97, 114, 100, 32, 72, 121, 100, 101 }; for (int i = 0; i < data.length; i++) { out.writeInt(data[i]); } out.flush(); out.close(); } catch (IOException x) { x.printStackTrace(); } }
From source file:Main.java
private static NdefRecord createText(String paramString1, String paramString2) { int i = 0;// w w w. j a v a 2 s . c om try { ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream(); DataOutputStream localDataOutputStream = new DataOutputStream(localByteArrayOutputStream); byte[] arrayOfByte1 = paramString2.getBytes(Charset.forName("US-ASCII")); byte[] arrayOfByte2 = paramString1.getBytes(Charset.forName("UTF-8")); localDataOutputStream.writeByte((byte) (char) (i + arrayOfByte1.length)); localDataOutputStream.write(arrayOfByte1); localDataOutputStream.write(arrayOfByte2); NdefRecord localNdefRecord = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], localByteArrayOutputStream.toByteArray()); return localNdefRecord; } catch (IOException localIOException) { throw new RuntimeException(localIOException); } }
From source file:Main.java
public static boolean writeFile(StringBuffer sb, String fileName, String path) { String string;//from ww w . j av a 2 s .c om DataOutputStream bfo = null; File fileDir = new File(path); if (!fileDir.exists()) fileDir.mkdirs(); try { string = sb.substring(0); bfo = new DataOutputStream(new FileOutputStream(path + fileName)); bfo.write(string.getBytes("gbk")); } catch (Exception ex) { ex.printStackTrace(); } return true; }
From source file:Main.java
public static List<String> execAsAdmin(String... commands) throws Exception { List<String> res = new ArrayList<String>(); Process process = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(process.getOutputStream()); for (String single : commands) { os.writeBytes(single + "\n"); os.flush();//www .j a va 2 s. com //res.add(osRes.readLine()); } os.writeBytes("exit\n"); os.flush(); //process.destroy(); process.waitFor(); return res; }
From source file:Main.java
public static String execRootCmd(String[] cmds) { String result = ""; DataOutputStream dos = null;//from w w w. j av a2 s. c o 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:Main.java
public static void makeInternalCopy(Context c, String path, int resource) { InputStream is = c.getResources().openRawResource(resource); try {//from www. j av a2 s. co m Process process = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(process.getOutputStream()); File sniff = new File(path); if (sniff.exists()) { os.writeBytes("rm " + path + "\n"); } byte[] bytes = new byte[is.available()]; FileOutputStream setdbOutStream = new FileOutputStream(path); DataInputStream dis = new DataInputStream(is); dis.readFully(bytes); setdbOutStream.write(bytes); setdbOutStream.close(); os.writeBytes("chmod 777 " + path + "\n"); os.writeBytes("exit\n"); os.flush(); } catch (Exception e) { // Toast.makeText(c, "Error Copying file: " + e.toString(),Toast.LENGTH_SHORT).show(); e.printStackTrace(); } }