Search in sources :

Example 36 with JarInputStream

use of java.util.jar.JarInputStream in project aries by apache.

the class WarToWabConverterImpl method convert.

private void convert() throws IOException {
    if (wab != null) {
        // WAB is already converted
        return;
    }
    generateManifest();
    CachedOutputStream output = new CachedOutputStream();
    JarOutputStream jarOutput = null;
    JarInputStream jarInput = null;
    ZipEntry entry = null;
    // Copy across all entries from the original jar
    int val;
    try {
        jarOutput = new JarOutputStream(output, wabManifest);
        jarInput = new JarInputStream(input.getInputStream());
        byte[] buffer = new byte[2048];
        while ((entry = jarInput.getNextEntry()) != null) {
            // skip signature files if war is signed
            if (signed && isSignatureFile(entry.getName())) {
                continue;
            }
            jarOutput.putNextEntry(entry);
            while ((val = jarInput.read(buffer)) > 0) {
                jarOutput.write(buffer, 0, val);
            }
        }
    } finally {
        if (jarOutput != null) {
            jarOutput.close();
        }
        if (jarInput != null) {
            jarInput.close();
        }
    }
    wab = output;
}
Also used : JarInputStream(java.util.jar.JarInputStream) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream)

Example 37 with JarInputStream

use of java.util.jar.JarInputStream in project aries by apache.

the class WarToWabConverterImpl method scanRecursive.

private void scanRecursive(final JarInputStream jarInput, boolean topLevel) throws IOException {
    ZipEntry entry;
    while ((entry = jarInput.getNextEntry()) != null) {
        if (entry.getName().endsWith(".class")) {
            PackageFinder pkgFinder = new PackageFinder();
            new ClassReader(jarInput).accept(pkgFinder, ClassReader.SKIP_DEBUG);
            importPackages.addAll(pkgFinder.getImportPackages());
            exemptPackages.addAll(pkgFinder.getExemptPackages());
        } else if (entry.getName().endsWith(".jsp")) {
            Collection<String> thisJSPsImports = JSPImportParser.getImports(jarInput);
            importPackages.addAll(thisJSPsImports);
        } else if (entry.getName().endsWith(".jar")) {
            JarInputStream newJar = new JarInputStream(new InputStream() {

                @Override
                public int read() throws IOException {
                    return jarInput.read();
                }
            });
            // discard return, we only care about the top level jars
            scanRecursive(newJar, false);
            // do not add jar embedded in already embedded jars
            if (topLevel) {
                manifests.put(entry.getName(), newJar.getManifest());
            }
        }
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ClassReader(org.objectweb.asm.ClassReader) Collection(java.util.Collection) IOException(java.io.IOException)

Example 38 with JarInputStream

use of java.util.jar.JarInputStream in project maven-plugins by apache.

the class EvaluateMojo method addAlias.

/**
     * @param xstreamObject not null
     * @param jarFile not null
     * @param packageFilter a package name to filter.
     */
private void addAlias(XStream xstreamObject, File jarFile, String packageFilter) {
    JarInputStream jarStream = null;
    try {
        jarStream = new JarInputStream(new FileInputStream(jarFile));
        for (JarEntry jarEntry = jarStream.getNextJarEntry(); jarEntry != null; jarEntry = jarStream.getNextJarEntry()) {
            if (jarEntry.getName().toLowerCase(Locale.ENGLISH).endsWith(".class")) {
                String name = jarEntry.getName().substring(0, jarEntry.getName().indexOf("."));
                name = name.replaceAll("/", "\\.");
                if (name.contains(packageFilter)) {
                    try {
                        Class<?> clazz = ClassUtils.getClass(name);
                        String alias = StringUtils.lowercaseFirstLetter(clazz.getSimpleName());
                        xstreamObject.alias(alias, clazz);
                        if (!clazz.equals(Model.class)) {
                            // unnecessary field
                            xstreamObject.omitField(clazz, "modelEncoding");
                        }
                    } catch (ClassNotFoundException e) {
                        getLog().error(e);
                    }
                }
            }
            jarStream.closeEntry();
        }
        jarStream.close();
        jarStream = null;
    } catch (IOException e) {
        if (getLog().isDebugEnabled()) {
            getLog().debug("IOException: " + e.getMessage(), e);
        }
    } finally {
        IOUtil.close(jarStream);
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) Model(org.apache.maven.model.Model) IOException(java.io.IOException) JarEntry(java.util.jar.JarEntry) FileInputStream(java.io.FileInputStream)

Example 39 with JarInputStream

use of java.util.jar.JarInputStream in project karaf by apache.

the class BlueprintDeploymentListenerTest method testAppendDescriptorFileExtension.

// KARAF-1617
public void testAppendDescriptorFileExtension() throws Exception {
    final String expectedFileName = "test-fileextension";
    File f = File.createTempFile("smx", ".jar");
    try {
        ZipEntry zipEntry = null;
        OutputStream os = new FileOutputStream(f);
        BlueprintTransformer.transform(getClass().getClassLoader().getResource(expectedFileName), os);
        os.close();
        InputStream is = new FileInputStream(f);
        JarInputStream jar = new JarInputStream(is);
        while (true) {
            zipEntry = jar.getNextEntry();
            if (null == zipEntry) {
                break;
            }
            if (zipEntry.getName() != null && zipEntry.getName().contains(expectedFileName)) {
                break;
            }
        }
        is.close();
        assertNotNull("blueprint service descriptor JAR file entry", zipEntry);
        assertEquals(BLUEPRINT_ENTRY + expectedFileName + ".xml", zipEntry.getName());
    } finally {
        f.delete();
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) JarInputStream(java.util.jar.JarInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 40 with JarInputStream

use of java.util.jar.JarInputStream in project karaf by apache.

the class BlueprintDeploymentListenerTest method testAppendNotTwiceDescriptorFileExtension.

public void testAppendNotTwiceDescriptorFileExtension() throws Exception {
    final String expectedFileName = "test.xml";
    File f = File.createTempFile("smx", ".jar");
    try {
        ZipEntry zipEntry = null;
        OutputStream os = new FileOutputStream(f);
        BlueprintTransformer.transform(getClass().getClassLoader().getResource(expectedFileName), os);
        os.close();
        InputStream is = new FileInputStream(f);
        JarInputStream jar = new JarInputStream(is);
        while (true) {
            zipEntry = jar.getNextEntry();
            if (null == zipEntry) {
                break;
            }
            if (zipEntry.getName() != null && zipEntry.getName().contains(expectedFileName)) {
                break;
            }
        }
        is.close();
        assertNotNull("blueprint service descriptor JAR file entry", zipEntry);
        assertEquals(BLUEPRINT_ENTRY + expectedFileName, zipEntry.getName());
    } finally {
        f.delete();
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) JarInputStream(java.util.jar.JarInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

JarInputStream (java.util.jar.JarInputStream)186 JarEntry (java.util.jar.JarEntry)83 IOException (java.io.IOException)73 FileInputStream (java.io.FileInputStream)67 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)16 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