Search in sources :

Example 61 with FileOutputStream

use of java.io.FileOutputStream in project bazel by bazelbuild.

the class ZipReaderTest method testSimultaneousReads.

@Test
public void testSimultaneousReads() throws IOException {
    byte[] expectedFooData = "This is file foo. It contains a foo.".getBytes(UTF_8);
    byte[] expectedBarData = "This is a different file bar. It contains only a bar.".getBytes(UTF_8);
    try (ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(test))) {
        ZipEntry foo = new ZipEntry("foo");
        foo.setComment("foo comment.");
        foo.setMethod(ZipEntry.DEFLATED);
        zout.putNextEntry(foo);
        zout.write(expectedFooData);
        zout.closeEntry();
        ZipEntry bar = new ZipEntry("bar");
        bar.setComment("bar comment.");
        bar.setMethod(ZipEntry.DEFLATED);
        zout.putNextEntry(bar);
        zout.write(expectedBarData);
        zout.closeEntry();
    }
    try (ZipReader reader = new ZipReader(test, UTF_8)) {
        ZipFileEntry fooEntry = reader.getEntry("foo");
        ZipFileEntry barEntry = reader.getEntry("bar");
        InputStream fooIn = reader.getInputStream(fooEntry);
        InputStream barIn = reader.getInputStream(barEntry);
        byte[] fooData = new byte[expectedFooData.length];
        byte[] barData = new byte[expectedBarData.length];
        fooIn.read(fooData, 0, 10);
        barIn.read(barData, 0, 10);
        fooIn.read(fooData, 10, 10);
        barIn.read(barData, 10, 10);
        fooIn.read(fooData, 20, fooData.length - 20);
        barIn.read(barData, 20, barData.length - 20);
        assertThat(fooData).isEqualTo(expectedFooData);
        assertThat(barData).isEqualTo(expectedBarData);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) Test(org.junit.Test)

Example 62 with FileOutputStream

use of java.io.FileOutputStream in project bazel by bazelbuild.

the class ZipReaderTest method testZipEntryInvalidTime.

@Test
public void testZipEntryInvalidTime() throws IOException {
    // 11/30/1979 00:00:00, which is also 0 in DOS format
    long date = 312796800000L;
    byte[] extra = new ExtraData((short) 0xaa, new byte[] { (byte) 0xbb, (byte) 0xcd }).getBytes();
    try (ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(test))) {
        ZipEntry foo = new ZipEntry("foo");
        foo.setComment("foo comment.");
        foo.setMethod(ZipEntry.DEFLATED);
        foo.setTime(date);
        foo.setExtra(extra);
        zout.putNextEntry(foo);
        zout.write("foo".getBytes(UTF_8));
        zout.closeEntry();
    }
    try (ZipReader reader = new ZipReader(test, UTF_8)) {
        ZipFileEntry fooEntry = reader.getEntry("foo");
        assertThat(fooEntry.getTime()).isEqualTo(ZipUtil.DOS_EPOCH);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) Test(org.junit.Test)

Example 63 with FileOutputStream

use of java.io.FileOutputStream in project bazel by bazelbuild.

the class ZipReaderTest method testZip64_FileCount_Zip64Range_ForceZip32.

@Test
public void testZip64_FileCount_Zip64Range_ForceZip32() throws IOException {
    try (ZipWriter writer = new ZipWriter(new FileOutputStream(test), UTF_8, false)) {
        ZipFileEntry template = new ZipFileEntry("template");
        template.setSize(0);
        template.setCompressedSize(0);
        template.setCrc(0);
        template.setTime(ZipUtil.DOS_EPOCH);
        for (int i = 0; i < 0x100ff; i++) {
            ZipFileEntry entry = new ZipFileEntry(template);
            entry.setName("entry" + i);
            writer.putNextEntry(entry);
        }
    }
    try (ZipReader reader = new ZipReader(test, UTF_8)) {
        assertThat(reader.size()).isEqualTo(0x100ff);
    }
    try (ZipReader reader = new ZipReader(test, UTF_8, true)) {
        assertThat(reader.size()).isEqualTo(0x00ff);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test)

Example 64 with FileOutputStream

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

the class VAccountManagerService method saveAllAccounts.

/**
	 * Serializing all accounts
	 */
private void saveAllAccounts() {
    File accountFile = VEnvironment.getAccountConfigFile();
    Parcel dest = Parcel.obtain();
    try {
        dest.writeInt(1);
        List<VAccount> accounts = new ArrayList<>();
        for (int i = 0; i < this.accountsByUserId.size(); i++) {
            List<VAccount> list = this.accountsByUserId.valueAt(i);
            if (list != null) {
                accounts.addAll(list);
            }
        }
        dest.writeInt(accounts.size());
        for (VAccount account : accounts) {
            account.writeToParcel(dest, 0);
        }
        dest.writeLong(lastAccountChangeTime);
        FileOutputStream fileOutputStream = new FileOutputStream(accountFile);
        fileOutputStream.write(dest.marshall());
        fileOutputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    dest.recycle();
}
Also used : Parcel(android.os.Parcel) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) File(java.io.File) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

Example 65 with FileOutputStream

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

the class UidSystem method save.

private void save() {
    File uidFile = VEnvironment.getUidListFile();
    File bakUidFile = VEnvironment.getBakUidListFile();
    if (uidFile.exists()) {
        if (bakUidFile.exists() && !bakUidFile.delete()) {
            VLog.w(TAG, "Warning: Unable to delete the expired file --\n " + bakUidFile.getPath());
        }
        try {
            FileUtils.copyFile(uidFile, bakUidFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    try {
        ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(uidFile));
        os.writeInt(mFreeUid);
        os.writeObject(mSharedUserIdMap);
        os.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File)

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