Search in sources :

Example 66 with FileOutputStream

use of java.io.FileOutputStream in project VirtualApp by asLody.

the class VJobSchedulerService method saveJobs.

private void saveJobs() {
    File jobFile = VEnvironment.getJobConfigFile();
    Parcel p = Parcel.obtain();
    try {
        p.writeInt(JOB_FILE_VERSION);
        p.writeInt(mJobStore.size());
        for (Map.Entry<JobId, JobConfig> entry : mJobStore.entrySet()) {
            entry.getKey().writeToParcel(p, 0);
            entry.getValue().writeToParcel(p, 0);
        }
        FileOutputStream fos = new FileOutputStream(jobFile);
        fos.write(p.marshall());
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        p.recycle();
    }
}
Also used : Parcel(android.os.Parcel) FileOutputStream(java.io.FileOutputStream) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

Example 67 with FileOutputStream

use of java.io.FileOutputStream in project VirtualApp by asLody.

the class PersistenceLayer method save.

public void save() {
    Parcel p = Parcel.obtain();
    try {
        writeMagic(p);
        p.writeInt(getCurrentVersion());
        writePersistenceData(p);
        FileOutputStream fos = new FileOutputStream(mPersistenceFile);
        fos.write(p.marshall());
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        p.recycle();
    }
}
Also used : Parcel(android.os.Parcel) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

Example 68 with FileOutputStream

use of java.io.FileOutputStream in project VirtualApp by asLody.

the class FileUtils method copyFile.

public static void copyFile(File source, File target) throws IOException {
    FileInputStream inputStream = null;
    FileOutputStream outputStream = null;
    try {
        inputStream = new FileInputStream(source);
        outputStream = new FileOutputStream(target);
        FileChannel iChannel = inputStream.getChannel();
        FileChannel oChannel = outputStream.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        while (true) {
            buffer.clear();
            int r = iChannel.read(buffer);
            if (r == -1)
                break;
            buffer.limit(buffer.position());
            buffer.position(0);
            oChannel.write(buffer);
        }
    } finally {
        closeQuietly(inputStream);
        closeQuietly(outputStream);
    }
}
Also used : FileChannel(java.nio.channels.FileChannel) FileOutputStream(java.io.FileOutputStream) ByteBuffer(java.nio.ByteBuffer) FileInputStream(java.io.FileInputStream)

Example 69 with FileOutputStream

use of java.io.FileOutputStream in project VirtualApp by asLody.

the class FileUtils method writeToFile.

public static void writeToFile(InputStream dataIns, File target) throws IOException {
    final int BUFFER = 1024;
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(target));
    int count;
    byte[] data = new byte[BUFFER];
    while ((count = dataIns.read(data, 0, BUFFER)) != -1) {
        bos.write(data, 0, count);
    }
    bos.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 70 with FileOutputStream

use of java.io.FileOutputStream in project baker-android by bakerframework.

the class Configuration method copyFile.

public static void copyFile(File source, File destination) throws IOException {
    InputStream is = null;
    OutputStream os = null;
    try {
        is = new FileInputStream(source);
        os = new FileOutputStream(destination);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = is.read(buffer)) > 0) {
            os.write(buffer, 0, length);
        }
    } finally {
        if (is != null)
            is.close();
        if (os != null)
            os.close();
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream)

Aggregations

FileOutputStream (java.io.FileOutputStream)6586 File (java.io.File)3769 IOException (java.io.IOException)2864 FileInputStream (java.io.FileInputStream)1189 OutputStream (java.io.OutputStream)1071 BufferedOutputStream (java.io.BufferedOutputStream)907 InputStream (java.io.InputStream)864 FileNotFoundException (java.io.FileNotFoundException)682 OutputStreamWriter (java.io.OutputStreamWriter)644 Test (org.junit.Test)528 BufferedWriter (java.io.BufferedWriter)313 PrintWriter (java.io.PrintWriter)311 ZipEntry (java.util.zip.ZipEntry)311 BufferedInputStream (java.io.BufferedInputStream)287 DataOutputStream (java.io.DataOutputStream)275 ZipOutputStream (java.util.zip.ZipOutputStream)273 ByteArrayOutputStream (java.io.ByteArrayOutputStream)267 ArrayList (java.util.ArrayList)247 Writer (java.io.Writer)215 URL (java.net.URL)206