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.opensymphony.xwork2.util.finder.ResourceFinder.java

private static void readJarDirectoryEntries(URL location, String basePath, Set<String> resources)
        throws IOException {
    JarURLConnection conn = (JarURLConnection) location.openConnection();
    JarFile jarfile = null;//from  w ww.  j  a  va  2  s.  co  m
    jarfile = conn.getJarFile();

    Enumeration<JarEntry> entries = jarfile.entries();
    while (entries != null && entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        String name = entry.getName();

        if (entry.isDirectory() && StringUtils.startsWith(name, basePath)) {
            resources.add(name);
        }
    }
}

From source file:com.tobedevoured.solrsail.SolrConfig.java

/**
 * Install Solr Config t the local file system by extracting from the
 * SolrSail jar//from   w w w  .j  av a  2  s.c  om
 * 
 * @param jar File
 * @throws IOException
 */
public void installFromJar(File jar) throws IOException {
    logger.info("Installing config from Jar to {}", this.getSolrHome());
    logger.debug("Opening Jar {}", jar.toString());

    JarFile jarFile = new JarFile(jar);

    for (Enumeration<JarEntry> enumeration = jarFile.entries(); enumeration.hasMoreElements();) {
        JarEntry entry = enumeration.nextElement();

        if (!entry.getName().equals("solr/") && entry.getName().startsWith("solr/")) {
            StringBuilder dest = new StringBuilder(getSolrHome()).append(File.separator)
                    .append(entry.getName().replaceFirst("solr/", ""));

            File file = new File(dest.toString());

            if (entry.isDirectory()) {
                file.mkdirs();
            } else {
                if (file.getParentFile() != null) {
                    file.getParentFile().mkdirs();
                }

                logger.debug("Copying {} to {}", entry.getName(), dest.toString());

                InputStream input = jarFile.getInputStream(entry);
                Writer writer = new FileWriter(file.getAbsoluteFile());
                IOUtils.copy(input, writer);

                input.close();

                writer.close();
            }
        }
    }
}

From source file:com.sinosoft.one.mvc.scanning.vfs.JarFileObject.java

public FileObject[] getChildren() throws IOException {
    List<FileObject> children = new LinkedList<FileObject>();
    Enumeration<JarEntry> e = jarFile.entries();
    String entryName = root == this ? "" : entry.getName();
    while (e.hasMoreElements()) {
        JarEntry entry = e.nextElement();
        if (entry.getName().length() > entryName.length() && entry.getName().startsWith(entryName)) {
            int index = entry.getName().indexOf('/', entryName.length() + 1);
            // ?=?
            if (index == -1 || index == entry.getName().length() - 1) {
                children.add(fs.resolveFile(root.urlString + entry.getName()));
            }//  ww  w.  j a  va2s. c om
        }
    }
    return children.toArray(new FileObject[0]);
}

From source file:hudson.remoting.RegExpBenchmark.java

private List<String> getAllRTClasses() throws Exception {
    List<String> classes = new ArrayList<String>();
    // Object.class.getProtectionDomain().getCodeSource() returns null :(
    String javaHome = System.getProperty("java.home");
    JarFile jf = new JarFile(javaHome + "/lib/rt.jar");
    for (JarEntry je : Collections.list(jf.entries())) {
        if (!je.isDirectory() && je.getName().endsWith(".class")) {
            String name = je.getName().replace('/', '.');
            // remove the .class
            name = name.substring(0, name.length() - 6);
            classes.add(name);//w  w w  . ja va 2 s  .c o m
        }
    }
    jf.close();
    // add in a couple from xalan and commons just for testing...
    classes.add(new String("org.apache.commons.collections.functors.EvilClass"));
    classes.add(new String("org.codehaus.groovy.runtime.IWIllHackYou"));
    classes.add(new String("org.apache.xalan.YouAreOwned"));
    return classes;
}

From source file:com.thoughtworks.go.util.NestedJarClassLoader.java

private URL expandJarAndReturnURL(JarInputStream jarStream, JarEntry entry) throws IOException {
    File nestedJarFile = new File(jarDir, entry.getName());
    nestedJarFile.getParentFile().mkdirs();
    try (FileOutputStream out = new FileOutputStream(nestedJarFile)) {
        IOUtils.copy(jarStream, out);/* w ww.j  a  v a  2s.  com*/
    }
    LOGGER.info("Exploded Entry {} from to {}", entry.getName(), nestedJarFile);
    return nestedJarFile.toURI().toURL();
}

