List of usage examples for java.io DataOutputStream close
@Override public void close() throws IOException
From source file:yodlee.ysl.api.io.HTTP.java
public static String doPutNew(String url, String param, Map<String, String> sessionTokens) throws IOException, URISyntaxException { String mn = "doIO(PUT :" + url + ", sessionTokens = " + sessionTokens.toString() + " )"; System.out.println(fqcn + " :: " + mn); //param=param.replace("\"", "%22").replace("{", "%7B").replace("}", "%7D").replace(",", "%2C").replace("[", "%5B").replace("]", "%5D").replace(":", "%3A").replace(" ", "+"); String processedURL = url;//+"?MFAChallenge="+param;//"%7B%22loginForm%22%3A%7B%22formType%22%3A%22token%22%2C%22mfaTimeout%22%3A%2299380%22%2C%22row%22%3A%5B%7B%22id%22%3A%22token_row%22%2C%22label%22%3A%22Security+Key%22%2C%22form%22%3A%220001%22%2C%22fieldRowChoice%22%3A%220001%22%2C%22field%22%3A%5B%7B%22id%22%3A%22token%22%2C%22name%22%3A%22tokenValue%22%2C%22type%22%3A%22text%22%2C%22value%22%3A%22123456%22%2C%22isOptional%22%3Afalse%2C%22valueEditable%22%3Atrue%2C%22maxLength%22%3A%2210%22%7D%5D%7D%5D%7D%7D"; URL myURL = new URL(processedURL); System.out.println(fqcn + " :: " + mn + ": Request URL=" + processedURL.toString()); HttpURLConnection conn = (HttpURLConnection) myURL.openConnection(); conn.setRequestMethod("PUT"); conn.setRequestProperty("Accept-Charset", "UTF-8"); conn.setRequestProperty("Content-Type", contentTypeJSON); conn.setRequestProperty("Authorization", sessionTokens.toString()); conn.setDoOutput(true);// ww w. ja v a 2 s. co m DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); wr.writeBytes(param); wr.flush(); wr.close(); System.out.println(fqcn + " :: " + mn + " : " + "Sending 'HTTP PUT' request"); int responseCode = conn.getResponseCode(); 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) { System.out.println(inputLine); jsonResponse.append(inputLine); } in.close(); System.out.println(fqcn + " :: " + mn + " : " + jsonResponse.toString()); return new String(jsonResponse); }
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);// w w w. j a v a 2s .co m 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:yodlee.ysl.api.io.HTTP.java
public static String doPostUser(String url, Map<String, String> sessionTokens, String requestBody, boolean isEncodingNeeded) throws IOException { String mn = "doIO(POST : " + url + ", " + requestBody + "sessionTokens : " + sessionTokens + " )"; System.out.println(fqcn + " :: " + mn); URL restURL = new URL(url); HttpURLConnection conn = (HttpURLConnection) restURL.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("User-Agent", userAgent); if (isEncodingNeeded) //conn.setRequestProperty("Content-Type", contentTypeURLENCODED); conn.setRequestProperty("Content-Type", contentTypeJSON); else/*from w w w . ja v a2 s . c o m*/ conn.setRequestProperty("Content-Type", "text/plain;charset=UTF-8"); conn.setRequestProperty("Authorization", sessionTokens.toString()); conn.setDoOutput(true); 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:Main.java
public static String executeHttpsPost(String url, String data, InputStream key) { HttpsURLConnection localHttpsURLConnection = null; try {//from ww w . jav a 2 s.c om URL localURL = new URL(url); localHttpsURLConnection = (HttpsURLConnection) localURL.openConnection(); localHttpsURLConnection.setRequestMethod("POST"); localHttpsURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); localHttpsURLConnection.setRequestProperty("Content-Length", "" + Integer.toString(data.getBytes().length)); localHttpsURLConnection.setRequestProperty("Content-Language", "en-US"); localHttpsURLConnection.setUseCaches(false); localHttpsURLConnection.setDoInput(true); localHttpsURLConnection.setDoOutput(true); localHttpsURLConnection.connect(); Certificate[] arrayOfCertificate = localHttpsURLConnection.getServerCertificates(); byte[] arrayOfByte1 = new byte[294]; DataInputStream localDataInputStream = new DataInputStream(key); localDataInputStream.readFully(arrayOfByte1); localDataInputStream.close(); Certificate localCertificate = arrayOfCertificate[0]; PublicKey localPublicKey = localCertificate.getPublicKey(); byte[] arrayOfByte2 = localPublicKey.getEncoded(); for (int i = 0; i < arrayOfByte2.length; i++) { if (arrayOfByte2[i] != arrayOfByte1[i]) throw new RuntimeException("Public key mismatch"); } DataOutputStream localDataOutputStream = new DataOutputStream( localHttpsURLConnection.getOutputStream()); localDataOutputStream.writeBytes(data); localDataOutputStream.flush(); localDataOutputStream.close(); InputStream localInputStream = localHttpsURLConnection.getInputStream(); BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(localInputStream)); StringBuffer localStringBuffer = new StringBuffer(); String str1; while ((str1 = localBufferedReader.readLine()) != null) { localStringBuffer.append(str1); localStringBuffer.append('\r'); } localBufferedReader.close(); return localStringBuffer.toString(); } catch (Exception localException) { byte[] arrayOfByte1; localException.printStackTrace(); return null; } finally { if (localHttpsURLConnection != null) localHttpsURLConnection.disconnect(); } }
From source file:RemoteDeviceDiscovery.java
public static void postDevice(RemoteDevice d) throws Exception { String url = "http://bluetoothdatabase.com/datacollection/"; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); //add reuqest header con.setRequestMethod("POST"); con.setRequestProperty("User-Agent", "blucat"); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); String urlParameters = deviceJson(d); // Send post request con.setDoOutput(true);/*from w ww .j ava2 s. co m*/ DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(urlParameters); 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(); }
From source file:neal.http.impl.httpstack.HurlStack.java
private static void addBodyIfExists(HttpURLConnection connection, Request<?> request) throws IOException, HttpErrorCollection.AuthFailureError { byte[] body = request.getBody(); if (body != null) { connection.setDoOutput(true);//from w w w . ja v a2 s . c o m connection.addRequestProperty(HEADER_CONTENT_TYPE, request.getBodyContentType()); DataOutputStream out = new DataOutputStream(connection.getOutputStream()); out.write(body); out.close(); } }
From source file:Main.java
public static void writeContatctInfo(String accountId, Vector contactInfo, File contactInfoFile) throws IOException { contactInfoFile.getParentFile().mkdirs(); FileOutputStream contactFileOutputStream = new FileOutputStream(contactInfoFile); DataOutputStream out = new DataOutputStream(contactFileOutputStream); out.writeUTF((String) contactInfo.get(0)); out.writeInt(((Integer) (contactInfo.get(1))).intValue()); for (int i = 2; i < contactInfo.size(); ++i) { out.writeUTF((String) contactInfo.get(i)); }/*from w w w .java 2s.c o m*/ out.close(); }
From source file:Main.java
public static void writeInts(String file, int[] ints) throws IOException { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file), 4 * 1024)); try {//from ww w . j a va 2s . c o m int len = ints.length; out.writeInt(len); for (int i = 0; i < len; i++) { out.writeInt(ints[i]); } } finally { out.close(); } }
From source file:net.maxgigapop.mrs.driver.openstack.OpenStackRESTClient.java
private static String sendPOST(URL url, HttpURLConnection con, String body) throws IOException { con.setRequestMethod("POST"); con.setRequestProperty("Content-type", "application/json"); con.setRequestProperty("Accept", "application/json"); con.setDoOutput(true);// w w w . j ava2 s . c o m DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(body); wr.flush(); wr.close(); logger.log(Level.INFO, "Sending POST request to URL : {0}", url); int responseCode = con.getResponseCode(); logger.log(Level.INFO, "Response Code : {0}", responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuilder responseStr = new StringBuilder(); while ((inputLine = in.readLine()) != null) { responseStr.append(inputLine); } in.close(); return responseStr.toString(); }
From source file:Main.java
public static void writeFloats(String file, float[] floats) throws IOException { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file), 4 * 1024)); try {// w ww . j av a 2s. co m int len = floats.length; out.writeInt(len); for (int i = 0; i < len; i++) { out.writeFloat(floats[i]); } } finally { out.close(); } }