Example usage for java.util.jar JarEntry getName

List of usage examples for java.util.jar JarEntry getName

Introduction

In this page you can find the example usage for java.util.jar JarEntry getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the entry.

Usage

From source file:org.ow2.proactive_grid_cloud_portal.studio.StudioRest.java

@Override
public ArrayList<String> getClasses(@HeaderParam("sessionid") String sessionId)
        throws NotConnectedRestException {
    String userName = getUserName(sessionId);
    File classesDir = new File(getFileStorageSupport().getWorkflowsDir(userName), "classes");

    ArrayList<String> classes = new ArrayList<>();
    if (classesDir.exists()) {
        File[] jars = classesDir.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.toLowerCase().endsWith(".jar");
            }//from  www .ja  v  a 2 s  .c o m
        });

        for (File jar : jars) {
            try {
                JarFile jarFile = new JarFile(jar.getAbsolutePath());
                Enumeration allEntries = jarFile.entries();
                while (allEntries.hasMoreElements()) {
                    JarEntry entry = (JarEntry) allEntries.nextElement();
                    String name = entry.getName();
                    if (name.endsWith(".class")) {
                        String noExt = name.substring(0, name.length() - ".class".length());
                        classes.add(noExt.replaceAll("/", "."));
                    }
                }

            } catch (IOException e) {
                logger.warn("Could not read jar file " + jar, e);
            }
        }
    }

    return classes;

}

From source file:com.fujitsu.dc.engine.extension.support.ExtensionJarLoader.java

/**
 * jar???JavaScript??? Set??.//from  w w w  .j ava  2 s. c  o m
 * @param jarPaths  jar?
 * @param filter Extension
 * @return Javascript??????Java?
 * @throws IOException ?????/????
 */
@SuppressWarnings("unchecked")
private Set<Class<? extends Scriptable>> loadPrototypeClassSet(List<URL> jarPaths, ExtensionClassFilter filter)
        throws IOException, DcEngineException {
    scriptableClassSet = new HashSet<Class<? extends Scriptable>>();

    for (URL jarUrl : jarPaths) {
        JarFile jar = null;
        try {
            File jarFile = new File(jarUrl.getPath());
            if (jarFile.isDirectory()) {
                continue;
            }
            jar = new JarFile(jarFile);

            for (Enumeration<JarEntry> ent = jar.entries(); ent.hasMoreElements();) {
                JarEntry entry = ent.nextElement();
                String[] pathAndName = resolveJarEntry(entry.getName());
                if (null == pathAndName) {
                    continue;
                }
                String entryPath = pathAndName[0];
                String entryName = pathAndName[1];
                if (null == entryPath || null == entryName) {
                    continue;
                }
                //   jar??"/" ????????
                entryPath = entryPath.replaceAll("\\/", "\\.");
                // ??? JavaScript????? filter??????
                if (filter.accept(entryPath, entryName)) {
                    String className = entryPath + "." + entryName;
                    try {
                        Class<?> cl = classloader.loadClass(className);
                        if (ScriptableObject.class.isAssignableFrom(cl)
                                || Scriptable.class.isAssignableFrom(cl)) {
                            scriptableClassSet.add((Class<? extends Scriptable>) cl);
                            log.info(String.format("Info: Extension class %s is revealed to JavaScript.",
                                    className));
                            // OK.
                            continue;
                        }
                        // ScriptableObject/Scriptable????????JavaScript??????
                        log.info(String.format("Info: Extension class %s is not derived from "
                                + "ScriptableObject class or does not implment Scriptable interface. Ignored.",
                                className));
                    } catch (ClassNotFoundException e) {
                        log.warn(String.format("Warn: Extension class %s is not found in classLoader: %s",
                                className, e.getMessage()), e);
                    } catch (NoClassDefFoundError e) {
                        log.warn(String.format("Warn: Extension class %s is not found in classLoader: %s",
                                className, e.getMessage()), e);
                    } catch (Exception e) {
                        log.warn(String.format("Warn: Extension class %s cannot be loaded into classLoader: %s "
                                + "or the jar content is invalid.", className, e.getMessage()), e);
                    }
                }
            }
        } catch (RuntimeException e) {
            log.warn(String.format("Warn: Failed to handle Extension jar file %s: %s", jarUrl.toString(),
                    e.getMessage()), e);
        } catch (Exception e) {
            log.warn(String.format("Warn: Failed to handle Extension jar file %s: %s", jarUrl.toString(),
                    e.getMessage()), e);
            continue;
        } finally {
            IOUtils.closeQuietly(jar);
        }
    }
    return scriptableClassSet;
}

From source file:com.migratebird.script.repository.impl.ArchiveScriptLocation.java

