Search in sources :

Example 61 with ZipEntry

use of java.util.zip.ZipEntry in project j2objc by google.

the class OldAndroidZipStreamTest method createUncompressedZip.

private static void createUncompressedZip(ByteArrayOutputStream bytesOut) throws IOException {
    ZipOutputStream out = new ZipOutputStream(bytesOut);
    try {
        long[] crcs = { 0x205fbff3, 0x906fae57L, 0x2c235131 };
        int i;
        for (i = 0; i < 3; i++) {
            byte[] input = makeSampleFile(i);
            ZipEntry newEntry = new ZipEntry("file-" + i);
            if (i != 1)
                newEntry.setComment("this is file " + i);
            newEntry.setMethod(ZipEntry.STORED);
            newEntry.setSize(128 * 1024);
            newEntry.setCrc(crcs[i]);
            out.putNextEntry(newEntry);
            out.write(input, 0, input.length);
            out.closeEntry();
        }
        out.setComment("This is a lovely, but uncompressed, archive!");
    } finally {
        out.close();
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry)

Example 62 with ZipEntry

use of java.util.zip.ZipEntry in project j2objc by google.

the class ZipInputStreamTest method unzip.

public static byte[] unzip(String name, byte[] bytes) throws IOException {
    ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(bytes));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ZipEntry entry = in.getNextEntry();
    assertEquals(name, entry.getName());
    byte[] buffer = new byte[1024];
    int count;
    while ((count = in.read(buffer)) != -1) {
        out.write(buffer, 0, count);
    }
    // There's only one entry in the Zip files we create.
    assertNull(in.getNextEntry());
    in.close();
    return out.toByteArray();
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 63 with ZipEntry

use of java.util.zip.ZipEntry in project j2objc by google.

the class ZipInputStreamTest method testReadEmpty.

/**
     * Reference implementation allows reading of empty zip using a {@link ZipInputStream}.
     */
public void testReadEmpty() throws IOException {
    InputStream emptyZipIn = Support_Resources.getStream("java/util/zip/EmptyArchive.zip");
    ZipInputStream in = new ZipInputStream(emptyZipIn);
    try {
        ZipEntry entry = in.getNextEntry();
        assertNull("An empty zip has no entries", entry);
    } finally {
        in.close();
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry)

Example 64 with ZipEntry

use of java.util.zip.ZipEntry in project j2objc by google.

the class ZipOutputStreamTest method testNullComment.

/** Regression test for null comment causing a NullPointerException during write. */
public void testNullComment() throws IOException {
    ZipOutputStream out = new ZipOutputStream(new ByteArrayOutputStream());
    out.setComment(null);
    out.putNextEntry(new ZipEntry("name"));
    out.write(new byte[1]);
    out.closeEntry();
    out.finish();
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 65 with ZipEntry

use of java.util.zip.ZipEntry in project j2objc by google.

the class ZipEntryTest method testMaxLengthName.

public void testMaxLengthName() throws Exception {
    String maxLengthName = makeString(65535, "z");
    File f = createTemporaryZipFile();
    ZipOutputStream out = createZipOutputStream(f);
    out.putNextEntry(new ZipEntry(maxLengthName));
    out.closeEntry();
    out.close();
    // Read it back, and check that we see the entry.
    ZipFile zipFile = new ZipFile(f);
    assertNotNull(zipFile.getEntry(maxLengthName));
    zipFile.close();
}
Also used : ZipFile(java.util.zip.ZipFile) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

ZipEntry (java.util.zip.ZipEntry)1570 File (java.io.File)526 ZipFile (java.util.zip.ZipFile)523 IOException (java.io.IOException)445 ZipInputStream (java.util.zip.ZipInputStream)361 ZipOutputStream (java.util.zip.ZipOutputStream)357 InputStream (java.io.InputStream)332 FileInputStream (java.io.FileInputStream)321 FileOutputStream (java.io.FileOutputStream)314 BufferedInputStream (java.io.BufferedInputStream)147 JarFile (java.util.jar.JarFile)132 Test (org.junit.Test)129 BufferedOutputStream (java.io.BufferedOutputStream)117 ByteArrayOutputStream (java.io.ByteArrayOutputStream)113 ByteArrayInputStream (java.io.ByteArrayInputStream)101 ArrayList (java.util.ArrayList)92 OutputStream (java.io.OutputStream)76 FileNotFoundException (java.io.FileNotFoundException)69 Enumeration (java.util.Enumeration)63 JarOutputStream (java.util.jar.JarOutputStream)63