List of usage examples for java.io OutputStream close
public void close() throws IOException
From source file:Main.java
private static void closeQuietly(OutputStream output) { try {//from ww w .ja va 2 s. c o m if (output != null) { output.close(); } } catch (IOException ioe) { // ignore } }
From source file:Main.java
public static void closeOutputStream(OutputStream out) { if (out != null) { try {//from w w w . ja v a 2 s .co m out.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:Main.java
public static void writeFile(File file, byte[] data) throws IOException { OutputStream out = new FileOutputStream(file); try {// w w w. j a v a2 s . c om out.write(data); out.flush(); out.close(); } finally { try { out.close(); } catch (IOException ex) { // Do nothing. } } }
From source file:Main.java
public static void connectAndSendHttp(ByteArrayOutputStream baos) { try {// w ww . j av a 2 s . c om URL url; url = new URL("http://10.0.2.2:8080"); String charset = "UTF-8"; HttpURLConnection conn; conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestProperty("Accept-Charset", charset); conn.setRequestProperty("ENCTYPE", "multipart/form-data"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset); OutputStream output = conn.getOutputStream(); output.write(baos.toByteArray()); output.close(); conn.getInputStream(); } catch (IOException e) { e.printStackTrace(); } }
From source file:OutputStreamDemo.java
static void writeints(String msg, int count, OutputStream os) throws IOException { long currentTime = System.currentTimeMillis(); for (int i = 0; i < count; i++) os.write(i & 255);// w w w . j a v a 2s . c o m os.close(); System.out.println(msg + Long.toString(System.currentTimeMillis() - currentTime)); }
From source file:Main.java
public static void writeFully(File file, byte[] data) throws IOException { final OutputStream out = new FileOutputStream(file); try {// w ww . j a v a 2 s . c o m out.write(data); } finally { out.close(); } }
From source file:Main.java
public static void saveBitmap(Bitmap bitmap, String fileName) { long time = System.currentTimeMillis(); String filePath = Environment.getExternalStorageDirectory() + "/" + fileName; try {/*from w ww. j a v a 2s .co m*/ OutputStream stream = new FileOutputStream(filePath); bitmap.compress(Bitmap.CompressFormat.PNG, 80, stream); stream.close(); } catch (Exception e) { throw new RuntimeException(e); } Log.d("artbook", "save bitmap time: " + (System.currentTimeMillis() - time)); }
From source file:Main.java
public static void close(OutputStream output) { if (output != null) { try {//ww w .j av a 2s. c o m output.close(); } catch (IOException e) { closingFailed(e); } } }
From source file:Main.java
public static boolean storePropertyInstance(String filePath, String fileName, Properties p, String comment) { try {//ww w. j a v a2 s . c om File d = new File(filePath); if (!d.exists()) { d.mkdirs(); } File f = new File(d, fileName); if (!f.exists()) { f.createNewFile(); } OutputStream os = new FileOutputStream(f); p.store(os, comment); os.close(); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
From source file:Main.java
static void close(OutputStream outputStream) { if (outputStream != null) { try {/*from w ww.j a v a 2s .c o m*/ outputStream.flush(); outputStream.close(); } catch (IOException e) { // Do nothing } } }