Example usage for java.io FileOutputStream write

List of usage examples for java.io FileOutputStream write

Introduction

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

Prototype

public void write(byte b[]) throws IOException 

Source Link

Document

Writes b.length bytes from the specified byte array to this file output stream.

Usage

From source file:com.folio3.parse.MainActivity.java

public static void writeLogToFile(Context context, String alert) {
    String eol = System.getProperty("line.separator");
    BufferedWriter writer = null;
    try {/*  w  w w .j av  a2 s.  c om*/
        FileOutputStream openFileOutput = context.openFileOutput(FILE, Context.MODE_APPEND);
        openFileOutput.write((alert + "\r\n").getBytes());
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}

From source file:net.firejack.platform.core.utils.SecurityHelper.java

public static void write64(byte[] data, String name) throws IOException {
    FileOutputStream stream = new FileOutputStream(name);
    stream.write(Base64.encode(data));
    stream.flush();/*from w ww . ja va 2 s .com*/
    stream.close();
}

From source file:Main.java

public static boolean writeFile(String filePath, String content) {
    boolean success = false;
    FileOutputStream fos = null;
    try {/*from  ww  w  .  jav  a 2  s  . com*/
        fos = new FileOutputStream(filePath);
        byte[] byteContent = content.getBytes();
        fos.write(byteContent);

        success = true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (fos != null)
                fos.close();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

    return success;
}

From source file:Main.java

public static void write(InputStream in, File file) {
    if (file.exists()) {
        file.delete();/*from  ww  w.j  av  a 2  s . c  o  m*/
    }
    try {
        file.createNewFile();
        FileOutputStream out = new FileOutputStream(file);
        byte[] buffer = new byte[1024];
        while (in.read(buffer) > -1) {
            out.write(buffer);
        }
        out.flush();
        in.close();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String saveImageToTemporaryDirectory(Bitmap image) {
    Log.d(TAG, "[AirImagePickerUtils] Entering saveImageToTemporaryDirectory");
    String path = "";
    FileOutputStream outputStream;
    try {//from   w  ww  . j  ava  2  s  .co m
        File file = getTemporaryFile(".jpg");
        outputStream = new FileOutputStream(file);
        outputStream.write(getJPEGRepresentationFromBitmap(image));
        outputStream.close();
        path = file.getAbsolutePath();
        Log.d(TAG, "[AirImagePickerUtils] saveImageToTemporaryDirectory path:" + path);
    } catch (IOException e) {
        Log.e(TAG, "[AirImagePickerUtils] saveImageToTemporaryDirectory error:" + e.toString());
        // Error while creating file
    }
    Log.d(TAG, "[AirImagePickerUtils] Exiting saveImageToTemporaryDirectory");
    return path;
}

From source file:MainServer.UploadServlet.java

public static void inputStream2File(InputStream is, String savePath) throws Exception {
    System.out.println("Save path:" + savePath);
    File file = new File(savePath);
    InputStream inputStream = is;
    BufferedInputStream fis = new BufferedInputStream(inputStream);
    FileOutputStream fos = new FileOutputStream(file);
    int f;// w  w w.  jav  a2s.c o m
    while ((f = fis.read()) != -1) {
        fos.write(f);
    }
    fos.flush();
    fos.close();
    fis.close();
    inputStream.close();
}

From source file:Main.java

private static void write(String strLevel, String strTag, String strMessage, Object... args) {
    if (!m_boolWrite)
        return;/* w ww .  j ava2 s. c  o  m*/

    String _strMessage = strMessage;
    if ((strMessage == null) || (strMessage.length() == 0))
        return;

    if (args.length != 0)
        _strMessage = String.format(strMessage, args);

    _strMessage = strLevel + " " + getCurrentTime() + "\t" + strTag + "\t" + _strMessage + "\n";

    File file = new File(m_strLogFilePath + "/" + m_strLogFileName);
    FileOutputStream fos = null;

    try {
        fos = new FileOutputStream(file, true);
        if (fos != null)
            fos.write(_strMessage.getBytes());
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (fos != null)
                fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.feedzai.commons.sql.abstraction.util.AESHelper.java

/**
 * Encrypts the byte[] to a file./*from  ww w . j a v  a2 s. c o  m*/
 *
 * @param path The destination path.
 * @param buf  The buffer.
 * @param key  The key.
 */
public static void encryptToFile(String path, byte[] buf, String key) {
    try {
        FileOutputStream fos = new FileOutputStream(path);
        fos.write(encrypt(buf, key).getBytes());
        fos.close();
    } catch (Exception e) {
        logger.warn("Could not encrypt to file {}", path, e);
    }
}

From source file:com.hernandez.rey.crypto.TripleDES.java

/**
 * Save the specified TripleDES SecretKey to the specified file
 * //from  w  ww  .ja  va2 s  .  co  m
 * @param key the key to write
 * @param keyFile
 * @throws IOException
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeySpecException
 */
public static void writeKey(final SecretKey key, final File keyFile)
        throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
    // Convert the secret key to an array of bytes like this
    final SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("DESede");
    final DESedeKeySpec keyspec = (DESedeKeySpec) keyfactory.getKeySpec(key, DESedeKeySpec.class);
    final byte[] rawkey = keyspec.getKey();

    final byte[] encodedKey = Base64.encodeBase64(rawkey);

    // Write the raw key to the file
    FileOutputStream out = new FileOutputStream(keyFile);
    out.write(encodedKey);
    out.close();

    out = new FileOutputStream(new File(keyFile.toString().concat("-raw")));
    out.write(rawkey);
    out.close();
}

From source file:Main.java

public static boolean saveContentToFile(byte[] content, File fileForSave) {
    ReentrantReadWriteLock.WriteLock writeLock = getLock(fileForSave.getAbsolutePath()).writeLock();
    boolean succeed = true;
    FileOutputStream out = null;
    if (writeLock.tryLock()) {
        try {//from   ww  w  .  j a v a2  s.  c  o m
            out = new FileOutputStream(fileForSave, false);
            out.write(content);
        } catch (Exception var9) {
            //log.d(var9.toString());
            succeed = false;
        } finally {
            if (out != null) {
                closeQuietly(out);
            }

            writeLock.unlock();
        }
    }

    return succeed;
}