Examples of JarInputStream


Examples of java.util.jar.JarInputStream

        IResource resource = root.findMember(path);
        if (resource != null) {
            bundlePath = resource.getLocation();
        }

        JarInputStream jarStream = null;
        try {
            jarStream = new JarInputStream(new FileInputStream(bundlePath.toFile()), false);
            Manifest manifest = jarStream.getManifest();
            if (manifest == null) {
                return null;
            }

            Domain domain = Domain.domain(manifest);
View Full Code Here

Examples of java.util.jar.JarInputStream

        }
    }
   
    public String getBundleSymbolicName(File bundleFile) throws IOException {
        String name = null;
        final JarInputStream jis = new JarInputStream(new FileInputStream(bundleFile));
        try {
            final Manifest m = jis.getManifest();
            if(m == null) {
                fail("Manifest is null in " + bundleFile.getAbsolutePath());
            }
            name = m.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
        } finally {
            jis.close();
        }
        return name;
    }
View Full Code Here

Examples of java.util.jar.JarInputStream

        return name;
    }
   
    public String getBundleVersion(File bundleFile) throws IOException {
        String version = null;
        final JarInputStream jis = new JarInputStream(new FileInputStream(bundleFile));
        try {
            final Manifest m = jis.getManifest();
            if(m == null) {
                fail("Manifest is null in " + bundleFile.getAbsolutePath());
            }
            version = m.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
        } finally {
            jis.close();
        }
        return version;
    }
View Full Code Here

