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.bimserver.plugins.classloaders.MemoryJarClassLoader.java

public MemoryJarClassLoader(ClassLoader parentClassLoader, File jarFile)
        throws FileNotFoundException, IOException {
    super(parentClassLoader);
    this.jarFile = jarFile;
    JarInputStream jarInputStream = new JarInputStream(new FileInputStream(jarFile));
    JarEntry entry = jarInputStream.getNextJarEntry();
    while (entry != null) {
        if (entry.getName().endsWith(".jar")) {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            IOUtils.copy(jarInputStream, byteArrayOutputStream);

            // Not storing the original JAR, so future code will be unable to read the original
            loadSubJars(byteArrayOutputStream.toByteArray());
        } else {/*from w  w w  . ja  v a  2 s . co  m*/
            // Files are being stored deflated in memory because most of the time a lot of files are not being used (or the complete plugin is not being used)
            addDataToMap(jarInputStream, entry);
        }
        entry = jarInputStream.getNextJarEntry();
    }
    jarInputStream.close();
}

From source file:com.photon.phresco.util.PhrescoDynamicLoader.java

public InputStream getResourceAsStream(String fileName) throws PhrescoException {
    InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(fileName);
    if (resourceAsStream != null) {
        return resourceAsStream;
    }/*ww w .  j av  a  2  s .com*/
    List<Artifact> artifacts = new ArrayList<Artifact>();
    Artifact foundArtifact = null;
    String destFile = "";
    JarFile jarfile = null;
    for (ArtifactGroup plugin : plugins) {
        List<ArtifactInfo> versions = plugin.getVersions();
        for (ArtifactInfo artifactInfo : versions) {

            foundArtifact = createArtifact(plugin.getGroupId(), plugin.getArtifactId(), "jar",
                    artifactInfo.getVersion());
            artifacts.add(foundArtifact);
        }
    }
    try {
        URL artifactURLs = MavenArtifactResolver.resolveSingleArtifact(repoInfo.getGroupRepoURL(),
                repoInfo.getRepoUserName(), repoInfo.getRepoPassword(), artifacts);
        File jarFile = new File(artifactURLs.toURI());
        if (jarFile.getName().equals(foundArtifact.getArtifactId() + "-" + foundArtifact.getVersion() + "."
                + foundArtifact.getType())) {
            jarfile = new JarFile(jarFile);
            for (Enumeration<JarEntry> em = jarfile.entries(); em.hasMoreElements();) {
                JarEntry jarEntry = em.nextElement();
                if (jarEntry.getName().endsWith(fileName)) {
                    destFile = jarEntry.getName();
                }
            }
        }
        if (StringUtils.isNotEmpty(destFile)) {
            ZipEntry entry = jarfile.getEntry(destFile);
            return jarfile.getInputStream(entry);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new PhrescoException(e);
    }
    return null;
}

From source file:javadepchecker.Main.java

public void processJar(JarFile jar) throws IOException {
    for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements();) {
        JarEntry entry = e.nextElement();
        String name = entry.getName();
        if (!entry.isDirectory() && name.endsWith(".class")) {
            this.current.add(name);
            InputStream stream = jar.getInputStream(entry);
            new ClassReader(stream).accept(this, 0);
        }/*from ww  w  .  j  a  v a2  s  .c  o m*/
    }
}

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

/**
 * Writes the JAR to Tomcat's shared/lib directory, as specified by {@link TomcatDeployerConfig#getCatalinaShared()}.
 *///from   ww  w . j a v a2s .  co  m
@Override
protected final void deployJar(JarEntry jarEntry, JarFile earFile, DeployerConfig deployerConfig)
        throws MojoFailureException {
    final String jarName = jarEntry.getName();

    if (jarName.contains("/")) {
        throw new IllegalArgumentException(
                "The EAR contains a JAR entry in a folder, this is not supported. Bad Jar: '" + jarName + "'");
    }

    final File sharedLibDir = getSharedLibDir(deployerConfig);
    final File jarDest;
    try {
        jarDest = this.createSafeFile(sharedLibDir, jarName);
    } catch (IOException e) {
        throw new MojoFailureException(
                "Failed to setup File to deploy '" + jarName + "' to '" + sharedLibDir + "'", e);
    }

    this.copyAndClose(jarEntry, earFile, jarDest);
}

From source file:org.mule.tools.schemadocs.SchemaDocsMain.java

protected void readFromJar(URL jarUrl, List resources) throws IOException {
    JarURLConnection jarConnection = (JarURLConnection) jarUrl.openConnection();
    Enumeration entries = jarConnection.getJarFile().entries();
    while (entries.hasMoreElements()) {
        JarEntry entry = (JarEntry) entries.nextElement();
        String name = new File(entry.getName()).getName();
        if (name.startsWith(MULE) && name.endsWith(XSD)) {
            logger.debug("entry: " + entry);
            resources.add(new URL(jarUrl, entry.getName()));
        }/*w ww . j a v a2s .  c  o  m*/
    }
}