protected SortedSet<Script> loadScriptsFromJar(final JarFile jarFile, String subPath) {
    SortedSet<Script> scripts = new TreeSet<Script>();
    for (Enumeration<JarEntry> jarEntries = jarFile.entries(); jarEntries.hasMoreElements();) {
        final JarEntry jarEntry = jarEntries.nextElement();
        String fileName = jarEntry.getName();
        if (LOCATION_PROPERTIES_FILENAME.equals(fileName) || !isScriptFileName(fileName)) {
            continue;
        }/*from  w  w w . j  a  v  a 2  s. c  o  m*/

        String relativeScriptName = jarEntry.getName();
        if (subPath != null) {
            if (!fileName.startsWith(subPath)) {
                continue;
            }
            relativeScriptName = relativeScriptName.substring(subPath.length());
        }
        ScriptContentHandle scriptContentHandle = new ScriptContentHandle(scriptEncoding,
                ignoreCarriageReturnsWhenCalculatingCheckSum) {
            @Override
            protected InputStream getScriptInputStream() {
                try {
                    return jarFile.getInputStream(jarEntry);
                } catch (IOException e) {
                    throw new MigrateBirdException("Error while reading jar entry " + jarEntry, e);
                }
            }
        };
        Long fileLastModifiedAt = jarEntry.getTime();
        Script script = scriptFactory.createScriptWithContent(relativeScriptName, fileLastModifiedAt,
                scriptContentHandle);
        scripts.add(script);
    }
    return scripts;
}

From source file:io.personium.engine.extension.support.ExtensionJarLoader.java

/**
 * jar???JavaScript??? Set??.// w  w w . ja v a2s  .  c  om
 * @param jarPaths  jar?
 * @param filter Extension
 * @return Javascript??????Java?
 * @throws IOException ?????/????
 */
@SuppressWarnings("unchecked")
private Set<Class<? extends Scriptable>> loadPrototypeClassSet(List<URL> jarPaths, ExtensionClassFilter filter)
        throws IOException, PersoniumEngineException {
    scriptableClassSet = new HashSet<Class<? extends Scriptable>>();

    for (URL jarUrl : jarPaths) {
        JarFile jar = null;
        try {
            File jarFile = new File(jarUrl.getPath());
            if (jarFile.isDirectory()) {
                continue;
            }
            jar = new JarFile(jarFile);

            for (Enumeration<JarEntry> ent = jar.entries(); ent.hasMoreElements();) {
                JarEntry entry = ent.nextElement();
                String[] pathAndName = resolveJarEntry(entry.getName());
                if (null == pathAndName) {
                    continue;
                }
                String entryPath = pathAndName[0];
                String entryName = pathAndName[1];
                if (null == entryPath || null == entryName) {
                    continue;
                }
                //   jar??"/" ????????
                entryPath = entryPath.replaceAll("\\/", "\\.");
                // ??? JavaScript????? filter??????
                if (filter.accept(entryPath, entryName)) {
                    String className = entryPath + "." + entryName;
                    try {
                        Class<?> cl = classloader.loadClass(className);
                        if (ScriptableObject.class.isAssignableFrom(cl)
                                || Scriptable.class.isAssignableFrom(cl)) {
                            scriptableClassSet.add((Class<? extends Scriptable>) cl);
                            log.info(String.format("Info: Extension class %s is revealed to JavaScript.",
                                    className));
                            // OK.
                            continue;
                        }
                        // ScriptableObject/Scriptable????????JavaScript??????
                        log.info(String.format("Info: Extension class %s is not derived from "
                                + "ScriptableObject class or does not implment Scriptable interface. Ignored.",
                                className));
                    } catch (ClassNotFoundException e) {
                        log.warn(String.format("Warn: Extension class %s is not found in classLoader: %s",
                                className, e.getMessage()), e);
                    } catch (NoClassDefFoundError e) {
                        log.warn(String.format("Warn: Extension class %s is not found in classLoader: %s",
                                className, e.getMessage()), e);
                    } catch (Exception e) {
                        log.warn(String.format("Warn: Extension class %s cannot be loaded into classLoader: %s "
                                + "or the jar content is invalid.", className, e.getMessage()), e);
                    }
                }
            }
        } catch (RuntimeException e) {
            log.warn(String.format("Warn: Failed to handle Extension jar file %s: %s", jarUrl.toString(),
                    e.getMessage()), e);
        } catch (Exception e) {
            log.warn(String.format("Warn: Failed to handle Extension jar file %s: %s", jarUrl.toString(),
                    e.getMessage()), e);
            continue;
        } finally {
            IOUtils.closeQuietly(jar);
        }
    }
    return scriptableClassSet;
}

From source file:org.apache.pig.test.TestJobControlCompiler.java

/**
 * checks if the given file name is in the jar
 * @param jarFile the jar to check/*w  ww  .  ja va2  s .c  o m*/
 * @param name the name to find (full path in the jar)
 * @return true if the name was found
 * @throws IOException
 */
private boolean jarContainsFileNamed(File jarFile, String name) throws IOException {
    Enumeration<JarEntry> entries = new JarFile(jarFile).entries();
    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        if (entry.getName().equals(name)) {
            return true;
        }
    }
    return false;
}

From source file:org.pentaho.pac.server.util.ResolverUtil.java

