Example usage for java.io BufferedOutputStream BufferedOutputStream

List of usage examples for java.io BufferedOutputStream BufferedOutputStream

Introduction

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

Prototype

public BufferedOutputStream(OutputStream out) 

Source Link

Document

Creates a new buffered output stream to write data to the specified underlying output stream.

Usage

From source file:Main.java

public static OutputStream openCacheFileForOutput(File root, String... path) throws FileNotFoundException {
    return new BufferedOutputStream(new FileOutputStream(openPath(true, root, path)));
}

From source file:Main.java

public static void writeBeanToXml(String path, Object bean) {
    XMLEncoder encoder = null;/*  w  ww. j a v a  2  s .  c o  m*/
    try {
        // Serialize object into XML
        encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(path)));
        encoder.writeObject(bean);
        encoder.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } finally {
        if (encoder != null) {
            encoder.close();
        }
    }
}

From source file:Main.java

public static void writeData(OutputStream stream, String str) {
    if (null == stream || TextUtils.isEmpty(str)) {
        return;//from w  ww.jav  a  2 s  .c om
    }

    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 boolean bytesToFile(byte[] bfile, File file) {
    BufferedOutputStream bos = null;
    FileOutputStream fos = null;//from  ww  w.  j a va  2  s .  co m
    try {
        fos = new FileOutputStream(file);
        bos = new BufferedOutputStream(fos);
        bos.write(bfile);
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (bos != null) {
            try {
                bos.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    }
    return false;
}

From source file:Main.java

public static void saveBitmapToFile(Bitmap bitmap, String filePath) throws IOException {
    makeDirsByFilePath(filePath);/* ww  w  .j a va 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 boolean saveBitmap(File file, Bitmap bitmap) {
    if (file == null || bitmap == null)
        return false;
    try {//from  w  w w .  j a v a  2s. c om
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
        return bitmap.compress(CompressFormat.JPEG, 100, out);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:TestPipes.java

public static void writeData(OutputStream os) {
    try {//from   w  ww.  j  a  v  a2  s.  c o m
        DataOutputStream out = new DataOutputStream(new BufferedOutputStream(os));

        int[] numArray = { 1, 2, 3, 4, 5 };

        for (int i = 0; i < numArray.length; i++) {
            out.writeInt(numArray[i]);
        }

        out.flush();

        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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  .  ja  v  a2 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 File getFileFromBytes(byte[] b, String outputFile) {
    File ret = null;/* w  w  w . j a v  a 2  s. c  om*/
    BufferedOutputStream stream = null;
    try {
        ret = new File(outputFile);
        FileOutputStream fstream = new FileOutputStream(ret);
        stream = new BufferedOutputStream(fstream);
        stream.write(b);
    } catch (Exception e) {
        // log.error("helper:get file from byte process error!");
        e.printStackTrace();
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
                // log.error("helper:get file from byte process error!");
                e.printStackTrace();
            }
        }
    }
    return ret;
}

From source file:Main.java

private static void saveBitmap(Bitmap bitmap, String fileName) {
    File myCaptureFile = new File(fileName);
    BufferedOutputStream bos;/* w w w  .j a  v  a 2  s  .  c  om*/
    try {
        bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
        bitmap.compress(Bitmap.CompressFormat.PNG, 80, bos);
        bos.flush();
        bos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}