Search in sources :

Example 86 with JarInputStream

use of java.util.jar.JarInputStream in project Payara by payara.

the class InputJarArchive method getManifest.

/**
 * @return the manifest information for this abstract archive
 */
public Manifest getManifest() throws IOException {
    if (jarFile != null) {
        return jarFile.getManifest();
    }
    if (parentArchive != null) {
        // close the current input stream
        if (jarIS != null) {
            jarIS.close();
        }
        // at the beginning of the desired element
        if (jarIS == null) {
            jarIS = new JarInputStream(parentArchive.jarFile.getInputStream(parentArchive.jarFile.getJarEntry(uri.getSchemeSpecificPart())));
        }
        Manifest m = jarIS.getManifest();
        if (m == null) {
            java.io.InputStream is = getEntry(java.util.jar.JarFile.MANIFEST_NAME);
            if (is != null) {
                m = new Manifest();
                m.read(is);
                is.close();
            }
        }
        return m;
    }
    return null;
}
Also used : JarInputStream(java.util.jar.JarInputStream) java.io(java.io) Manifest(java.util.jar.Manifest)

Example 87 with JarInputStream

use of java.util.jar.JarInputStream in project Payara by payara.

the class InputJarArchive method getSubArchive.

/**
 * @return an Archive for an embedded archive indentified with
 * the name parameter
 */
public ReadableArchive getSubArchive(String name) throws IOException {
    if (jarFile != null) {
        // for now, I only support one level down embedded archives
        InputJarArchive ija = new InputJarArchive();
        JarEntry je = jarFile.getJarEntry(name);
        if (je != null) {
            JarInputStream jis = new JarInputStream(new BufferedInputStream(jarFile.getInputStream(je)));
            try {
                ija.uri = new URI("jar", name, null);
            } catch (URISyntaxException e) {
            // do nothing
            }
            ija.jarIS = jis;
            ija.parentArchive = this;
            return ija;
        }
    }
    return null;
}
Also used : JarInputStream(java.util.jar.JarInputStream) URISyntaxException(java.net.URISyntaxException) JarEntry(java.util.jar.JarEntry) URI(java.net.URI)

Example 88 with JarInputStream

use of java.util.jar.JarInputStream in project Payara by payara.

the class MemoryMappedArchive method getJarEntry.

public JarEntry getJarEntry(String name) {
    try {
        JarInputStream jis = new JarInputStream(new ByteArrayInputStream(file));
        JarEntry ze;
        while ((ze = jis.getNextJarEntry()) != null) {
            if (ze.getName().equals(name)) {
                return ze;
            }
        }
    } catch (IOException e) {
        return null;
    }
    return null;
}
Also used : JarInputStream(java.util.jar.JarInputStream) JarEntry(java.util.jar.JarEntry)

Example 89 with JarInputStream

use of java.util.jar.JarInputStream in project Payara by payara.

the class MemoryMappedArchive method entries.

private Vector<String> entries(boolean directory) {
    Vector entries = new Vector();
    try {
        JarInputStream jis = new JarInputStream(new ByteArrayInputStream(file));
        ZipEntry ze;
        while ((ze = jis.getNextEntry()) != null) {
            if (ze.isDirectory() == directory) {
                entries.add(ze.getName());
            }
        }
        jis.close();
    } catch (IOException ioe) {
        Logger.getAnonymousLogger().log(Level.WARNING, ioe.getMessage(), ioe);
    }
    return entries;
}
Also used : JarInputStream(java.util.jar.JarInputStream) ZipEntry(java.util.zip.ZipEntry) Vector(java.util.Vector)

Example 90 with JarInputStream

use of java.util.jar.JarInputStream in project Payara by payara.

the class InstalledLibrariesResolver method getInstalledLibraries.

public static Set<String> getInstalledLibraries(ReadableArchive archive) throws IOException {
    Set<String> libraries = new HashSet<String>();
    if (archive != null) {
        Manifest manifest = archive.getManifest();
        // we are looking for libraries only in "applibs" directory, hence strict=false
        Set<String> installedLibraries = getInstalledLibraries(archive.getURI().toString(), manifest, false, appLibsDirLibsStore);
        libraries.addAll(installedLibraries);
        // now check my libraries.
        Vector<String> libs = getArchiveLibraries(archive);
        if (libs != null) {
            for (String libUri : libs) {
                JarInputStream jis = null;
                try {
                    InputStream libIs = archive.getEntry(libUri);
                    if (libIs == null) {
                        // libIs can be null if reading an exploded archive where directories are also exploded. See FileArchive.getEntry()
                        continue;
                    }
                    jis = new JarInputStream(libIs);
                    manifest = jis.getManifest();
                    if (manifest != null) {
                        // we are looking for libraries only in "applibs" directory, hence strict=false
                        Set<String> jarLibraries = getInstalledLibraries(archive.getURI().toString(), manifest, false, appLibsDirLibsStore);
                        libraries.addAll(jarLibraries);
                    }
                } finally {
                    if (jis != null)
                        jis.close();
                }
            }
        }
    }
    return libraries;
}
Also used : JarInputStream(java.util.jar.JarInputStream) JarInputStream(java.util.jar.JarInputStream) Manifest(java.util.jar.Manifest)

Aggregations

JarInputStream (java.util.jar.JarInputStream)185 JarEntry (java.util.jar.JarEntry)82 IOException (java.io.IOException)73 FileInputStream (java.io.FileInputStream)66 Manifest (java.util.jar.Manifest)56 File (java.io.File)48 InputStream (java.io.InputStream)45 ZipEntry (java.util.zip.ZipEntry)34 JarOutputStream (java.util.jar.JarOutputStream)29 Test (org.junit.Test)29 FileOutputStream (java.io.FileOutputStream)26 ByteArrayInputStream (java.io.ByteArrayInputStream)24 URL (java.net.URL)20 ArrayList (java.util.ArrayList)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 OutputStream (java.io.OutputStream)14 JarFile (java.util.jar.JarFile)14 BufferedInputStream (java.io.BufferedInputStream)11 Attributes (java.util.jar.Attributes)11 HashSet (java.util.HashSet)9