Search in sources :

Example 1 with PrefixSet

use of org.forgerock.openam.utils.collections.PrefixSet in project OpenAM by OpenRock.

the class CreateFedlet method extractJars.

private void extractJars(ServletContext servletCtx, String workDir) throws WorkflowException {
    for (final Map.Entry<String, PrefixSet> jarFilter : jarExtracts.entrySet()) {
        final String fileName = jarFilter.getKey();
        final PrefixSet pkgNames = jarFilter.getValue();
        if (StringUtils.isEmpty(fileName)) {
            continue;
        }
        try (JarInputStream jarInputStream = new JarInputStream(servletCtx.getResourceAsStream(fileName));
            JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(workDir + fileName))) {
            JarEntry entry = jarInputStream.getNextJarEntry();
            while (entry != null) {
                if (entry.getSize() != 0) {
                    String name = entry.getName();
                    if (pkgNames.containsPrefixOf(name)) {
                        jarOutputStream.putNextEntry(entry);
                        IOUtils.copyStream(jarInputStream, jarOutputStream);
                    }
                }
                entry = jarInputStream.getNextJarEntry();
            }
        } catch (IOException ex) {
            throw new WorkflowException(ex.getMessage());
        }
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) SimplePrefixSet(org.forgerock.openam.utils.collections.SimplePrefixSet) PrefixSet(org.forgerock.openam.utils.collections.PrefixSet) IOException(java.io.IOException) JarEntry(java.util.jar.JarEntry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 JarEntry (java.util.jar.JarEntry)1 JarInputStream (java.util.jar.JarInputStream)1 JarOutputStream (java.util.jar.JarOutputStream)1 PrefixSet (org.forgerock.openam.utils.collections.PrefixSet)1 SimplePrefixSet (org.forgerock.openam.utils.collections.SimplePrefixSet)1