List of usage examples for java.io DataOutputStream flush
public void flush() throws IOException
From source file:Main.java
public static void RunAsRoot(String string) throws IOException { Process P = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(P.getOutputStream()); os.writeBytes(string + "\n"); os.writeBytes("exit\n"); os.flush(); }
From source file:me.sonarbeserk.lockup.utils.UUIDFetcher.java
private static void writeBody(HttpURLConnection connection, String body) throws Exception { DataOutputStream writer = new DataOutputStream(connection.getOutputStream()); writer.write(body.getBytes());//w w w . j av a 2 s. c o m writer.flush(); writer.close(); }
From source file:Main.java
public static void RunAsRootNoOutput(String[] cmds) { try {/*from w ww . ja v a 2s . c o m*/ Process p = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(p.getOutputStream()); for (String tmpCmd : cmds) { os.writeBytes(tmpCmd + "\n"); } os.writeBytes("exit\n"); os.flush(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.meetingninja.csse.database.BaseDatabaseAdapter.java
protected static int sendPostPayload(URLConnection connection, String payload) throws IOException { Log.d(IRequest.POST, "[URL] " + connection.getURL().toString()); logPrint(payload);// w w w. j ava 2 s . co m DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(payload); wr.flush(); wr.close(); return ((HttpURLConnection) connection).getResponseCode(); }
From source file:software.uncharted.util.HTTPUtil.java
public static String post(String urlToRead, String postData) { URL url;/*from w w w .j a v a2 s .c o m*/ HttpURLConnection conn; try { url = new URL(urlToRead); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "application/json"); DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); wr.writeBytes(postData); wr.flush(); wr.close(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; byte[] data = new byte[16384]; InputStream is = conn.getInputStream(); while ((nRead = is.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } buffer.flush(); return buffer.toString(); } catch (Exception e) { e.printStackTrace(); System.err.println("Failed to read URL: " + urlToRead + " <" + e.getMessage() + ">"); } return null; }
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(); }/*from w w w.j a v 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 boolean isRootOk(DataOutputStream output, DataInputStream input, final DataInputStream errInput) { if (output != null) { try {//from www. ja v a2 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:Main.java
public static String do_exec_with_root(String cmd) { String s = "\n"; try {/*from w w w . j a v a2 s . c o m*/ Process su_p = Runtime.getRuntime().exec("su"); DataOutputStream dataOutputStream = new DataOutputStream(su_p.getOutputStream()); dataOutputStream.writeBytes(cmd + "\n"); dataOutputStream.writeBytes("exit" + "\n"); dataOutputStream.flush(); BufferedReader in = new BufferedReader(new InputStreamReader(su_p.getInputStream())); String line = null; while ((line = in.readLine()) != null) { s += line + "\n"; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return s; }
From source file:Main.java
public static String httpPost(String urlStr, List<NameValuePair> params) { String paramsEncoded = ""; if (params != null) { paramsEncoded = URLEncodedUtils.format(params, "UTF-8"); }/* w w w . jav a 2 s . co m*/ String result = null; URL url = null; HttpURLConnection connection = null; InputStreamReader in = null; try { url = new URL(urlStr); connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Charset", "utf-8"); DataOutputStream dop = new DataOutputStream(connection.getOutputStream()); dop.writeBytes(paramsEncoded); dop.flush(); dop.close(); in = new InputStreamReader(connection.getInputStream()); BufferedReader bufferedReader = new BufferedReader(in); StringBuffer strBuffer = new StringBuffer(); String line = null; while ((line = bufferedReader.readLine()) != null) { strBuffer.append(line); } result = strBuffer.toString(); } catch (Exception e) { e.printStackTrace(); } finally { if (connection != null) { connection.disconnect(); } if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; }
From source file:net.technicpack.launchercore.auth.AuthenticationService.java
private static String postJson(String url, String data) throws IOException { byte[] rawData = data.getBytes("UTF-8"); HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setUseCaches(false);// w w w . j a v a2 s . c o m connection.setDoOutput(true); connection.setDoInput(true); connection.setConnectTimeout(15000); connection.setReadTimeout(15000); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json; charset=utf-8"); connection.setRequestProperty("Content-Length", rawData.length + ""); connection.setRequestProperty("Content-Language", "en-US"); DataOutputStream writer = new DataOutputStream(connection.getOutputStream()); writer.write(rawData); writer.flush(); writer.close(); InputStream stream = null; String returnable = null; try { stream = connection.getInputStream(); returnable = IOUtils.toString(stream); } catch (IOException e) { stream = connection.getErrorStream(); if (stream == null) { throw e; } } finally { try { if (stream != null) stream.close(); } catch (IOException e) { } } return returnable; }