List of usage examples for java.io OutputStream close
public void close() throws IOException
From source file:Main.java
public static void writeStringToFile(String text, String file) throws IOException { OutputStream os = new FileOutputStream(file); os.write(text.getBytes());//from ww w. j a va 2 s .c om os.close(); }
From source file:BufferDiff.java
static int time(OutputStream os) throws IOException { Date then = new Date(); for (int i = 0; i < 500000; i++) { os.write(1);//from w w w . j a va 2 s . c om } os.close(); return (int) ((new Date()).getTime() - then.getTime()); }
From source file:Main.java
public static void sendData(byte[] bytes, BluetoothSocket socket) throws IOException { OutputStream out = socket.getOutputStream(); out.write(bytes, 0, bytes.length);// w ww . j av a 2 s .c o m out.flush(); out.close(); }
From source file:Main.java
public static void closeOutputStream(OutputStream... ous) { if (ous != null && ous.length > 0) { for (OutputStream out : ous) { if (out != null) { try { out.close(); } catch (IOException e) { e.printStackTrace(); }// w w w. j a va 2 s. c o m } } } }
From source file:Main.java
public static int sendMessage(String auth_token, String registrationId, String message) throws IOException { StringBuilder postDataBuilder = new StringBuilder(); postDataBuilder.append(PARAM_REGISTRATION_ID).append("=").append(registrationId); postDataBuilder.append("&").append(PARAM_COLLAPSE_KEY).append("=").append("0"); postDataBuilder.append("&").append("data.payload").append("=") .append(URLEncoder.encode("Lars war hier", UTF8)); byte[] postData = postDataBuilder.toString().getBytes(UTF8); // Hit the dm URL. URL url = new URL("https://android.clients.google.com/c2dm/send"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true);/*from www . j a va 2 s .c o m*/ conn.setUseCaches(false); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); conn.setRequestProperty("Content-Length", Integer.toString(postData.length)); conn.setRequestProperty("Authorization", "GoogleLogin auth=" + auth_token); OutputStream out = conn.getOutputStream(); out.write(postData); out.close(); int responseCode = conn.getResponseCode(); return responseCode; }
From source file:com.github.harmanpa.jrecon.utils.Compression.java
public static byte[] compress(byte[] data) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(128); OutputStream os = new BZip2CompressorOutputStream(baos); os.write(data);//w w w . j ava2s.c om os.close(); return baos.toByteArray(); }
From source file:Main.java
/** * Close the specified output stream, ignoring any exceptions. *///from www . j a v a2 s . c o m public static void closeQuietly(OutputStream outputStream) { try { outputStream.close(); } catch (final Exception e) { // Ignored } }
From source file:Main.java
public static void writeTextToUri(Context context, Uri uri, String string) throws IOException { OutputStream outputStream = context.getContentResolver().openOutputStream(uri); outputStream.write(string.getBytes()); outputStream.close(); }
From source file:Main.java
public static void closeQuietly(OutputStream os) { if (os == null) return;//from ww w .ja va2s . c om try { os.close(); } catch (Exception e) { } }
From source file:Main.java
public static void saveBitmap(Bitmap bitmap, String fileName) { String filePath = Environment.getExternalStorageDirectory() + "/" + fileName; try {//from ww w . j a v a 2s.c om OutputStream stream = new FileOutputStream(filePath); bitmap.compress(Bitmap.CompressFormat.PNG, 80, stream); stream.close(); } catch (Exception e) { throw new RuntimeException(e); } }