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:Main.java

public static File savePictureInGallery(String albumName, String prefix, byte[] fileBytes) {
    Log.d(TAG, "[AirImagePickerUtils] Entering didSavePictureInGallery");

    long current = System.currentTimeMillis();

    // Save image to album
    File folder = getAlbumFolder(albumName);
    File picture = new File(folder, prefix + "_" + current);

    // Write Image to File
    try {//w w  w .  jav a2 s.  c o m
        FileOutputStream stream = new FileOutputStream(picture);
        stream.write(fileBytes);
        stream.close();
    } catch (Exception exception) {
        Log.d(TAG, "[AirImagePickerUtils] exception = " + exception.getMessage());
        Log.d(TAG, "[AirImagePickerUtils] Exiting didSavePictureInGallery (failed)");
        return null;
    }

    Log.d(TAG, "[AirImagePickerUtils] Exiting didSavePictureInGallery (succeeded)");
    return picture;
}

From source file:Main.java

public static void writeStringToFile(String string, File file) {
    FileOutputStream fos = null;
    try {/*from   w ww.  ja  va 2s  .  c o m*/
        fos = new FileOutputStream(file);
        fos.write(string.getBytes());
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:Main.java

public static boolean delete(File file) {
    file.setWritable(true);/*from w w w . ja v a2s. com*/
    try {
        if (!file.delete()) {
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(0);
            fos.flush();
            fos.close();
        }
        Log.d("delete", "Deleted file: " + file + " successfully");
        return true;
    } catch (IOException e) {
        Log.d("delete", "The deleting file: " + file + " is not successfully", e);
        return false;
    }
}

From source file:org.apache.camel.example.osgi.RmiTest.java

@BeforeClass
public static void setupFreePort() throws Exception {
    // find a free port number, and write that in the custom.properties file
    // which we will use for the unit tests, to avoid port number in use problems
    port = AvailablePortFinder.getNextAvailable();
    String s = "port=" + port;

    File custom = new File("target/custom.properties");
    FileOutputStream fos = new FileOutputStream(custom);
    fos.write(s.getBytes());
    fos.close();//from  w w  w  .ja v  a2  s .c  o  m
}

From source file:ju.ehealthservice.graphs.RespRateGraphImage.java

public static boolean save(String fileName, String img) {
    try {/*w ww. j  a va  2s .  c  o m*/
        StringBuffer data = new StringBuffer(img);
        data = new StringBuffer(data.substring(23));
        int c = 0;
        for (int i = 0; i < data.length(); i++) {
            if (data.charAt(i) == ' ') {
                c++;
                data.setCharAt(i, '+');
            }
        }
        byte[] imageByteArray = Base64.decodeBase64(data.toString());
        String ID = fileName.substring(0, fileName.indexOf('_'));
        String path = Constants.GRAPH_REPOSITORY_PATH + ID + "\\RespRate\\";
        fileName = fileName + ".jpg";
        FileOutputStream imageOutFile = new FileOutputStream(path + fileName);
        imageOutFile.write(imageByteArray);
        imageOutFile.close();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:ju.ehealthservice.graphs.ECGGraphImage.java

public static boolean save(String fileName, String img) {
    try {/*from ww w.j ava2 s.c o m*/
        StringBuffer data = new StringBuffer(img);
        data = new StringBuffer(data.substring(23));
        int c = 0;
        for (int i = 0; i < data.length(); i++) {
            if (data.charAt(i) == ' ') {
                c++;
                data.setCharAt(i, '+');
            }
        }
        byte[] imageByteArray = Base64.decodeBase64(data.toString());
        String ID = fileName.substring(0, fileName.indexOf('_'));
        String path = Constants.GRAPH_REPOSITORY_PATH + ID + "\\ECG\\";
        fileName = fileName + ".jpg";
        FileOutputStream imageOutFile = new FileOutputStream(path + fileName);
        imageOutFile.write(imageByteArray);
        imageOutFile.close();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

/**
 * @param maxSize unit kb/*from   ww  w .  jav a 2  s .c om*/
 */
public static boolean compressSizeToFile(Bitmap bitmap, int maxSize, File outFile) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int quality = 100;
    bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos);
    while (baos.toByteArray().length / 1024.0 > maxSize) {
        if (quality < 30) {
            break;
        }
        quality -= 20;
        baos.reset();
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, baos);
    }
    try {
        FileOutputStream fileOutputStream = new FileOutputStream(outFile);
        fileOutputStream.write(baos.toByteArray());
        fileOutputStream.close();
    } catch (Exception e) {
        return false;
    }
    return true;
}

From source file:Main.java

public static void getWordDocument1(ByteArrayOutputStream recvstram, String filename, String xslfilename)
        throws TransformerConfigurationException, TransformerException, TransformerFactoryConfigurationError {

    try {//  ww w  .  j ava  2  s.c  o m

        byte[] myBytes = recvstram.toByteArray();
        FileOutputStream out = new FileOutputStream("g:/input.txt");
        try {
            out.write(myBytes);
        } finally {
            out.close();
        }
        (TransformerFactory.newInstance().newTransformer(new StreamSource(new File("g:/" + xslfilename))))
                .transform(new StreamSource(new File("g:/input.txt")),
                        new StreamResult(new File("g:/channel.doc")));

    } catch (Exception e) {

    }

}

From source file:Main.java

public static File convertBase64IntoFile(String base64, String path) {
    File dwldsPath = new File(path);
    byte[] pdfAsBytes = convertBase64IntoByte(base64);
    FileOutputStream os;
    try {//from www  .  ja  v  a 2s .  c om
        os = new FileOutputStream(dwldsPath, false);
        os.write(pdfAsBytes);
        os.flush();
        os.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return dwldsPath;
}

From source file:Main.java

public static void writeFileSdcard(String filePath, String content, boolean isAppend) {
    try {/*from  w w w  . j a va 2s .  c o  m*/
        FileOutputStream fout = new FileOutputStream(filePath, isAppend);
        byte[] bytes = content.getBytes();
        fout.write(bytes);
        fout.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}