List of usage examples for java.io DataOutputStream close
@Override public void close() throws IOException
From source file:com.android.volley.stack.HurlStack.java
private static void addBodyIfExists(HttpURLConnection connection, Request<?> request) throws IOException, AuthFailureError { byte[] body = request.getBody(); if (body != null) { connection.setDoOutput(true);/*w w w . j a v a2 s . c o m*/ connection.addRequestProperty(HTTP.CONTENT_TYPE, request.getBodyContentType()); DataOutputStream out = new DataOutputStream(connection.getOutputStream()); out.write(body); out.close(); } }
From source file:com.android.dialer.omni.PlaceUtil.java
/** * Executes a post request and return a JSON object * @param url The API URL/*from w w w . j a v a 2 s. co m*/ * @param data The data to post in POST field * @return the JSON object * @throws IOException * @throws JSONException */ public static JSONObject postJsonRequest(String url, String postData) throws IOException, JSONException { URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("POST"); if (DEBUG) Log.d(TAG, "Posting: " + postData + " to " + url); // Send post request con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(postData); 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(); JSONObject json = new JSONObject(response.toString()); return json; }
From source file:Main.java
public static byte[] getBodyBytes(String ip, String port, String key) throws NumberFormatException, IOException { String[] ipArr = ip.split("\\."); byte[] ipByte = new byte[4]; ipByte[0] = (byte) (Integer.parseInt(ipArr[0]) & 0xFF); ipByte[1] = (byte) (Integer.parseInt(ipArr[1]) & 0xFF); ipByte[2] = (byte) (Integer.parseInt(ipArr[2]) & 0xFF); ipByte[3] = (byte) (Integer.parseInt(ipArr[3]) & 0xFF); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.write(ipByte);//from ww w. j a v a 2s . c o m dos.writeShort(Short.parseShort(port)); dos.writeByte(key.getBytes().length); dos.write(key.getBytes()); byte[] bs = baos.toByteArray(); baos.close(); dos.close(); return bs; }
From source file:Main.java
public static void ExecuteNoReturn(String command, Boolean useroot, boolean forcenew) throws Exception { Process p;//ww w . jav a2 s .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(); }
From source file:Main.java
private static byte[] stringToBytes(String string) { if (string == null) { return null; }//from w w w. j av a 2 s. c o m byte[] buffer = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { dos.writeUTF(string); buffer = baos.toByteArray(); } catch (IOException ex) { } finally { try { baos.close(); dos.close(); } catch (IOException ex1) { } baos = null; dos = null; } return buffer; }
From source file:tachyon.master.Image.java
/** * Write a new image to path. This method assumes having a lock on the master info. * //from www . ja v a 2 s . com * @param info the master info to generate the image * @param path the new image path * @throws IOException */ public static void create(MasterInfo info, String path) throws IOException { String tPath = path + ".tmp"; String parentFolder = path.substring(0, path.lastIndexOf(TachyonURI.SEPARATOR)); LOG.info("Creating the image file: " + tPath); UnderFileSystem ufs = UnderFileSystem.get(path, info.getTachyonConf()); if (!ufs.exists(parentFolder)) { LOG.info("Creating parent folder " + parentFolder); ufs.mkdirs(parentFolder, true); } OutputStream os = ufs.create(tPath); DataOutputStream imageOs = new DataOutputStream(os); ObjectWriter writer = JsonObject.createObjectMapper().writer(); info.writeImage(writer, imageOs); imageOs.flush(); imageOs.close(); LOG.info("Succefully created the image file: " + tPath); ufs.delete(path, false); ufs.rename(tPath, path); ufs.delete(tPath, false); LOG.info("Renamed " + tPath + " to " + path); // safe to close, nothing created here with scope outside function ufs.close(); }
From source file:com.scut.easyfe.network.kjFrame.http.HttpConnectStack.java
/** * body/*from www . j ava 2 s .c om*/ */ private static void addBodyIfExists(HttpURLConnection connection, Request<?> request) throws IOException { byte[] body = request.getBody(); if (body != null) { connection.setDoOutput(true); connection.addRequestProperty(HEADER_CONTENT_TYPE, request.getBodyContentType()); DataOutputStream out = new DataOutputStream(connection.getOutputStream()); out.write(body); out.close(); } }
From source file:PipedBytes.java
public static void writeStuff(OutputStream rawOut) { try {//from w ww .j a v a2s .c om 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:com.flexdesktop.connections.restfulConnection.java
public static void postRequest(HttpURLConnection connection, String data) { DataOutputStream wr = null; try {/*from w ww . j av a2s. 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 {/* w w w . j a v a2s . co m*/ 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); } }