Example usage for java.io BufferedOutputStream write

List of usage examples for java.io BufferedOutputStream write

Introduction

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

Prototype

@Override
public synchronized void write(int b) throws IOException 

Source Link

Document

Writes the specified byte to this buffered output stream.

Usage

From source file:Main.java

public static void writeFile(byte[] data, File file) throws IOException {
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, false));
    bos.write(data);
    bos.close();/*from  w w  w.j av  a2 s.  c  o  m*/
}

From source file:Main.java

public static void writeFile(byte[] data, File file) {
    try {//  w w w . j av  a2  s . c o  m
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file, false));
        bos.write(data);
        bos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

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;//w w w .  ja  v  a 2 s.c  o m
    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

/**
 * Copy.//from   www. j ava2  s. co  m
 *
 * @param in the in
 * @param out the out
 * @throws IOException Signals that an I/O exception has occurred.
 */
private static void copy(InputStream in, BufferedOutputStream out) throws IOException {
    int byte_;
    while ((byte_ = in.read()) != -1)
        out.write(byte_);
}

From source file:Main.java

public static boolean writeBmpToSDCard(Bitmap bmp, File file, int quality) {
    try {/*from   w  w  w .  j av  a 2 s . c o  m*/
        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: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);
    }//from   ww w.  j a  v a2s.c  o m
    bout.flush();
}

From source file:MainClass.java

public static void blowfishEncrypt(String f1, String f2) throws Exception {
    SecretKey key = null;/*from   w w  w  .j a  v  a 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;/*from   w w w.j av a2  s.c  om*/

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

From source file:Main.java

public static void writeByteArray(Context context, byte[] data, String fileName) {

    FileOutputStream outputStream;

    try {/*from w  w  w  .  j av  a2s  .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: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  .j a  v a  2  s  . c  o m
    in.close();
    out.close();
}