Examples of java.util.jar.JarInputStream

        String fileName = file.getName();
        int pos = fileName.indexOf(oldVersion);
        fileName = fileName.substring(0, pos) + newVersion
            + fileName.substring(pos + oldVersion.length());

        JarInputStream jis = null;
        JarOutputStream jos;
        OutputStream out = null;
        try {
            // now create a temporary file and update the version
            final JarFile sourceJar = new JarFile(file);
            final Manifest manifest = sourceJar.getManifest();
            manifest.getMainAttributes().putValue("Bundle-Version", newVersion);

            jis = new JarInputStream(new FileInputStream(file));
            final File destJar = new File(file.getParentFile(), fileName);
            out = new FileOutputStream(destJar);
            jos = new JarOutputStream(out, manifest);

            jos.setMethod(JarOutputStream.DEFLATED);
            jos.setLevel(Deflater.BEST_COMPRESSION);

            JarEntry entryIn = jis.getNextJarEntry();
            while (entryIn != null) {
                JarEntry entryOut = new JarEntry(entryIn.getName());
                entryOut.setTime(entryIn.getTime());
                entryOut.setComment(entryIn.getComment());
                jos.putNextEntry(entryOut);
                if (!entryIn.isDirectory()) {
                    IOUtils.copy(jis, jos);
                }
                jos.closeEntry();
                jis.closeEntry();
                entryIn = jis.getNextJarEntry();
            }

            // close the JAR file now to force writing
            jos.close();
            return destJar;
View Full Code Here

Examples of java.util.jar.JarInputStream

                return;
            }

            FileItem item = items.get(0);

            JarInputStream jar = null;
            InputStream rawInput = null;
            try {
                jar = new JarInputStream(item.getInputStream());
                Manifest manifest = jar.getManifest();
                if (manifest == null) {
                    logAndWriteError("Uploaded jar file does not contain a manifest", resp);
                    return;
                }
View Full Code Here

Examples of java.util.jar.JarInputStream

    public static Resource create(File file) throws IOException {
        return create(file.toURL());
    }

    public static Resource create(URL file) throws IOException {
        JarInputStream jar = null;
        try {
            URLConnection conn = file.openConnection();
            jar = new JarInputStream(conn.getInputStream());
            Manifest manifest = jar.getManifest();
            if (manifest == null) {
                throw new IOException(file + " is not a valid JAR file: Manifest not first entry");
            }
            return new Resource(file, manifest.getMainAttributes(),
                conn.getContentLength());
View Full Code Here

Examples of java.util.jar.JarInputStream

            out.write(buf, 0, rd);
        }
    }

    File spoolModified(InputStream ins) throws IOException {
        JarInputStream jis = new JarInputStream(ins);

        // immediately handle the manifest
        JarOutputStream jos;
        Manifest manifest = jis.getManifest();
        if (manifest == null) {
            throw new IOException("Missing Manifest !");
        }

        String symbolicName = manifest.getMainAttributes().getValue(
            "Bundle-SymbolicName");
        if (symbolicName == null || symbolicName.length() == 0) {
            throw new IOException("Missing Symbolic Name in Manifest !");
        }

        String version = manifest.getMainAttributes().getValue("Bundle-Version");
        Version v = Version.parseVersion(version);
        if (v.getQualifier().indexOf("SNAPSHOT") >= 0) {
            String tStamp;
            synchronized (DATE_FORMAT) {
                tStamp = DATE_FORMAT.format(new Date());
            }
            version = v.getMajor() + "." + v.getMinor() + "." + v.getMicro()
                + "." + v.getQualifier().replaceAll("SNAPSHOT", tStamp);
            manifest.getMainAttributes().putValue("Bundle-Version", version);
        }

        File bundle = new File(this.repoLocation, symbolicName + "-" + v + ".jar");
        OutputStream out = null;
        try {
            out = new FileOutputStream(bundle);
            jos = new JarOutputStream(out, manifest);

            jos.setMethod(JarOutputStream.DEFLATED);
            jos.setLevel(Deflater.BEST_COMPRESSION);

            JarEntry entryIn = jis.getNextJarEntry();
            while (entryIn != null) {
                JarEntry entryOut = new JarEntry(entryIn.getName());
                entryOut.setTime(entryIn.getTime());
                entryOut.setComment(entryIn.getComment());
                jos.putNextEntry(entryOut);
                if (!entryIn.isDirectory()) {
                    spool(jis, jos);
                }
                jos.closeEntry();
                jis.closeEntry();
                entryIn = jis.getNextJarEntry();
            }

            // close the JAR file now to force writing
            jos.close();
View Full Code Here

Examples of java.util.jar.JarInputStream

        final InputStream ins = rsrc.getInputStream();

        Manifest result = null;

        if ( ins != null ) {
            JarInputStream jis = null;
            try {
                jis = new JarInputStream(ins);
                result= jis.getManifest();

                // SLING-2288 : if this is a jar file, but the manifest is not the first entry
                //              log a warning
                if ( rsrc.getURL().endsWith(".jar") && result == null ) {
                    logger.warn("Resource {} does not have the manifest as its first entry in the archive. If this is " +
                                "a bundle, make sure to put the manifest first in the jar file.", rsrc.getURL());
                }
            } finally {

                // close the jar stream or the inputstream, if the jar
                // stream is set, we don't need to close the input stream
                // since closing the jar stream closes the input stream
                if (jis != null) {
                    try {
                        jis.close();
                    } catch (IOException ignore) {
                    }
                } else {
                    try {
                        ins.close();
View Full Code Here

Examples of java.util.jar.JarInputStream

     * @return full qualified paths of the contained files
     * @throws Exception
     */
    private List<String> getContainedFilePaths(URL url) throws Exception
    {
        JarInputStream jis = new JarInputStream(url.openStream());
        ZipEntry zentry = null;
        ArrayList<String> fullNames = new ArrayList<String>();
        while ((zentry = jis.getNextEntry()) != null)
        {
            String name = zentry.getName();
            // Add only files, no directory entries.
            if (!zentry.isDirectory())
            {
                fullNames.add(name);
            }
        }
        jis.close();
        return (fullNames);
    }
View Full Code Here

Examples of java.util.jar.JarInputStream

     * @return full qualified class name
     * @throws IOException
     */
    private String getFullClassName(URL url, String className) throws IOException //throws Exception
    {
        JarInputStream jis = new JarInputStream(url.openStream());
        ZipEntry zentry = null;
        while ((zentry = jis.getNextEntry()) != null)
        {
            String name = zentry.getName();
            int lastPos = name.lastIndexOf(".class");
            if (lastPos < 0)
            {
                continue; // No class file.
            }
            name = name.replace('/', '.');
            int pos = -1;
            int nonCasePos = -1;
            if (className != null)
            {
                pos = name.indexOf(className);
                nonCasePos = name.toLowerCase().indexOf(className.toLowerCase());
            }
            if (pos != -1 && name.length() == pos + className.length() + 6) // "Main" class found
            {
                jis.close();
                return (name.substring(0, lastPos));
            }

            if (nonCasePos != -1 && name.length() == nonCasePos + className.length() + 6)
            // "Main" class with different case found
            {
                throw new IllegalArgumentException("Fatal error! The declared panel name in the xml file ("
                        + className + ") differs in case to the founded class file (" + name + ").");
            }
        }
        jis.close();
        return (null);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.