From source file:com.katsu.dwm.web.Loader.java

private void copyContent(File f, JarEntry je) {
    File rootPath = JarUtils.getRootApplicationContentPath();
    File temp = new File(rootPath, je.getName());
    if (je.isDirectory()) {
        logger.debug("Create path: " + temp.mkdirs() + " " + temp.getPath());
    } else {//from w  ww. j  av a  2s .c o  m
        InputStream is = null;
        FileOutputStream fos = null;
        try {
            JarFile jf = new JarFile(f);
            is = jf.getInputStream(je);
            if (!temp.exists()) {
                temp.createNewFile();
            }
            fos = new FileOutputStream(temp);
            byte[] array = new byte[1024];
            int readed;
            while ((readed = is.read(array)) != -1) {
                fos.write(array, 0, readed);
            }
        } catch (Exception e) {
            logger.error(e);
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException ex) {
            }
            try {
                if (fos != null) {
                    fos.close();
                }
            } catch (IOException ex) {
            }
        }
    }
}

From source file:org.silverpeas.applicationbuilder.ReadOnlyArchive.java

/**
 * @param entry the entry to read//from w w  w . j a v a 2 s .co  m
 * @return the jarEntry of the entry (null if not found or directory)
 * @since 1.0/B
 */
private JarEntry getJarEntry(ApplicationBuilderItem entry) {
    if (getJar() == null) {
        return null;
    }
    Enumeration<JarEntry> e = getJar().entries();
    while (e.hasMoreElements()) {
        JarEntry jarEntry = e.nextElement();
        File entryFile = new File(jarEntry.getName());
        if (entryFile.getPath().equals(entry.getArchivePath())) {
            return jarEntry;
        }
    }
    return null;
}

From source file:com.opensymphony.xwork2.util.finder.ResourceFinder.java

private static void readJarEntries(URL location, String basePath, Map<String, URL> resources)
        throws IOException {
    JarURLConnection conn = (JarURLConnection) location.openConnection();
    JarFile jarfile = null;/*from  w  ww  .  ja va  2  s .c o m*/
    jarfile = conn.getJarFile();

    Enumeration<JarEntry> entries = jarfile.entries();
    while (entries != null && entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        String name = entry.getName();

        if (entry.isDirectory() || !name.startsWith(basePath) || name.length() == basePath.length()) {
            continue;
        }

        name = name.substring(basePath.length());

        if (name.contains("/")) {
            continue;
        }

        URL resource = new URL(location, name);
        resources.put(name, resource);
    }
}

From source file:org.apache.bcel.generic.JDKGenericDumpTestCase.java

private void testJar(final File file) throws Exception {
    System.out.println(file);//from ww w .  j  ava  2  s.c  o  m
    try (JarFile jar = new JarFile(file)) {
        final Enumeration<JarEntry> en = jar.entries();
        while (en.hasMoreElements()) {
            final JarEntry e = en.nextElement();
            final String name = e.getName();
            if (name.endsWith(".class")) {
                // System.out.println("- " + name);
                try (InputStream in = jar.getInputStream(e)) {
                    final ClassParser parser = new ClassParser(in, name);
                    final JavaClass jc = parser.parse();
                    for (final Method m : jc.getMethods()) {
                        compare(name, m);
                    }
                }
            }
        }
    }
}

From source file:com.thoughtworks.go.domain.materials.tfs.TfsSDKCommandBuilder.java

private void explodeNatives() throws IOException {
    URL urlOfJar = getJarURL();//w w  w.  jav a2 s.  c o m
    LOGGER.info("[TFS SDK] Exploding natives from {} to folder {}", urlOfJar.toString(),
            tempFolder.getAbsolutePath());
    JarInputStream jarStream = new JarInputStream(urlOfJar.openStream());
    JarEntry entry;
    while ((entry = jarStream.getNextJarEntry()) != null) {
        if (!entry.isDirectory() && entry.getName().startsWith("tfssdk/native/")) {
            File newFile = new File(tempFolder, entry.getName());
            newFile.getParentFile().mkdirs();
            LOGGER.info("[TFS SDK] Extract {} -> {}", entry.getName(), newFile);
            try (OutputStream fos = new FileOutputStream(newFile)) {
                IOUtils.copy(jarStream, fos);
            }
        }
    }
}