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.BibleQuote.utils.FsUtils.java

public static boolean loadContentFromURL(String fromURL, String toFile) {
    try {/*w w  w  .  j a  v a  2s  .c o  m*/
        URL url = new URL("http://bible-desktop.com/xml" + fromURL);
        File file = new File(toFile);

        /* Open a connection to that URL. */
        URLConnection ucon = url.openConnection();

        /* Define InputStreams to read from the URLConnection */
        InputStream is = ucon.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);

        /* Read bytes to the Buffer until there is nothing more to read(-1) */
        ByteArrayBuffer baf = new ByteArrayBuffer(50);
        int current = 0;
        while ((current = bis.read()) != -1) {
            baf.append((byte) current);
        }

        /* Convert the Bytes read to a String. */
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(baf.toByteArray());
        fos.close();

    } catch (IOException e) {
        Log.e(TAG, String.format("loadContentFromURL(%1$s, %2$s)", fromURL, toFile), e);
        return false;
    }

    return true;
}

From source file:ca.tbcn.greenp.GreenParkingApp.java

public static void updateJsonFile(Context context, String contents) throws IOException {
    // write out to local file
    FileOutputStream fos = context.openFileOutput(JSON_FILE_NAME, Context.MODE_PRIVATE);
    fos.write(contents.getBytes());
    fos.close();//from www  .jav  a2s .co  m
}

From source file:Main.java

/**
 * Decompresses a given byte array that is a compressed folder.
 * //from w  w w  .ja va  2s .c o  m
 * @param folderAsCompressedArray to decompress
 * @param unzippedLocation where the decompressed folder should be
 * @throws IOException e
 * @throws FileNotFoundException e
 */
public static void decompressFolderByteArray(byte[] folderAsCompressedArray, File unzippedLocation)
        throws IOException, FileNotFoundException {
    ZipInputStream zipFile = new ZipInputStream(new ByteArrayInputStream(folderAsCompressedArray));
    ZipEntry ze = null;
    final int minusOne = -1;
    while ((ze = zipFile.getNextEntry()) != null) {
        FileOutputStream fout = new FileOutputStream(
                new File(unzippedLocation, ze.getName()).getAbsolutePath());
        for (int c = zipFile.read(); c != minusOne; c = zipFile.read()) {
            fout.write(c);
        }
        zipFile.closeEntry();
        fout.close();
    }
    zipFile.close();
}

From source file:com.xebia.incubator.xebium.ScreenCapture.java

static void writeToFile(final File file, final String output) throws IOException {
    FileOutputStream w = new FileOutputStream(file);
    try {/*from  www  . j  a va2s.c o  m*/
        w.write(Base64.decodeBase64(output));
    } finally {
        try {
            w.close();
        } catch (IOException e) {
            LOG.error("Unable to close screenshot file " + file.getPath(), e);
        }
    }
}

From source file:gov.nih.nci.cabig.caaers.api.BlankFormGenerator.java

public static void testXMLGenaration() {
    Study s;/*from  www .ja  v  a 2s.  c  om*/
    Epoch e;

    BlankFormGenerator g;
    g = new BlankFormGenerator();
    s = new LocalStudy();
    s.setShortTitle("ST");
    s.setLongTitle("LT");
    s.setId(55588);

    s.setIdentifiers(new ArrayList<Identifier>());
    s.getIdentifiers().add(new OrganizationAssignedIdentifier());
    s.getIdentifiers().get(0).setPrimaryIndicator(true);
    s.getIdentifiers().get(0).setValue("VALUE");

    e = new Epoch();
    e.setName("PT");
    e.setDescriptionText("DT");
    e.setId(88);

    SolicitedAdverseEvent sae = new SolicitedAdverseEvent();
    s.addEpoch(e);
    e.addArm(new Arm());
    List<SolicitedAdverseEvent> sael = new ArrayList<SolicitedAdverseEvent>();
    SolicitedAdverseEvent sae1 = new SolicitedAdverseEvent();
    sae1.setCtcterm(new CtcTerm());
    sae1.getCtcterm().setTerm("Nausea");
    sael.add(sae1);

    sae1 = new SolicitedAdverseEvent();
    sae1.setCtcterm(new CtcTerm());
    sae1.getCtcterm().setTerm("Bone Pain");
    sael.add(sae1);

    e.getArms().get(0).setSolicitedAdverseEvents(sael);
    try {
        String xml = g.serialize(s, e);
        FileOutputStream out = new FileOutputStream(XMLFile);
        out.write(xml.getBytes());
        out.close();
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}

From source file:com.amazonaws.encryptionsdk.internal.TestIOUtils.java

public static void generateFile(final String fileName, final long fileSize) throws IOException {
    final FileOutputStream fs = new FileOutputStream(fileName);
    final byte[] fileBytes = new byte[(int) fileSize];
    rng_.nextBytes(fileBytes);/*w  ww  .j av  a 2  s.co m*/
    fs.write(fileBytes);
    fs.close();
}

From source file:com.ginstr.android.service.opencellid.library.data.ApiKeyHandler.java

/**
 * stores newly generated key into the file
 * @param key generated by the server//from  ww w.  j av a2s  . c  om
 * @param testMode Defines in which file the key will be stored
 */
private static void writeApiKeyToFile(String key, boolean testMode) {
    String keyFilePath = testMode ? API_KEY_FILE_TEST_DEFAULT : API_KEY_FILE_DEFAULT;

    File keyFile = new File(keyFilePath);

    try {
        FileOutputStream fos = new FileOutputStream(keyFile, false);
        fos.write(key.getBytes());
        fos.flush();
        fos.close();
    } catch (Exception e) {
        Log.e(ApiKeyHandler.class.getSimpleName(), "Error writing key to file", e);
    }
}

From source file:bobs.mcapisignature.CertUtils.java

public static void dump(byte[] content, String file) {
    try {/*from   w  w  w  .  j  ava2s. com*/
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(content);
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.ibm.zurich.Main.java

private static void writeToFile(byte[] b, String fileName) throws IOException {
    FileOutputStream f = new FileOutputStream(fileName);
    try {//from   w w w . j  a  v a  2 s .c om
        f.write(b);
    } finally {
        if (f != null) {
            f.close();
        }
    }
}

From source file:IORoutines.java

public static void save(File file, byte[] content) throws IOException {
    FileOutputStream out = new FileOutputStream(file);
    try {/*from w w w  .j  a va2  s . c  om*/
        out.write(content);
    } finally {
        out.close();
    }
}