List of usage examples for java.io BufferedOutputStream flush
@Override public synchronized void flush() throws IOException
From source file:Main.java
public static void saveFile(File f, byte[] content) throws IOException { FileOutputStream fos = new FileOutputStream(f); try {//from www .j a v a 2 s .c o m BufferedOutputStream bos = new BufferedOutputStream(fos); bos.write(content); bos.flush(); } finally { fos.close(); } }
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 2 s . c o m bos.write(data); } finally { bos.flush(); bos.close(); } }
From source file:Main.java
public static boolean writeBmpToSDCard(Bitmap bmp, File file, int quality) { try {/*from w w w.j a v a2s . c om*/ ByteArrayOutputStream baosm = new ByteArrayOutputStream(); if (file.getPath().toLowerCase(Locale.getDefault()).endsWith(".png")) { bmp.compress(Bitmap.CompressFormat.PNG, quality, baosm); } else { bmp.compress(Bitmap.CompressFormat.JPEG, quality, baosm); } byte[] bts = baosm.toByteArray(); if (file.exists()) { file.delete(); } file.createNewFile(); File tempFile = new File(file.getPath() + ".png"); FileOutputStream fosm = new FileOutputStream(tempFile); BufferedOutputStream bos = new BufferedOutputStream(fosm); bos.write(bts); bos.flush(); bos.close(); fosm.close(); tempFile.renameTo(file); return true; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; }
From source file:Main.java
public static void saveBArrToFile(String fileName, byte[] barr) throws IOException { File file = new File(fileName); file.getParentFile().mkdirs();//w w w. ja v a 2 s. c o m File tempFile = new File(fileName + ".tmp"); FileOutputStream fos = new FileOutputStream(tempFile); BufferedOutputStream bos = new BufferedOutputStream(fos); bos.write(barr, 0, barr.length); bos.flush(); fos.flush(); bos.close(); fos.close(); file.delete(); tempFile.renameTo(file); }
From source file:Main.java
public static void writeData(OutputStream stream, String str) { if (null == stream || TextUtils.isEmpty(str)) { return;//from w w w . j a va2 s.c o m } str = str + "\r\n"; try { BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(stream); bufferedOutputStream.write(str.getBytes()); bufferedOutputStream.flush(); } catch (Exception ex) { ex.printStackTrace(); } finally { } }
From source file:Main.java
public static void saveBitmapToFile(Bitmap bitmap, File file) { try {//from w ww. j a v a2 s .co 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:Main.java
public static void saveBitmapToFile(Bitmap bitmap, String filePath) throws IOException { makeDirsByFilePath(filePath);/*from ww w . j a v a 2 s. com*/ File bitmapFile = new File(filePath); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(bitmapFile)); bitmap.compress(Bitmap.CompressFormat.PNG, 80, bos); bos.flush(); bos.close(); }
From source file:Main.java
public static void saveFile(Bitmap bm, String path, String fileName) throws IOException { String uri = path;//from w w w . jav a2 s .c om if (!uri.endsWith("/")) { uri = uri + "/"; } uri = uri + fileName; File dirFile = new File(path); if (!dirFile.exists()) { dirFile.mkdir(); } File myCaptureFile = new File(uri); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile)); bm.compress(Bitmap.CompressFormat.JPEG, 80, bos); bos.flush(); bos.close(); // SharedPreferences sp= }
From source file:Main.java
public static boolean saveImageTo(Bitmap photo, String spath) { try {// ww w . j a v a 2 s. c o m 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 saveBitmap(Bitmap b) { String path = initPath();//www. ja va 2s .c om SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyyMMdd-hhmmss"); String dataTake = sDateFormat.format(System.currentTimeMillis()); String jpegName = path + "/" + "repair" + ".jpg"; try { FileOutputStream fout = new FileOutputStream(jpegName); BufferedOutputStream bos = new BufferedOutputStream(fout); b.compress(Bitmap.CompressFormat.JPEG, 100, bos); bos.flush(); bos.close(); } catch (IOException e) { e.printStackTrace(); } Log.e("camera", "pic saved jpegName: " + jpegName); }