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.gzj.tulip.load.vfs.JarFileObject.java

@Override
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()));
            }//w w  w.j  a  v  a 2 s. co  m
        }
    }
    return children.toArray(new FileObject[0]);
}

From source file:br.com.uol.runas.classloader.JarClassLoader.java

private void addUrlsFromJar(URL url) throws IOException, MalformedURLException {
    final JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
    jarFile = jarConnection.getJarFile();
    final Enumeration<JarEntry> entries = jarFile.entries();
    final URL jarUrl = new File(jarFile.getName()).toURI().toURL();
    final String base = jarUrl.toString();

    addURL(jarUrl);/*from   w ww  .j av  a 2 s .c om*/

    while (entries.hasMoreElements()) {
        final JarEntry entry = entries.nextElement();

        if (entry.isDirectory() || endsWithAny(entry.getName(), ".jar", ".war", ".ear")) {
            addURL(new URL(base + entry.getName()));
        }
    }
}

From source file:com.igormaznitsa.jcp.it.maven.ITPreprocessorMojo.java

@Test
@SuppressWarnings("unchecked")
public void testPreprocessorUsage() throws Exception {
    final File testDir = ResourceExtractor.simpleExtractResources(this.getClass(), "./dummy_maven_project");

    final Verifier verifier = new Verifier(testDir.getAbsolutePath());

    verifier.deleteArtifact("com.igormaznitsa", "DummyMavenProjectToTestJCP", "1.0-SNAPSHOT", "jar");
    verifier.executeGoal("package");
    assertFalse("Folder must be removed", new File("./dummy_maven_project/target").exists());

    final File resultJar = ResourceExtractor.simpleExtractResources(this.getClass(),
            "./dummy_maven_project/DummyMavenProjectToTestJCP-1.0-SNAPSHOT.jar");

    verifier.verifyErrorFreeLog();//w  w  w .j av a  2  s. c om
    verifier.verifyTextInLog("PREPROCESSED_TESTING_COMPLETED");
    verifier.verifyTextInLog("Cleaning has been started");
    verifier.verifyTextInLog("Removing preprocessed source folder");
    verifier.verifyTextInLog("Removing preprocessed test source folder");
    verifier.verifyTextInLog("Scanning for deletable directories");
    verifier.verifyTextInLog("Deleting directory:");
    verifier.verifyTextInLog("Cleaning has been completed");
    verifier.verifyTextInLog(" mvn.project.property.some.datapass.base=***** ");
    verifier.verifyTextInLog(" mvn.project.property.some.private.key=***** ");

    final JarAnalyzer jarAnalyzer = new JarAnalyzer(resultJar);
    List<JarEntry> classEntries;
    try {
        classEntries = (List<JarEntry>) jarAnalyzer.getClassEntries();

        for (final JarEntry ce : classEntries) {
            assertFalse(ce.getName().contains("excludedfolder"));
        }

        assertEquals("Must have only class", 1, classEntries.size());
        final JarEntry classEntry = classEntries.get(0);
        assertNotNull(findClassEntry(jarAnalyzer, "com/igormaznitsa/dummyproject/testmain2.class"));

        DataInputStream inStream = null;
        final byte[] buffer = new byte[(int) classEntry.getSize()];
        Class<?> instanceClass = null;
        try {
            inStream = new DataInputStream(jarAnalyzer.getEntryInputStream(classEntry));
            inStream.readFully(buffer);

            instanceClass = new ClassLoader() {

                public Class<?> loadClass(final byte[] data) throws ClassNotFoundException {
                    return defineClass(null, data, 0, data.length);
                }
            }.loadClass(buffer);
        } finally {
            IOUtils.closeQuietly(inStream);
        }

        if (instanceClass != null) {
            final Object instance = instanceClass.newInstance();
            assertEquals("Must return the project name", "Dummy Maven Project To Test JCP",
                    instanceClass.getMethod("test").invoke(instance));
        } else {
            fail("Unexpected state");
        }
    } finally {
        jarAnalyzer.closeQuietly();
    }
}

From source file:gemlite.core.internal.support.hotdeploy.scanner.ScannerIterator.java

@Override
public ScannerIteratorItem next() {
    ScannerIteratorItem sitem = null;//  w  ww.j a v  a 2s .  c o  m
    if (jarInputStream != null) {
        try {
            JarEntry item = jarInputStream.getNextJarEntry();
            if (item != null)
                sitem = new ScannerIteratorItem(item.getName(), item, jarFile);
        } catch (IOException e) {
            LogUtil.getCoreLog().warn("JarInputStream is the reason," + e.getMessage());
            return null;
        }
    } else if (classFileIterator != null) {
        File item = classFileIterator.next();
        if (item != null) {
            String filePath = item.getAbsolutePath();
            filePath = filePath.substring(classpathLen - 1);
            if (filePath.startsWith(".") || filePath.startsWith("/") || filePath.startsWith("\\"))
                filePath = filePath.substring(1);

            sitem = new ScannerIteratorItem(filePath, item, jarFile);
        }
    } else if (dynClassesIterator != null) {
        Entry<String, byte[]> entry = dynClassesIterator.next();
        sitem = new ScannerIteratorItem(entry.getKey(), entry.getValue(), false);
    }
    return sitem;
}

From source file:org.bimserver.plugins.classloaders.JarClassLoader.java

