List of usage examples for java.io DataOutputStream close
@Override public void close() throws IOException
From source file:Main.java
public static Process runSuCommandAsync_miracle2(Context context, String command) throws IOException { DataOutputStream fout_miracle2 = new DataOutputStream(context.openFileOutput(SCRIPT_NAME_miracle2, 0)); fout_miracle2.writeBytes(command);//from www. j a va2s .c o m fout_miracle2.close(); String[] args_miracle2 = new String[] { "su", "-c", ". " + context.getFilesDir().getAbsolutePath() + "/" + SCRIPT_NAME_miracle2 }; Process proc_miracle2 = Runtime.getRuntime().exec(args_miracle2); return proc_miracle2; }
From source file:Main.java
public static Process runSuCommandAsync_spica2(Context context, String command) throws IOException { DataOutputStream fout_spica2 = new DataOutputStream(context.openFileOutput(SCRIPT_NAME_spica2, 0)); fout_spica2.writeBytes(command);// ww w. java 2 s . c om fout_spica2.close(); String[] args_spica2 = new String[] { "su", "-c", ". " + context.getFilesDir().getAbsolutePath() + "/" + SCRIPT_NAME_spica2 }; Process proc_spica = Runtime.getRuntime().exec(args_spica2); return proc_spica; }
From source file:Main.java
public static Process runSuCommandAsync_miracle(Context context, String command) throws IOException { DataOutputStream fout_miracle = new DataOutputStream(context.openFileOutput(SCRIPT_NAME_miracle, 0)); fout_miracle.writeBytes(command);/*from w w w. j a va 2s . c om*/ fout_miracle.close(); String[] args_miracle = new String[] { "su", "-c", ". " + context.getFilesDir().getAbsolutePath() + "/" + SCRIPT_NAME_miracle }; Process proc_miracle = Runtime.getRuntime().exec(args_miracle); return proc_miracle; }
From source file:bakuposter.gcm.server.POST2GCMessage.java
public static void post(String apiKey, Content content) { try {/*from w w w . j a v a 2 s. c o m*/ URL url = new URL("https://android.googleapis.com/gcm/send"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Authorization", "key=" + apiKey); conn.setDoOutput(true); ObjectMapper mapper = new ObjectMapper(); System.out.println(content.getRegistration_ids().get(0)); DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); mapper.writeValue(wr, content); wr.flush(); wr.close(); int responseCode = conn.getResponseCode(); System.out.println("responseCode = " + responseCode); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:editor.util.URLUtil.java
public static String sendPost(String url, String data) throws Exception { URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); //add reuqest header con.setRequestMethod("POST"); // Send post request con.setDoOutput(true);// w ww .ja v a 2 s .c om DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(data); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); 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 response.toString(); }
From source file:Main.java
public static String executePost(String url, String parameters) throws IOException { URL request = new URL(url); HttpURLConnection connection = (HttpURLConnection) request.openConnection(); connection.setDoOutput(true);/*w w w . j a v a2s . com*/ connection.setDoInput(true); connection.setInstanceFollowRedirects(false); connection.setRequestMethod("POST"); connection.setRequestProperty("User-Agent", "StripeConnectAndroid"); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("charset", "utf-8"); connection.setRequestProperty("Content-Length", "" + Integer.toString(parameters.getBytes().length)); connection.setUseCaches(false); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(parameters); wr.flush(); wr.close(); String response = streamToString(connection.getInputStream()); connection.disconnect(); return response; }
From source file:com.baran.file.FileOperator.java
public static String storeBinaryContent(byte[] crypted, String inputFile) { String completePath = uniqueNameGenerator(inputFile); try {/*from w w w . java2 s . c om*/ DataOutputStream dos = new DataOutputStream(new FileOutputStream(completePath)); dos.write(crypted); dos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return completePath; }
From source file:Main.java
public static void writeBin(String fileName, byte[] data) { try {/*from ww w . j a v a 2s . co m*/ DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(fileName))); for (byte b : data) { out.writeByte(b); } out.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
private static HttpURLConnection defineHttpsURLConnection(HttpURLConnection connection, JSONObject jsonObject) { try {//from w w w. j a v a 2s . c om connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); /* Add headers to the request */ connection.setRequestProperty("Content-Type", "application/json;charset=utf-8"); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.write(jsonObject.toString().getBytes(Charset.forName("UTF-8"))); wr.flush(); wr.close(); } catch (Exception e) { e.printStackTrace(); } return connection; }
From source file:com.enonic.cms.framework.util.UUIDGenerator.java
/** * Generate random uuid.//from ww w. j a v a 2 s. co m */ public static String randomUUID() { UUID uuid = UUID.randomUUID(); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(out); dataOut.writeLong(uuid.getMostSignificantBits()); dataOut.writeLong(uuid.getLeastSignificantBits()); dataOut.close(); return new String(Hex.encodeHex(out.toByteArray())); } catch (Exception e) { return uuid.toString(); } }