Search in sources :

Example 46 with ZipInputStream

use of java.util.zip.ZipInputStream in project robovm by robovm.

the class ZipFileTest method testInflatingStreamsRequiringZipRefill.

public void testInflatingStreamsRequiringZipRefill() throws IOException {
    int originalSize = 1024 * 1024;
    byte[] readBuffer = new byte[8192];
    ZipInputStream in = new ZipInputStream(new FileInputStream(createZipFile(1, originalSize)));
    while (in.getNextEntry() != null) {
        while (in.read(readBuffer, 0, readBuffer.length) != -1) {
        }
    }
    in.close();
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream)

Example 47 with ZipInputStream

use of java.util.zip.ZipInputStream in project robovm by robovm.

the class OldZipInputStreamTest method setUp.

@Override
protected void setUp() throws IOException {
    InputStream is = Support_Resources.getStream("hyts_ZipFile.zip");
    if (is == null) {
        System.out.println("file hyts_ZipFile.zip can not be found");
    }
    zis = new ZipInputStream(is);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ZipOutputStream zos = new ZipOutputStream(bos);
    ZipEntry entry = new ZipEntry("myFile");
    zos.putNextEntry(entry);
    zos.write(dataBytes);
    zos.closeEntry();
    zos.close();
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 48 with ZipInputStream

use of java.util.zip.ZipInputStream in project robovm by robovm.

the class OldZipInputStreamTest method test_closeEntry.

public void test_closeEntry() throws Exception {
    zis.getNextEntry();
    zis.closeEntry();
    zis.getNextEntry();
    zis.close();
    try {
        zis.closeEntry();
        fail("IOException expected");
    } catch (IOException ee) {
    // expected
    }
    File resources = Support_Resources.createTempFolder();
    Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
    FileInputStream fis = new FileInputStream(new File(resources, "Broken_manifest.jar"));
    ZipInputStream zis1 = new ZipInputStream(fis);
    try {
        for (int i = 0; i < 6; i++) {
            zis1.getNextEntry();
            zis1.closeEntry();
        }
        fail("ZipException expected");
    } catch (ZipException ee) {
    // expected
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 49 with ZipInputStream

use of java.util.zip.ZipInputStream in project bazel by bazelbuild.

the class SignedJarBuilder method writeZip.

/**
     * Copies the content of a Jar/Zip archive into the receiver archive.
     * <p/>An optional {@link IZipEntryFilter} allows to selectively choose which files
     * to copy over.
     * @param input the {@link InputStream} for the Jar/Zip to copy.
     * @param filter the filter or <code>null</code>
     * @throws IOException
     * @throws ZipAbortException if the {@link IZipEntryFilter} filter indicated that the write
     *                           must be aborted.
     */
public void writeZip(InputStream input, IZipEntryFilter filter) throws IOException, ZipAbortException {
    ZipInputStream zis = new ZipInputStream(input);
    try {
        // loop on the entries of the intermediary package and put them in the final package.
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            String name = entry.getName();
            // do not take directories
            if (entry.isDirectory()) {
                continue;
            }
            // if we have a filter, we check the entry against it
            if (filter != null && !filter.checkEntry(name)) {
                continue;
            }
            JarEntry newEntry;
            // Preserve the STORED method of the input entry.
            if (entry.getMethod() == JarEntry.STORED) {
                newEntry = new JarEntry(entry);
            } else {
                // Create a new entry so that the compressed len is recomputed.
                newEntry = new JarEntry(name);
            }
            writeEntry(zis, newEntry);
            zis.closeEntry();
        }
    } finally {
        zis.close();
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) JarEntry(java.util.jar.JarEntry)

Example 50 with ZipInputStream

use of java.util.zip.ZipInputStream in project bazel by bazelbuild.

the class ZipCombinerTest method testAddFileAndDuplicateZipEntry.

@Test
public void testAddFileAndDuplicateZipEntry() throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (ZipCombiner zipCombiner = new ZipCombiner(out)) {
        zipCombiner.addFile("hello.txt", ZipCombiner.DOS_EPOCH, asStream("Hello World!"));
        zipCombiner.addZip(sampleZip());
    }
    ZipInputStream zipInput = new ZipInputStream(new ByteArrayInputStream(out.toByteArray()));
    assertEntry(zipInput, "hello.txt", "Hello World!");
    assertNull(zipInput.getNextEntry());
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ZipInputStream (java.util.zip.ZipInputStream)968 ZipEntry (java.util.zip.ZipEntry)762 IOException (java.io.IOException)355 File (java.io.File)319 FileInputStream (java.io.FileInputStream)316 InputStream (java.io.InputStream)203 FileOutputStream (java.io.FileOutputStream)198 ByteArrayInputStream (java.io.ByteArrayInputStream)190 ByteArrayOutputStream (java.io.ByteArrayOutputStream)138 BufferedInputStream (java.io.BufferedInputStream)127 ZipOutputStream (java.util.zip.ZipOutputStream)91 Test (org.junit.Test)89 ArrayList (java.util.ArrayList)80 OutputStream (java.io.OutputStream)67 URL (java.net.URL)58 Path (java.nio.file.Path)58 FileNotFoundException (java.io.FileNotFoundException)56 HashMap (java.util.HashMap)56 BufferedOutputStream (java.io.BufferedOutputStream)54 ZipFile (java.util.zip.ZipFile)43