public JarClassLoader(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 ww  w. j a va2  s.  c  o  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:org.jahia.modules.serversettings.portlets.WebSpherePortletHelper.java

@Override
boolean handled(JarEntry jarEntry, JarInputStream source, JarOutputStream dest) throws IOException {
    if (!"WEB-INF/web.xml".equals(jarEntry.getName())) {
        return false;
    }//from  w  w w  .  ja v  a  2s .c  o  m
    try {
        String processedWebXml = processWebXml(source);
        IOUtils.write(processedWebXml, dest);
    } catch (JDOMException e) {
        throw new IOException(e);
    }

    return true;
}

From source file:net.ymate.framework.unpack.Unpackers.java

private boolean __unpack(JarFile jarFile, String prefixPath) throws Exception {
    boolean _results = false;
    Enumeration<JarEntry> _entriesEnum = jarFile.entries();
    for (; _entriesEnum.hasMoreElements();) {
        JarEntry _entry = _entriesEnum.nextElement();
        if (StringUtils.startsWith(_entry.getName(), prefixPath)) {
            if (!_entry.isDirectory()) {
                _LOG.info("Synchronizing resource file: " + _entry.getName());
                //
                String _entryName = StringUtils.substringAfter(_entry.getName(), prefixPath);
                File _targetFile = new File(RuntimeUtils.getRootPath(false), _entryName);
                _targetFile.getParentFile().mkdirs();
                IOUtils.copyLarge(jarFile.getInputStream(_entry), new FileOutputStream(_targetFile));
                _results = true;/*  www .  j  av a2 s  . c o  m*/
            }
        }
    }
    return _results;
}

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

protected void extractJarFile(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().equals(configuration_folder)) {
                InputStream in = connection.getJarFile().getInputStream(entry);
                try {
                    File file = new File(dest_folder);
                    if (!file.getParentFile().exists()) {
                        file.getParentFile().mkdirs();
                    }//from w  ww .j  a  va2s  . com
                    OutputStream out = new FileOutputStream(file);
                    try {
                        IOUtils.copy(in, out);
                    } finally {
                        out.close();
                    }
                } finally {
                    in.close();
                }
            }
        }
    }
}

From source file:org.springframework.web.context.support.ServletContextResourcePatternResolver.java

/**
 * Extract entries from the given jar by pattern.
 * @param jarFilePath the path to the jar file
 * @param entryPattern the pattern for jar entries to match
 * @param result the Set of matching Resources to add to
 *//*from  w  ww  .  ja  v  a  2 s.co  m*/
private void doRetrieveMatchingJarEntries(String jarFilePath, String entryPattern, Set<Resource> result) {
    if (logger.isDebugEnabled()) {
        logger.debug("Searching jar file [" + jarFilePath + "] for entries matching [" + entryPattern + "]");
    }
    try {
        JarFile jarFile = new JarFile(jarFilePath);
        try {
            for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
                JarEntry entry = entries.nextElement();
                String entryPath = entry.getName();
                if (getPathMatcher().match(entryPattern, entryPath)) {
                    result.add(new UrlResource(ResourceUtils.URL_PROTOCOL_JAR, ResourceUtils.FILE_URL_PREFIX
                            + jarFilePath + ResourceUtils.JAR_URL_SEPARATOR + entryPath));
                }
            }
        } finally {
            jarFile.close();
        }
    } catch (IOException ex) {
        if (logger.isWarnEnabled()) {
            logger.warn("Cannot search for matching resources in jar file [" + jarFilePath
                    + "] because the jar cannot be opened through the file system", ex);
        }
    }
}

From source file:com.krikelin.spotifysource.AppInstaller.java

public void installJar() throws IOException, SAXException, ParserConfigurationException {

    java.util.jar.JarFile jar = new java.util.jar.JarFile(app_jar);
    // Get manifest
    java.util.Enumeration<JarEntry> enu = jar.entries();
    while (enu.hasMoreElements()) {
        JarEntry elm = enu.nextElement();
        if (elm.getName().equals("SpotifyAppManifest.xml")) {
            DataInputStream dis = new DataInputStream(jar.getInputStream(elm));
            Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(dis);
            dis.close();/*from  ww  w.j a  va2 s  .co  m*/
            // Get package name
            String package_name = d.getDocumentElement().getAttribute("package");

            addPackage(package_name, "packages");
            // Get all activities
            NodeList activities = d.getElementsByTagName("activity");
            for (int i = 0; i < activities.getLength(); i++) {
                Element activity = (Element) activities.item(i);
                String name = activity.getAttribute("name"); // Get the name
                // Append the previous name if it starts with .
                if (name.startsWith(".")) {
                    name = name.replace(".", "");

                }
                if (!name.startsWith(package_name)) {
                    name = package_name + "." + name;

                }
                //addPackage(name,"activities");
                NodeList intentFilters = activity.getElementsByTagName("intent-filter");
                for (int j = 0; j < intentFilters.getLength(); j++) {
                    NodeList actions = ((Element) intentFilters.item(0)).getElementsByTagName("action");
                    for (int k = 0; k < actions.getLength(); k++) {
                        String action_name = ((Element) actions.item(k)).getAttribute("name");
                        addPackage(name, "\\activities\\" + action_name);
                    }

                }
            }
            copyFile(app_jar.getAbsolutePath(), SPContainer.EXTENSION_DIR + "\\jar\\" + package_name + ".jar");
            // Runtime.getRuntime().exec("copy \""+app_jar+"\" \""+SPContainer.EXTENSION_DIR+"\\jar\\"+package_name+".jar\"");

        }
    }

}