List of usage examples for java.io BufferedOutputStream flush
@Override public synchronized void flush() throws IOException
From source file:Main.java
public static boolean storeBitmapToFile(Bitmap bitmap, String filePath) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { try {//from w w w.j a v a 2s. c o m BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); bitmap.compress(CompressFormat.PNG, 50, bos); bos.flush(); bos.close(); } catch (Exception e) { return false; } return true; } return false; }
From source file:Main.java
public static void saveImageToSD(Context ctx, String filePath, Bitmap bitmap, int quality) throws IOException { if (bitmap != null) { File file = new File(filePath); File dir = new File(filePath.substring(0, filePath.lastIndexOf(File.separator))); if (!dir.exists()) { dir.mkdirs();//from www. ja va2s .c o m } file.createNewFile(); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); bitmap.compress(Bitmap.CompressFormat.JPEG, quality, bos); bos.flush(); bos.close(); } }
From source file:Main.java
public static boolean saveFile(Bitmap bm, String fileDir, String fileName) { try {//from w w w .j av a 2 s .c o m File dirFile = new File(fileDir); if (!dirFile.exists()) { dirFile.mkdirs(); } File myCaptureFile = new File(fileDir, fileName + ".jpg"); if (myCaptureFile.exists()) { myCaptureFile = new File(fileDir, fileName + System.currentTimeMillis() + ".jpg"); } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile)); bm.compress(CompressFormat.JPEG, 100, bos); bos.flush(); bos.close(); return true; } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static void saveBitmap(Bitmap b) { String path = initPath();//from w w w. j a v a 2 s . c o m SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyyMMdd-hhmmss"); String dataTake = sDateFormat.format(System.currentTimeMillis()); String jpegName = path + "/" + "myImage.jpg"; try { Log.e(TAG, "save pic"); 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(TAG, e.toString()); } Log.e("camera", "pic saved jpegName: " + jpegName); }
From source file:MainClass.java
public static void copy(InputStream in, OutputStream out) throws IOException { BufferedInputStream bin = new BufferedInputStream(in); BufferedOutputStream bout = new BufferedOutputStream(out); while (true) { int datum = bin.read(); if (datum == -1) break; bout.write(datum);/*w w w . j ava 2s . c om*/ } bout.flush(); }
From source file:Main.java
public static String saveFile(Bitmap bm, String dirPath, String fileName, int scale) { File dirFile = new File(dirPath); if (!dirFile.exists()) { dirFile.mkdirs();/*from ww w . ja va 2 s . c o m*/ } File myCaptureFile = new File(dirPath + fileName); try { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile)); bm.compress(Bitmap.CompressFormat.JPEG, scale, bos); bos.flush(); bos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return dirPath + fileName; }
From source file:Main.java
public static void saveImageToSD(Context ctx, String filePath, Bitmap bitmap, int quality) throws IOException { if (bitmap != null) { File file = new File(filePath.substring(0, filePath.lastIndexOf(File.separator))); if (!file.exists()) { file.mkdirs();/*ww w. j a v a2 s .com*/ } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); bitmap.compress(CompressFormat.JPEG, quality, bos); bos.flush(); bos.close(); if (ctx != null) { scanPhoto(ctx, filePath); } } }
From source file:Main.java
public static void saveBackgroundImage(Context ctx, String filePath, Bitmap bitmap, int quality) throws IOException { if (bitmap != null) { File file = new File(filePath.substring(0, filePath.lastIndexOf(File.separator))); if (!file.exists()) { file.mkdirs();/*ww w .j a v a 2s . c o m*/ } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); bitmap.compress(CompressFormat.PNG, quality, bos); bos.flush(); bos.close(); if (ctx != null) { scanPhoto(ctx, filePath); } } }
From source file:Main.java
public static boolean saveFile(Bitmap bm, String path, Bitmap.CompressFormat format) { if (bm == null || path == null) return false; File myCaptureFile = new File(path); if (myCaptureFile.exists()) { myCaptureFile.delete();//from w ww. j a va 2 s . co m } try { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile)); bm.compress(format, 80, bos); bos.flush(); bos.close(); return true; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return false; }
From source file:librarymanagementsystem.Base64Converter.java
/** * This method writes byte array content into a file. *//* w w w .java 2s .com*/ public static void writeByteArraysToFile(String fileName, byte[] content) throws IOException { File file = new File(fileName); BufferedOutputStream writer = new BufferedOutputStream(new FileOutputStream(file)); writer.write(content); writer.flush(); writer.close(); }