Search in sources :

Example 66 with ZipEntry

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

the class ZipEntryTest method testMaxLengthExtra_zip64.

public void testMaxLengthExtra_zip64() throws Exception {
    // Not quite the max length (65535), but large enough that there's no space
    // for the zip64 extended info header.
    byte[] maxLengthExtra = new byte[65530];
    File f = createTemporaryZipFile();
    ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(f)), true);
    ZipEntry ze = new ZipEntry("x");
    ze.setExtra(maxLengthExtra);
    try {
        out.putNextEntry(ze);
        fail();
    } catch (ZipException expected) {
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) ZipException(java.util.zip.ZipException) ZipFile(java.util.zip.ZipFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 67 with ZipEntry

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

the class ZipEntryTest method testCommentAndExtraInSameOrder.

public void testCommentAndExtraInSameOrder() throws Exception {
    String comment = makeString(17, "z");
    byte[] extra = makeString(11, "a").getBytes();
    File f = createTemporaryZipFile();
    ZipOutputStream out = createZipOutputStream(f);
    // Regular (non zip64) format.
    ZipEntry ze = new ZipEntry("x");
    ze.setSize(0);
    ze.setExtra(extra);
    ze.setComment(comment);
    out.putNextEntry(ze);
    out.closeEntry();
    // An entry without a length is assumed to be zip64.
    ze = new ZipEntry("y");
    ze.setExtra(extra);
    ze.setComment(comment);
    out.putNextEntry(ze);
    out.closeEntry();
    out.close();
    // Read it back and make sure comments and extra are in the right order
    ZipFile zipFile = new ZipFile(f);
    try {
        assertEquals(comment, zipFile.getEntry("x").getComment());
        assertTrue(Arrays.equals(extra, zipFile.getEntry("x").getExtra()));
        assertEquals(comment, zipFile.getEntry("y").getComment());
        assertTrue(Arrays.equals(extra, zipFile.getEntry("y").getExtra()));
    } finally {
        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)

Example 68 with ZipEntry

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

the class ZipEntryTest method testMaxLengthExtra.

public void testMaxLengthExtra() throws Exception {
    byte[] maxLengthExtra = new byte[65535];
    File f = createTemporaryZipFile();
    ZipOutputStream out = createZipOutputStream(f);
    ZipEntry ze = new ZipEntry("x");
    ze.setSize(0);
    ze.setExtra(maxLengthExtra);
    out.putNextEntry(ze);
    out.closeEntry();
    out.close();
    // Read it back, and check that we see the entry.
    ZipFile zipFile = new ZipFile(f);
    assertEquals(maxLengthExtra.length, zipFile.getEntry("x").getExtra().length);
    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)

Example 69 with ZipEntry

use of java.util.zip.ZipEntry in project CoreNLP by stanfordnlp.

the class JarFileChooser method getFiles.

public List<String> getFiles(File jarFile) throws ZipException, IOException {
    //System.out.println("Looking at " + jarFile);
    List<String> files = new ArrayList<>();
    ZipFile zin = new ZipFile(jarFile);
    Enumeration<? extends ZipEntry> entries = zin.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        String name = entry.getName();
        if (name.matches(pattern)) {
            files.add(name);
        }
    }
    Collections.sort(files);
    return files;
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList)

Example 70 with ZipEntry

use of java.util.zip.ZipEntry in project spring-loaded by spring-projects.

the class SubLoader method findResource.

@Override
public URL findResource(String name) {
    try {
        // Look in the folders we care about
        for (int i = 0; i < folders.length; i++) {
            File file = new File(folders[i], name);
            //				System.out.println(file.exists());
            if (file.exists()) {
                return file.toURI().toURL();
            }
        }
        for (int i = 0; i < jars.length; i++) {
            ZipFile zipfile = new ZipFile(jars[i]);
            ZipEntry zipentry = zipfile.getEntry(name);
            if (zipentry != null) {
                return new URL("jar:file:" + new File(jars[i]).getCanonicalPath() + "!/" + name);
            }
            zipfile.close();
        }
        return null;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) ZipFile(java.util.zip.ZipFile) URL(java.net.URL) IOException(java.io.IOException)

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