List of usage examples for java.io DataOutputStream writeBytes
public final void writeBytes(String s) throws IOException
From source file:org.apache.hadoop.mapred.TestLinuxTaskControllerOtherUserStreamingJob.java
private static void createInput(Path inDir, Configuration conf) throws IOException { FileSystem fs = inDir.getFileSystem(conf); if (!fs.mkdirs(inDir)) { throw new IOException("Failed to create the input directory:" + inDir.toString()); }/*from ww w . j av a 2 s . c o m*/ fs.setPermission(inDir, new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL)); DataOutputStream file = fs.create(new Path(inDir, "data.txt")); int i = 0; while (i++ < 200) { file.writeBytes(i + "\n"); } file.close(); }
From source file:net.technicpack.launchercore.util.Utils.java
public static boolean sendTracking(String category, String action, String label) { String url = "http://www.google-analytics.com/collect"; try {/* w ww.ja va2 s. c om*/ URL urlObj = new URL(url); HttpURLConnection con = (HttpURLConnection) urlObj.openConnection(); con.setRequestMethod("POST"); String urlParameters = "v=1&tid=UA-30896795-3&cid=" + Settings.getClientId() + "&t=event&ec=" + category + "&ea=" + action + "&el=" + label; con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); System.out.println("Analytics Response [" + category + "]: " + responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); return true; } catch (IOException e) { return false; } }
From source file:Main.java
public static void killProcesses(Context context, int pid, String processName) { String cmd = "kill -9 " + pid; String Command = "am force-stop " + processName + "\n"; Process sh = null;/*from w w w. ja v a 2 s .co m*/ DataOutputStream os = null; try { sh = Runtime.getRuntime().exec("su"); os = new DataOutputStream(sh.getOutputStream()); os.writeBytes(Command + "\n"); os.writeBytes(cmd + "\n"); os.writeBytes("exit\n"); os.flush(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { sh.waitFor(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // AbLogUtil.d(AbAppUtil.class, "#kill -9 "+pid); // L.i(processName); ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); String packageName = null; try { if (processName.indexOf(":") == -1) { packageName = processName; } else { packageName = processName.split(":")[0]; } activityManager.killBackgroundProcesses(packageName); // Method forceStopPackage = activityManager.getClass().getDeclaredMethod("forceStopPackage", String.class); forceStopPackage.setAccessible(true); forceStopPackage.invoke(activityManager, packageName); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean getRootPermission(Context context) { String packageCodePath = context.getPackageCodePath(); Process process = null;//from www .j ava 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:com.flexdesktop.connections.restfulConnection.java
public static void postRequest(HttpURLConnection connection, String data) { DataOutputStream wr = null; try {/*ww w.j a va 2 s . co m*/ wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(data); wr.flush(); wr.close(); } catch (IOException ex) { Logger.getLogger(com.flexdesktop.connections.restfulConnection.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:flexpos.restfulConnection.java
public static void postRequest(HttpURLConnection connection, String data) { DataOutputStream wr = null; try {//from www . ja v a 2 s. com wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(data); wr.flush(); wr.close(); } catch (IOException ex) { Logger.getLogger(restfulConnection.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Main.java
public static void execCmd(String cmd) { DataOutputStream dos = null; DataInputStream dis = null;/*from w ww .j a v a2 s. c o m*/ 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:net.technicpack.utilslib.Utils.java
public static boolean sendTracking(String category, String action, String label, String clientId) { String url = "http://www.google-analytics.com/collect"; try {/* ww w . jav a2 s . c o m*/ URL urlObj = new URL(url); HttpURLConnection con = (HttpURLConnection) urlObj.openConnection(); con.setRequestMethod("POST"); String urlParameters = "v=1&tid=UA-30896795-3&cid=" + clientId + "&t=event&ec=" + category + "&ea=" + action + "&el=" + label; con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); Utils.getLogger().info("Analytics Response [" + category + "]: " + responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); return true; } catch (IOException e) { return false; } }
From source file:yodlee.ysl.api.io.HTTP.java
public static String doPost(String url, String requestBody) throws IOException { String mn = "doIO(POST : " + url + ", " + requestBody + " )"; System.out.println(fqcn + " :: " + mn); URL restURL = new URL(url); HttpURLConnection conn = (HttpURLConnection) restURL.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", userAgent); //conn.setRequestProperty("Content-Type", contentTypeURLENCODED); conn.setRequestProperty("Content-Type", contentTypeJSON); conn.setDoOutput(true);// ww w . jav a2 s . c om DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); wr.writeBytes(requestBody); wr.flush(); wr.close(); int responseCode = conn.getResponseCode(); System.out.println(fqcn + " :: " + mn + " : " + "Sending 'HTTP POST' request"); System.out.println(fqcn + " :: " + mn + " : " + "Response Code : " + responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String inputLine; StringBuilder jsonResponse = new StringBuilder(); while ((inputLine = in.readLine()) != null) { jsonResponse.append(inputLine); } in.close(); System.out.println(fqcn + " :: " + mn + " : " + jsonResponse.toString()); return new String(jsonResponse); }
From source file:com.trsst.client.MultiPartRequestEntity.java
private static void writeContent(byte[] content, String contentId, String contentType, DataOutputStream out) throws IOException { if (contentType == null) { throw new NullPointerException("media content type can't be null"); }//from w w w . j av a2 s. co m out.writeBytes("content-type: " + contentType + "\r\n"); out.writeBytes("content-id: <cid:" + contentId + ">\r\n\r\n"); out.write(new Base64().encode(content)); }