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 boolean saveFile(Bitmap bm, String fileDir, String fileName) {
    try {//from   w  ww  .  j  ava  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 .  ja  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: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   www.ja  v a2 s  .  c o  m
    }
    in.close();
    out.close();
}

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   w ww  .  j a va2 s .  co 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  va2  s . c o  m
        }
        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();//from w w  w .ja v a2  s.  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  w  w.j a  v  a 2s . 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:com.github.khandroid.http.misc.FileDownloader.java

public static void download(HttpClient httpClient, URI source, File destination)
        throws ClientProtocolException, IOException {
    byte[] content = download(httpClient, source);
    ByteArrayInputStream input = new ByteArrayInputStream(content);
    BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(destination));

    IOUtils.copy(input, output);/*from w ww .ja  v a2 s.com*/
    input.close();
    output.close();
}

From source file:MainClass.java

public static void blowfishEncrypt(String f1, String f2) throws Exception {
    SecretKey key = null;/*from   ww w .  ja  va  2s  .c  o m*/

    ObjectInputStream keyFile = new ObjectInputStream(new FileInputStream("BlowfishKey.ser"));
    key = (SecretKey) keyFile.readObject();
    keyFile.close();
    Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
    cipher.init(Cipher.DECRYPT_MODE, key);
    CipherInputStream in = new CipherInputStream(new BufferedInputStream(new FileInputStream(f1)), cipher);
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f2));
    int i;
    do {
        i = in.read();
        if (i != -1)
            out.write(i);
    } while (i > 0);
    in.close();
    out.close();
}

From source file:MainClass.java

public static void desEncrypt(String f1, String f2) throws Exception {
    SecretKey key = null;/*ww w.  ja v  a2  s.  c  o m*/

    ObjectInputStream keyFile = new ObjectInputStream(new FileInputStream("DESKey.ser"));
    key = (SecretKey) keyFile.readObject();
    keyFile.close();
    Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
    cipher.init(Cipher.DECRYPT_MODE, key);
    CipherInputStream in = new CipherInputStream(new BufferedInputStream(new FileInputStream(f1)), cipher);
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f2));
    int i;
    do {
        i = in.read();
        if (i != -1)
            out.write(i);
    } while (i > 0);
    in.close();
    out.close();
}