List of usage examples for java.io BufferedOutputStream BufferedOutputStream
public BufferedOutputStream(OutputStream out)
From source file:Main.java
public static void writeFully(File file, byte[] data) throws IOException { final OutputStream out = new FileOutputStream(file); final BufferedOutputStream bos = new BufferedOutputStream(out); try {// w w w. ja v a 2s . c om bos.write(data); } finally { bos.flush(); bos.close(); } }
From source file:Main.java
public static boolean byte2file(byte[] bytes, File file) { BufferedOutputStream bos = null; FileOutputStream fos = null;/*from w w w . ja v a 2s . c o m*/ try { fos = new FileOutputStream(file); bos = new BufferedOutputStream(fos); bos.write(bytes); return true; } catch (FileNotFoundException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } finally { try { if (bos != null) bos.close(); if (fos != null) fos.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:Main.java
public static OutputStream getOutputStream(File file) { try {// www . j a v a2 s . co m OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); return out; } catch (FileNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static void append(File aFile, String content) { try {/*from w ww. j av a 2 s .c om*/ PrintStream p = new PrintStream(new BufferedOutputStream(new FileOutputStream(aFile, true))); p.println(content); p.close(); } catch (Exception e) { e.printStackTrace(); System.err.println(aFile); } }
From source file:Main.java
public static boolean saveImageTo(Bitmap photo, String spath) { try {/*from w ww . j a va 2 s. c om*/ BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(spath, false)); photo.compress(Bitmap.CompressFormat.PNG, 100, bos); bos.flush(); bos.close(); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:Main.java
public static void saveFile(File f, byte[] content) throws IOException { FileOutputStream fos = new FileOutputStream(f); try {// w w w. jav a2 s . com BufferedOutputStream bos = new BufferedOutputStream(fos); bos.write(content); bos.flush(); } finally { fos.close(); } }
From source file:Main.java
public static void writeTofiles(Context context, Bitmap bitmap, String filename) { BufferedOutputStream outputStream = null; try {/*from www. j a va 2 s .c om*/ outputStream = new BufferedOutputStream(context.openFileOutput(filename, Context.MODE_PRIVATE)); bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:Main.java
public static void writeToFile(InputStream in, File target) throws IOException { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(target)); int count;//from ww w .java2 s . c o m byte data[] = new byte[BUFFER_SIZE]; while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) { bos.write(data, 0, count); } bos.close(); }
From source file:Main.java
public static void saveBitmapToFile(Bitmap bitmap, File file) { try {/* w ww .jav a2 s. c o m*/ BufferedOutputStream bStream = new BufferedOutputStream(new FileOutputStream(file)); bitmap.compress(CompressFormat.JPEG, 100, bStream); bStream.flush(); bStream.close(); bitmap.recycle(); } catch (IOException e) { // Log.d(TAG, e.toString()); } }
From source file:Util.java
public static void download(URL url, File to) throws IOException { BufferedInputStream in = new BufferedInputStream(url.openStream()); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(to)); int bit = -1; while ((bit = in.read()) != -1) { out.write(bit);/*from w w w . ja va2 s. c o m*/ } in.close(); out.close(); }