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:com.kotcrab.vis.editor.module.editor.PluginLoaderModule.java

private void loadJarClasses(URLClassLoader classLoader, PluginDescriptor descriptor,
        Enumeration<JarEntry> entries) throws ClassNotFoundException {
    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        if (entry.isDirectory() || entry.getName().endsWith(".class") == false)
            continue;

        String className = entry.getName().substring(0, entry.getName().length() - ".class".length());
        className = className.replace('/', '.');
        Class<?> clazz = classLoader.loadClass(className);

        if (clazz.getAnnotation(VisPlugin.class) != null)
            descriptor.pluginClasses.add(clazz);
    }//w  ww .j a  va2  s.co m
}

From source file:com.netease.hearttouch.hthotfix.HashTransformExecutor.java

public void transformJar(File inputFile, File outputFile) throws IOException {
    logger.info("HASHTRANSFORMJAR\t" + outputFile.getAbsolutePath());
    final JarFile jar = new JarFile(inputFile);
    final OutputJar outputJar = new OutputJar(outputFile);
    for (final Enumeration<JarEntry> entries = jar.entries(); entries.hasMoreElements();) {
        final JarEntry entry = entries.nextElement();
        if (entry.isDirectory()) {
            //                new File(outFile, entry.getName()).mkdirs();
            continue;
        }/*from  ww  w. ja  va 2s.c  o m*/
        final InputStream is = jar.getInputStream(entry);

        try {
            byte[] bytecode = IOUtils.toByteArray(is);
            if (entry.getName().endsWith(".class")) {
                if (!extension.getGeneratePatch()) {
                    hashFileGenerator.addClass(bytecode);
                    ClassReader cr = new ClassReader(bytecode);

                    outputJar.writeEntry(entry, hackInjector.inject(cr.getClassName(), bytecode));
                } else {
                    outputJar.writeEntry(entry, bytecode);
                }
            } else {
                outputJar.writeEntry(entry, bytecode);
            }
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
    outputJar.close();
}

From source file:edu.stanford.muse.email.JarDocCache.java

public Set<Integer> getAllContentIdxs(String prefix) throws IOException, ClassNotFoundException {
    Set<Integer> result = new LinkedHashSet<Integer>();
    JarFile jarFile = null;//from w ww.  j a v a  2s  . c  om
    String fname = baseDir + File.separator + prefix + ".contents";
    try {
        jarFile = new JarFile(fname);
    } catch (Exception e) {
        log.info("No Jar file exists: " + fname);
    }
    if (jarFile == null)
        return result;

    Enumeration<JarEntry> entries = jarFile.entries();
    String suffix = ".content";
    while (entries.hasMoreElements()) {
        JarEntry je = entries.nextElement();
        String s = je.getName();
        if (!s.endsWith(suffix))
            continue;
        String idx_str = s.substring(0, s.length() - suffix.length());
        int index = -1;
        try {
            index = Integer.parseInt(idx_str);
        } catch (Exception e) {
            log.error("Funny file in header: " + index);
        }

        result.add(index);
    }
    return result;
}

From source file:org.jasig.portal.plugin.deployer.AbstractExtractingEarDeployer.java

/**
 * Deployes an EAR to the container specified in the DeployerConfig. The EAR's
 * applicationContext.xml is parsed and the module/web entries are deployed using
 * {@link #deployWar(WebModule, JarFile, DeployerConfig)}. Then all JARs in the EAR are
 * deployed using {@link #deployJar(JarEntry, JarFile, DeployerConfig)}.
 * //w  ww. j  a v  a2s .c o m
 * @param deployerConfig
 * @throws MojoFailureException 
 * @throws Exception
 */
public final void deploy(DeployerConfig deployerConfig) throws MojoExecutionException, MojoFailureException {
    final JarFile earFile = this.getEarFile(deployerConfig);
    final Document descriptorDom = this.getDescriptorDom(earFile);
    final NodeList webModules = this.getWebModules(descriptorDom);

    //Iterate through the WebModules, deploying each
    for (int index = 0; index < webModules.getLength(); index++) {
        final Node webModuleNode = webModules.item(index);
        final WebModule webModuleInfo = this.getWebModuleInfo(webModuleNode);

        this.deployWar(webModuleInfo, earFile, deployerConfig);
    }

    //Iterate through all the entries in the EAR, deploying each that ends in .jar
    for (final Enumeration<JarEntry> earEntries = earFile.entries(); earEntries.hasMoreElements();) {
        final JarEntry entry = earEntries.nextElement();

        if (entry.getName().endsWith(".jar")) {
            this.deployJar(entry, earFile, deployerConfig);
        }
    }
}

From source file:edu.stanford.muse.email.JarDocCache.java

public Map<Integer, Document> getAllHeaders(String prefix) throws IOException, ClassNotFoundException {
    Map<Integer, Document> result = new LinkedHashMap<Integer, Document>();
    JarFile jarFile = null;// w w w.  ja va 2s.  c  o m
    String fname = baseDir + File.separator + prefix + ".headers";
    try {
        jarFile = new JarFile(fname);
    } catch (Exception e) {
        log.info("No Jar file exists: " + fname);
    }
    if (jarFile == null)
        return result;

    Enumeration<JarEntry> entries = jarFile.entries();
    String suffix = ".header";
    while (entries.hasMoreElements()) {
        JarEntry je = entries.nextElement();
        String s = je.getName();
        if (!s.endsWith(suffix))
            continue;
        String idx_str = s.substring(0, s.length() - suffix.length());
        int index = -1;
        try {
            index = Integer.parseInt(idx_str);
        } catch (Exception e) {
            log.error("Funny file in header: " + index);
        }

        ObjectInputStream ois = new ObjectInputStream(jarFile.getInputStream(je));
        Document ed = (Document) ois.readObject();
        ois.close();
        result.put(index, ed);
    }
    return result;
}

From source file:JarEntryOutputStream.java

/**
 * Removes the given entry from the jar.  If the entry does not exist,
 * the method returns without doing anything.
 *
 * @param entry entry to be removed/*from   www  .  j  a v a2  s .co  m*/
 * @throws IOException if there is a problem writing the changes
 * to the jar
 */
public void removeEntry(JarEntry entry) throws IOException {
    // opens an output stream and closes it without writing anything to it
    if (entry != null && getEntry(entry.getName()) != null) {
        JarEntryOutputStream outputStream = new JarEntryOutputStream(this, entry.getName());

        outputStream.close();
    }
}

From source file:com.izforge.izpack.compiler.packager.impl.Packager.java

private boolean isNotSignedJar(File file) throws IOException {
    JarFile jar = new JarFile(file);
    Enumeration<JarEntry> entries = jar.entries();
    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        if (entry.getName().startsWith("META-INF") && entry.getName().endsWith(".SF")) {
            jar.close();/*from  www  .  ja v a  2s . com*/
            return false;
        }
    }
    jar.close();
    return true;
}

From source file:com.xtructure.xutil.AbstractRunTests.java

/**
 * Processes the given jar resource.//from   w w  w  .j a  va2s.  co  m
 * 
 * @param packageName
 *            the name of the package currently being processed
 * 
 * @param resourceUrl
 *            the URL of the jar resource to process
 */
private final void processJarResource(final String packageName, final URL resourceUrl) {
    try {
        for (final JarEntry jarEntry : Collections
                .list(((JarURLConnection) resourceUrl.openConnection()).getJarFile().entries())) {
            final String className = stripSuffix(makeClassName(jarEntry.getName()));
            if (isTestClassName(packageName, className)) {
                addClass(className);
            }
        }
    } catch (IOException ioEx) {
        throw new RuntimeException("couldn't get entries from jar '" + resourceUrl + "': " + ioEx.getMessage(),
                ioEx);
    }
}

From source file:org.nuxeo.osgi.JarBundleFile.java

@Override
public Enumeration<URL> findEntries(String name, String pattern, boolean recurse) {
    if (name.startsWith("/")) {
        name = name.substring(1);/*from   w ww  .  ja v a 2s . co m*/
    }
    String prefix;
    if (name.length() == 0) {
        name = null;
        prefix = "";
    } else if (!name.endsWith("/")) {
        prefix = name + "/";
    } else {
        prefix = name;
    }
    int len = prefix.length();
    EntryFilter filter = EntryFilter.newFilter(pattern);
    Enumeration<JarEntry> entries = jarFile.entries();
    ArrayList<URL> result = new ArrayList<URL>();
    try {
        while (entries.hasMoreElements()) {
            JarEntry entry = entries.nextElement();
            if (entry.isDirectory()) {
                continue;
            }
            String ename = entry.getName();
            if (name != null && !ename.startsWith(prefix)) {
                continue;
            }
            int i = ename.lastIndexOf('/');
            if (!recurse) {
                if (i > -1) {
                    if (ename.indexOf('/', len) > -1) {
                        continue;
                    }
                }
            }
            String n = i > -1 ? ename.substring(i + 1) : ename;
            if (filter.match(n)) {
                result.add(getEntryUrl(ename));
            }
        }
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
    return Collections.enumeration(result);
}

From source file:org.kantega.revoc.source.MavenSourceArtifactSourceSource.java

private MavenSourceInfo parseInfo(String filePath, URL resource) {

    File file = new File(filePath);

    JarFile jarFile = null;/*from ww  w  .j a va  2  s .  c o m*/
    boolean isNewFile = false;
    try {
        URLConnection urlConnection = resource.openConnection();
        if (urlConnection instanceof JarURLConnection) {
            jarFile = ((JarURLConnection) urlConnection).getJarFile();
        } else {
            jarFile = new JarFile(file);
            isNewFile = true;
        }
        Enumeration<JarEntry> entries = jarFile.entries();
        while (entries.hasMoreElements()) {
            JarEntry entry = entries.nextElement();
            String prefix = "META-INF/maven/";
            String propSuffix = "/pom.properties";

            if (entry.getName().startsWith(prefix) && entry.getName().endsWith(propSuffix)) {
                Properties props = new Properties();
                InputStream inputStream = jarFile.getInputStream(entry);
                props.load(inputStream);
                inputStream.close();
                String groupId = props.getProperty("groupId");
                String artifactId = props.getProperty("artifactId");
                String version = props.getProperty("version");

                if (file.getName().startsWith(artifactId + "-" + version)) {
                    return new MavenSourceInfo(groupId, artifactId, version);
                }

            }
        }
        return null;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        if (isNewFile) {
            if (jarFile != null) {
                try {
                    jarFile.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}