From source file:com.github.ithildir.liferay.mobile.go.GoSDKBuilder.java

protected void copyJarResource(JarURLConnection jarConnection, File destinationDir) throws IOException {

    String jarConnectionEntryName = jarConnection.getEntryName();
    JarFile jarFile = jarConnection.getJarFile();

    Enumeration<JarEntry> enu = jarFile.entries();

    while (enu.hasMoreElements()) {
        JarEntry jarEntry = enu.nextElement();
        String jarEntryName = jarEntry.getName();

        if (jarEntryName.startsWith(jarConnectionEntryName)) {
            String fileName = jarEntryName;

            if (fileName.startsWith(jarConnectionEntryName)) {
                fileName = fileName.substring(jarConnectionEntryName.length());
            }/*from w  w  w . j a v a2s .  c  om*/

            File file = new File(destinationDir, fileName);

            if (jarEntry.isDirectory()) {
                file.mkdirs();
            } else {
                InputStream is = null;

                try {
                    is = jarFile.getInputStream(jarEntry);

                    FileUtils.copyInputStreamToFile(is, file);
                } finally {
                    IOUtils.closeQuietly(is);
                }
            }
        }
    }
}

From source file:fr.gael.dhus.server.http.web.WebApplication.java

protected void extractJarFolder(URL url, String configuration_folder, String dest_folder) throws IOException {
    final JarURLConnection connection = (JarURLConnection) url.openConnection();
    if (connection != null) {
        Enumeration<JarEntry> entries = connection.getJarFile().entries();
        while (entries.hasMoreElements()) {
            JarEntry entry = (JarEntry) entries.nextElement();
            if (!entry.isDirectory() && entry.getName().startsWith(configuration_folder)) {
                InputStream in = connection.getJarFile().getInputStream(entry);
                try {
                    File file = new File(dest_folder, entry.getName().substring(configuration_folder.length()));
                    if (!file.getParentFile().exists()) {
                        file.getParentFile().mkdirs();
                    }//from   w ww .  j a  v a 2 s  . com
                    OutputStream out = new FileOutputStream(file);
                    try {
                        IOUtils.copy(in, out);
                    } finally {
                        out.close();
                    }
                } finally {
                    in.close();
                }
            }
        }
    }
}

From source file:com.smartitengineering.util.simple.reflection.DefaultClassScannerImpl.java

private void scanJar(File jarFile, String parentPath, ClassVisitor classVisitor) {
    final JarFile jar = getJarFile(jarFile);
    try {//w  ww  .  j av  a 2s . co  m
        final Enumeration<JarEntry> entries = jar.entries();
        while (entries.hasMoreElements()) {
            JarEntry e = entries.nextElement();
            if (!e.isDirectory() && e.getName().startsWith(parentPath) && e.getName().endsWith(".class")) {
                visitClassFile(jar, e, classVisitor);
            }
        }
    } catch (Exception e) {
    } finally {
        try {
            if (jar != null) {
                jar.close();
            }
        } catch (IOException ex) {
        }
    }
}

From source file:de.micromata.tpsb.doc.sources.JarSourceFileRepository.java

@Override
public Collection<JavaSourceFileHolder> getSources() {
    List<JavaSourceFileHolder> fileContentList = new ArrayList<JavaSourceFileHolder>();

    for (String jarFileName : getLocations()) {
        try {//w w w .j a va  2  s.c o  m
            JarFile jarFile;
            jarFile = new JarFile(jarFileName);
            Enumeration<? extends ZipEntry> jarEntryEnum = jarFile.entries();

            while (jarEntryEnum.hasMoreElements()) {
                JarEntry jarEntry = (JarEntry) jarEntryEnum.nextElement();

                // nur Java-Dateien beachten
                if (jarEntry.isDirectory() || StringUtils.endsWith(jarEntry.getName(), ".java") == false) {
                    continue;
                }

                String javaFilename = jarEntry.getName();
                String javaFileContent = getContents(jarFile, jarEntry);

                if (StringUtils.isBlank(javaFileContent) == true) {
                    continue;
                }
                JavaSourceFileHolder fileHolder = new JavaSourceFileHolder(javaFilename, javaFileContent);
                fileHolder.setSource(Source.Jar);
                fileHolder.setOrigin(jarFileName);
                fileContentList.add(fileHolder);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return fileContentList;
}

From source file:org.n52.ifgicopter.spf.common.PluginRegistry.java

/**
 * @param jar//from   ww  w.j a  v a 2s .  c om
 *        the jar
 * @return list of fqcn
 */
private List<String> listClasses(File jar) throws IOException {
    ArrayList<String> result = new ArrayList<String>();

    JarInputStream jis = new JarInputStream(new FileInputStream(jar));
    JarEntry je;

    while (jis.available() > 0) {
        je = jis.getNextJarEntry();

        if (je != null) {
            if (je.getName().endsWith(".class")) {
                result.add(je.getName().replaceAll("/", "\\.").substring(0, je.getName().indexOf(".class")));
            }
        }
    }

    return result;
}