public void loadImplementationsInJar(String parent, URL jarfile, Test... tests) {
    try {//from  ww  w .  ja  v a 2  s  . c  o  m
        JarEntry entry;
        JarInputStream jarStream = new JarInputStream(jarfile.openStream());
        while ((entry = jarStream.getNextJarEntry()) != null) {
            String name = entry.getName();
            if (!entry.isDirectory() && name.startsWith(parent) && name.endsWith(".class")) { //$NON-NLS-1$
                addIfMatching(name, tests);
            }
        }
    } catch (IOException ioe) {
        log.debug("Could not search jar file \\\'" + jarfile //$NON-NLS-1$
                + "\\\' for classes matching criteria: " + tests //$NON-NLS-1$
                + " due to an IOException", ioe); //$NON-NLS-1$
    }
}

From source file:org.kitodo.serviceloader.KitodoServiceLoader.java

/**
 * Checks, whether a passed jarFile has frontend files or not. Returns true,
 * when the jar contains a folder with the name "resources".
 *
 * @param jarPath//from  www  . jav a  2 s .c om
 *            jarFile that will be checked for frontend files
 * @param destinationFolder
 *            destination path, where the frontend files will be extracted
 *            to
 *
 */
private void extractFrontEndFiles(String jarPath, File destinationFolder) throws IOException {
    if (!destinationFolder.exists()) {
        destinationFolder.mkdir();
    }

    try (JarFile jar = new JarFile(jarPath)) {
        Enumeration jarEntries = jar.entries();
        while (jarEntries.hasMoreElements()) {
            JarEntry currentJarEntry = (JarEntry) jarEntries.nextElement();

            if (currentJarEntry.getName().contains(RESOURCES_FOLDER)
                    || currentJarEntry.getName().contains(POM_PROPERTIES_FILE)) {
                File resourceFile = new File(destinationFolder + File.separator + currentJarEntry.getName());
                if (currentJarEntry.isDirectory()) {
                    resourceFile.mkdirs();
                    continue;
                }
                if (currentJarEntry.getName().contains(POM_PROPERTIES_FILE)) {
                    resourceFile.getParentFile().mkdirs();
                }

                try (InputStream is = jar.getInputStream(currentJarEntry);
                        FileOutputStream fos = new FileOutputStream(resourceFile)) {
                    while (is.available() > 0) {
                        fos.write(is.read());
                    }
                }
            }
        }
    }
}

From source file:com.sachviet.bookman.server.util.ResolverUtil.java

public void loadImplementationsInJar(String parent, URL jarfile, Test... tests) {
    JarInputStream jarStream = null;
    try {//from w w  w  .  j  av  a2s  . c  o  m
        JarEntry entry;
        jarStream = new JarInputStream(jarfile.openStream());
        while ((entry = jarStream.getNextJarEntry()) != null) {
            String name = entry.getName();
            if (!entry.isDirectory() && name.startsWith(parent) && name.endsWith(".class")) { //$NON-NLS-1$
                addIfMatching(name, tests);
            }
        }
    } catch (IOException ioe) {
        LOG.trace("Could not search jar file \\\'" + jarfile //$NON-NLS-1$
                + "\\\' for classes matching criteria: " + tests //$NON-NLS-1$
                + " due to an IOException", ioe); //$NON-NLS-1$
    } finally {
        if (jarStream != null)
            try {
                jarStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
}

From source file:io.fabric8.insight.log.support.LogQuerySupport.java

protected void addJarEntryToIndex(JarEntry entry, StringBuilder buffer) {
    // no need to show empty directories
    if (!entry.isDirectory()) {
        buffer.append(entry.getName());
        buffer.append("\n");
    }//from  ww  w.j  a va 2s .co  m
}

From source file:org.kitesdk.data.hbase.tool.SchemaTool.java

/**
 * Gets the list of HBase Common Avro schema strings from a directory in the
 * Jar. It recursively searches the directory in the jar to find files that
 * end in .avsc to locate thos strings./*ww  w.  ja  va2 s .c  o m*/
 * 
 * @param jarPath
 *          The path to the jar to search
 * @param directoryPath
 *          The directory in the jar to find avro schema strings
 * @return The list of schema strings.
 */
private List<String> getSchemaStringsFromJar(String jarPath, String directoryPath) {
    LOG.info("Getting schema strings in: " + directoryPath + ", from jar: " + jarPath);
    JarFile jar;
    try {
        jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new DatasetException(e);
    } catch (IOException e) {
        throw new DatasetException(e);
    }
    Enumeration<JarEntry> entries = jar.entries();
    List<String> schemaStrings = new ArrayList<String>();
    while (entries.hasMoreElements()) {
        JarEntry jarEntry = entries.nextElement();
        if (jarEntry.getName().startsWith(directoryPath) && jarEntry.getName().endsWith(".avsc")) {
            LOG.info("Found schema: " + jarEntry.getName());
            InputStream inputStream;
            try {
                inputStream = jar.getInputStream(jarEntry);
            } catch (IOException e) {
                throw new DatasetException(e);
            }
            String schemaString = AvroUtils.inputStreamToString(inputStream);
            schemaStrings.add(schemaString);
        }
    }
    return schemaStrings;
}