Search in sources :

Example 6 with IORuntimeException

use of org.apache.aries.util.IORuntimeException in project aries by apache.

the class BundleManifest method fromBundle.

/**
 * Read a manifest from a jar input stream. This will find the manifest even if it is NOT
 * the first file in the archive.
 *
 * @param is the jar input stream
 * @return the bundle manifest
 */
public static BundleManifest fromBundle(InputStream is) {
    JarInputStream jarIs = null;
    try {
        jarIs = new JarInputStream(is);
        Manifest m = jarIs.getManifest();
        if (m != null)
            return new BundleManifest(m);
        else {
            ZipEntry entry;
            while ((entry = jarIs.getNextEntry()) != null) {
                if (entry.getName().equals(MANIFEST_PATH))
                    return new BundleManifest(jarIs);
            }
            return null;
        }
    } catch (IOException e) {
        throw new IORuntimeException("IOException in BundleManifest()", e);
    } finally {
        IOUtils.close(jarIs);
    }
}
Also used : IORuntimeException(org.apache.aries.util.IORuntimeException) JarInputStream(java.util.jar.JarInputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) Manifest(java.util.jar.Manifest)

Aggregations

IORuntimeException (org.apache.aries.util.IORuntimeException)6 IOException (java.io.IOException)5 ZipFile (java.util.zip.ZipFile)4 ZipEntry (java.util.zip.ZipEntry)3 File (java.io.File)2 ZipInputStream (java.util.zip.ZipInputStream)2 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 JarInputStream (java.util.jar.JarInputStream)1 Manifest (java.util.jar.Manifest)1 IDirectory (org.apache.aries.util.filesystem.IDirectory)1 IFile (org.apache.aries.util.filesystem.IFile)1 Test (org.junit.Test)1