Search in sources :

Example 31 with ZipFile

use of java.util.zip.ZipFile 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)

Example 32 with ZipFile

use of java.util.zip.ZipFile 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 33 with ZipFile

use of java.util.zip.ZipFile 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 34 with ZipFile

use of java.util.zip.ZipFile 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 35 with ZipFile

use of java.util.zip.ZipFile 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

ZipFile (java.util.zip.ZipFile)637 ZipEntry (java.util.zip.ZipEntry)454 File (java.io.File)287 IOException (java.io.IOException)214 InputStream (java.io.InputStream)147 FileOutputStream (java.io.FileOutputStream)108 ZipOutputStream (java.util.zip.ZipOutputStream)92 Test (org.junit.Test)89 FileInputStream (java.io.FileInputStream)68 Enumeration (java.util.Enumeration)47 ArrayList (java.util.ArrayList)46 BufferedInputStream (java.io.BufferedInputStream)44 BufferedOutputStream (java.io.BufferedOutputStream)39 ZipInputStream (java.util.zip.ZipInputStream)35 ZipException (java.util.zip.ZipException)34 OutputStream (java.io.OutputStream)31 ClassReader (org.objectweb.asm.ClassReader)29 FileNotFoundException (java.io.FileNotFoundException)26 JarFile (java.util.jar.JarFile)26 ByteArrayOutputStream (java.io.ByteArrayOutputStream)24