Example usage for java.util.jar JarEntry toString

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

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the ZIP entry.

Usage

From source file:com.amalto.workbench.utils.Util.java

public static ByteArrayOutputStream retrieveJarEntryAsBytes(File barFile, String entryName) {
    JarInputStream jarIn = null;/*from   ww  w  .ja  v a  2s.  c o m*/
    ByteArrayOutputStream outBytes = new ByteArrayOutputStream();

    try {
        jarIn = new JarInputStream(new FileInputStream(barFile));
        JarEntry entry;
        byte[] buf = new byte[4096];
        while ((entry = jarIn.getNextJarEntry()) != null) {
            if (entry.toString().equals(entryName)) {
                int read;
                while ((read = jarIn.read(buf, 0, 4096)) != -1) {
                    outBytes.write(buf, 0, read);
                }
                if (outBytes.toByteArray().length > 0) {
                    return outBytes;
                }
            }
        }
    } catch (Exception e) {
    }
    return null;
}

From source file:org.entando.entando.plugins.jpcomponentinstaller.aps.system.services.installer.DefaultComponentInstaller.java

/**
 * Fetch all the entries in the given (jar) input stream and look for the
 * plugin directory./* w  ww.j  a  va  2  s. c  om*/
 *
 * @param is the input stream to analyse
 */
private Set<String> discoverJarPlugin(InputStream is) {
    Set<String> plugins = new HashSet<String>();
    if (null == is) {
        return plugins;
    }
    JarEntry je = null;
    try {
        JarInputStream jis = new JarInputStream(is);
        do {
            je = jis.getNextJarEntry();
            if (null != je) {
                String URL = je.toString();
                if (URL.contains(PLUGIN_DIRECTORY) && URL.endsWith(PLUGIN_APSADMIN_PATH)) {
                    plugins.add(URL);
                }
            }
        } while (je != null);
    } catch (Throwable t) {
        _logger.error("error in discoverJarPlugin", t);
        //ApsSystemUtils.logThrowable(t, this, "discoverJarPlugin");
    }
    return plugins;
}

From source file:petascope.util.IOUtil.java

public static List<String> filesInJarDir(String jarDir) {
    List<String> ret = new ArrayList<String>();
    JarInputStream jfile = null;/*w ww.  j a v  a2  s.  co m*/
    try {
        // path to the jar
        String jarPath = IOUtil.class.getResource("").getPath();
        jarPath = jarPath.substring(0, jarPath.indexOf("!"));

        File file = new File(new URI(jarPath));
        jfile = new JarInputStream(new FileInputStream(file));
        JarEntry entry = null;
        do {
            try {
                entry = jfile.getNextJarEntry();
                if (entry == null) {
                    continue;
                }
                String sentry = entry.toString();
                if (("/" + sentry).contains(jarDir) && !sentry.endsWith("/")) {
                    ret.add(sentry);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } while (entry != null);
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            jfile.close();
        } catch (Exception ex) {
        }
        return ret;
    }
}

From source file:uk.ac.ebi.intact.dataexchange.psimi.solr.server.IntactSolrHomeBuilder.java

public void install(File solrWorkingDir) throws IOException {
    if (log.isInfoEnabled())
        log.info("Installing Intact SOLR Home at: " + solrWorkingDir);

    // copy resource directory containing solr-home and war file
    File solrHomeToCreate = new File(solrWorkingDir, "home");
    File solrWarToCreate = new File(solrWorkingDir, "solr.war");

    // only copy solr-home when solr-home does not exist
    if (!solrHomeToCreate.exists() && getSolrHomeDir() == null) {
        solrHomeToCreate.mkdirs();//from  w ww.  ja  v  a 2 s  .  co  m

        File solrHomeToCopy = new File(IntactSolrHomeBuilder.class.getResource("/home").getFile());
        // is in the resources
        if (solrHomeToCopy.exists()) {
            FileUtils.copyDirectory(solrHomeToCopy, solrHomeToCreate);

            if (!solrWarToCreate.exists() && getSolrWar() == null) {
                try (InputStream solrWarToCopy = IntactSolrHomeBuilder.class.getResourceAsStream("/solr.war")) {
                    FileUtils.copyInputStreamToFile(solrWarToCopy, solrWarToCreate);
                }
            }
        }
        // is in the jar in the dependencies
        else {

            String originalName = IntactSolrHomeBuilder.class.getResource("/home").getFile();
            String jarFileName = originalName.substring(0, originalName.indexOf("!")).replace("file:", "");

            JarFile jarFile = new JarFile(jarFileName);
            Enumeration<JarEntry> jarEntries = jarFile.entries();

            // write
            while (jarEntries.hasMoreElements()) {
                JarEntry entry = jarEntries.nextElement();

                // solr war file
                if (entry.getName().endsWith("solr.war") && !solrWarToCreate.exists()
                        && getSolrHomeDir() == null) {

                    InputStream inputStream = jarFile.getInputStream(entry);

                    try {
                        FileUtils.copyInputStreamToFile(inputStream, solrWarToCreate);
                    } finally {
                        inputStream.close();
                    }
                } else if (entry.toString().startsWith("home")) {
                    File fileToCreate = new File(solrWorkingDir, entry.toString());

                    if (entry.isDirectory()) {
                        fileToCreate.mkdirs();
                        continue;
                    }

                    try (InputStream inputStream = jarFile.getInputStream(entry)) {
                        FileUtils.copyInputStreamToFile(inputStream, fileToCreate);
                    }
                }
            }
        }

        setSolrHomeDir(solrHomeToCreate);
        setSolrWar(solrWarToCreate);
    }
    // only copy solr.war when solr.war does not exist
    else if (!solrWarToCreate.exists() && getSolrWar() == null) {

        File solrHomeToCopy = new File(IntactSolrHomeBuilder.class.getResource("/home").getFile());
        // is in the resources
        if (solrHomeToCopy.exists()) {
            try (InputStream solrWarToCopy = IntactSolrHomeBuilder.class.getResourceAsStream("/solr.war")) {
                FileUtils.copyInputStreamToFile(solrWarToCopy, new File(solrWorkingDir + "/solr.war"));
            }
        }
        // is in the jar in the dependencies
        else {

            String originalName = IntactSolrHomeBuilder.class.getResource("/home").getFile();
            String jarFileName = originalName.substring(0, originalName.indexOf("!")).replace("file:", "");

            JarFile jarFile = new JarFile(jarFileName);
            Enumeration<JarEntry> jarEntries = jarFile.entries();

            // write
            while (jarEntries.hasMoreElements()) {
                JarEntry entry = jarEntries.nextElement();

                // solr war file
                if (entry.getName().endsWith("solr.war")) {
                    File fileToCreate = new File(solrWorkingDir, entry.toString());

                    try (InputStream inputStream = jarFile.getInputStream(entry)) {
                        FileUtils.copyInputStreamToFile(inputStream, fileToCreate);
                    }
                }
            }
        }

        setSolrHomeDir(solrHomeToCreate);
        setSolrWar(solrWarToCreate);
    }

    if (log.isDebugEnabled()) {
        log.debug("\nIntact Solr Home: {}\nSolr WAR: {}", getSolrHomeDir().toString(), getSolrWar().toString());
    }
}