Search in sources :

Example 46 with JarFile

use of java.util.jar.JarFile in project byte-buddy by raphw.

the class ClassFileLocatorForJarFileTest method testClose.

@Test
public void testClose() throws Exception {
    JarFile jarFile = mock(JarFile.class);
    new ClassFileLocator.ForJarFile(jarFile).close();
    verify(jarFile).close();
    verifyNoMoreInteractions(jarFile);
}
Also used : JarFile(java.util.jar.JarFile) Test(org.junit.Test)

Example 47 with JarFile

use of java.util.jar.JarFile in project robovm by robovm.

the class JarURLConnectionImpl method openJarFile.

private JarFile openJarFile() throws IOException {
    if (jarFileURL.getProtocol().equals("file")) {
        String decodedFile = UriCodec.decode(jarFileURL.getFile());
        return new JarFile(new File(decodedFile), true, ZipFile.OPEN_READ);
    } else {
        final InputStream is = jarFileURL.openConnection().getInputStream();
        try {
            FileOutputStream fos = null;
            JarFile result = null;
            try {
                File tempJar = File.createTempFile("hyjar_", ".tmp", null);
                tempJar.deleteOnExit();
                fos = new FileOutputStream(tempJar);
                byte[] buf = new byte[4096];
                int nbytes = 0;
                while ((nbytes = is.read(buf)) > -1) {
                    fos.write(buf, 0, nbytes);
                }
                fos.close();
                return new JarFile(tempJar, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE);
            } catch (IOException e) {
                return null;
            } finally {
                if (fos != null) {
                    try {
                        fos.close();
                    } catch (IOException ex) {
                        return null;
                    }
                }
            }
        } finally {
            if (is != null) {
                is.close();
            }
        }
    }
}
Also used : FilterInputStream(java.io.FilterInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 48 with JarFile

use of java.util.jar.JarFile in project robovm by robovm.

the class JarFileTest method testConstructor_file.

/**
     * Constructs JarFile object.
     *
     * java.util.jar.JarFile#JarFile(java.io.File)
     * java.util.jar.JarFile#JarFile(java.lang.String)
     */
public void testConstructor_file() throws IOException {
    File f = new File(resources, jarName);
    Support_Resources.copyFile(resources, null, jarName);
    assertTrue(new JarFile(f).getEntry(entryName).getName().equals(entryName));
    assertTrue(new JarFile(f.getPath()).getEntry(entryName).getName().equals(entryName));
}
Also used : JarFile(java.util.jar.JarFile) Support_PlatformFile(tests.support.Support_PlatformFile) JarFile(java.util.jar.JarFile) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 49 with JarFile

use of java.util.jar.JarFile in project robovm by robovm.

the class JarFileTest method test_Inserted_Entry_Manifest_with_DigestCode.

/*
     * If another entry is inserted into Manifest, no security exception will be
     * thrown out.
     */
public void test_Inserted_Entry_Manifest_with_DigestCode() throws IOException {
    String modifiedJarName = "Inserted_Entry_Manifest_with_DigestCode.jar";
    Support_Resources.copyFile(resources, null, modifiedJarName);
    JarFile jarFile = new JarFile(new File(resources, modifiedJarName), true);
    Enumeration<JarEntry> entries = jarFile.entries();
    int count = 0;
    while (entries.hasMoreElements()) {
        ZipEntry zipEntry = entries.nextElement();
        jarFile.getInputStream(zipEntry);
        count++;
    }
    assertEquals(5, count);
}
Also used : ZipEntry(java.util.zip.ZipEntry) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) Support_PlatformFile(tests.support.Support_PlatformFile) JarFile(java.util.jar.JarFile) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 50 with JarFile

use of java.util.jar.JarFile in project robovm by robovm.

the class JarFileTest method test_JarFile_Integrate_Jar.

/* The jar is intact, then everything is all right. */
public void test_JarFile_Integrate_Jar() throws IOException {
    String modifiedJarName = "Integrate.jar";
    Support_Resources.copyFile(resources, null, modifiedJarName);
    JarFile jarFile = new JarFile(new File(resources, modifiedJarName), true);
    Enumeration<JarEntry> entries = jarFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry zipEntry = entries.nextElement();
        jarFile.getInputStream(zipEntry).skip(Long.MAX_VALUE);
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) Support_PlatformFile(tests.support.Support_PlatformFile) JarFile(java.util.jar.JarFile) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Aggregations

JarFile (java.util.jar.JarFile)509 File (java.io.File)289 JarEntry (java.util.jar.JarEntry)230 IOException (java.io.IOException)212 URL (java.net.URL)92 ZipEntry (java.util.zip.ZipEntry)92 InputStream (java.io.InputStream)90 Manifest (java.util.jar.Manifest)81 ZipFile (java.util.zip.ZipFile)74 FileOutputStream (java.io.FileOutputStream)71 Test (org.junit.Test)66 ArrayList (java.util.ArrayList)54 JarURLConnection (java.net.JarURLConnection)48 Attributes (java.util.jar.Attributes)43 JarOutputStream (java.util.jar.JarOutputStream)41 MalformedURLException (java.net.MalformedURLException)31 FileInputStream (java.io.FileInputStream)30 Support_PlatformFile (tests.support.Support_PlatformFile)26 Enumeration (java.util.Enumeration)24 HashSet (java.util.HashSet)20