Example usage for java.io BufferedOutputStream close

List of usage examples for java.io BufferedOutputStream close

Introduction

In this page you can find the example usage for java.io BufferedOutputStream close.

Prototype

@Override
public void close() throws IOException 

Source Link

Document

Closes this output stream and releases any system resources associated with the stream.

Usage

From source file:Main.java

public static void saveBitmapToFile(Bitmap bitmap, String filePath) throws IOException {
    makeDirsByFilePath(filePath);/* w  ww  .jav  a 2  s .  co m*/
    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;//w  w w  .  j a v  a 2s .co  m
    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 File saveBitmap2file(Bitmap bmp) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] byteArray = stream.toByteArray();

    File imageFile = null;//ww w  .ja v a 2s. c om
    try {
        imageFile = File.createTempFile("tempImage" + System.currentTimeMillis(), ".png");
    } catch (IOException e) {
        e.printStackTrace();
    }

    FileOutputStream fstream = null;
    try {
        fstream = new FileOutputStream(imageFile);
        BufferedOutputStream bStream = new BufferedOutputStream(fstream);
        bStream.write(byteArray);
        if (bStream != null) {
            bStream.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return imageFile;

}

From source file:Main.java

public static void saveBArrToFile(String fileName, byte[] barr) throws IOException {
    File file = new File(fileName);
    file.getParentFile().mkdirs();// w ww  . j ava 2  s  .  co 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 writeByteArray(Context context, byte[] data, String fileName) {

    FileOutputStream outputStream;

    try {// w  ww  .j  a  v  a 2s  .c o m
        outputStream = context.openFileOutput(fileName, Context.MODE_PRIVATE);
        BufferedOutputStream bos = new BufferedOutputStream(outputStream);
        for (byte s : data) {
            bos.write(s);
        }
        bos.close();
        outputStream.close();

    } catch (Exception e) {
        Log.e(TAG, e.getMessage(), e);
    }
}

From source file:Main.java

public static void saveBitmapToFile(Bitmap bitmap, File file) {

    try {/*  w w w  .  j av  a  2  s .  c  om*/
        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 boolean saveImageTo(Bitmap photo, String spath) {
    try {//from  ww  w . j a v  a 2s.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();//w w w.  j a v  a 2s . c  o  m

    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);
}

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  ava  2  s . co 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  w w  w. j a  va  2 s.c  om
        }
        file.createNewFile();

        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, bos);
        bos.flush();
        bos.close();
    }
}