List of usage examples for java.util.jar JarEntry isDirectory
public boolean isDirectory()
From source file:org.entando.entando.plugins.jpcomponentinstaller.aps.system.services.installer.DefaultComponentInstaller.java
private void loadClasses(File[] jarFiles, URLClassLoader cl) throws Exception { for (File input : jarFiles) { try {//from w w w. j a v a 2 s . c o m //load classes from plugin's jar files using the classloader above //loadClassesFromJar(input, cl); JarFile jarFile = new JarFile(input.getAbsolutePath()); Enumeration e = jarFile.entries(); while (e.hasMoreElements()) { JarEntry je = (JarEntry) e.nextElement(); if (je.isDirectory() || !je.getName().endsWith(".class")) { continue; } String className = je.getName().substring(0, je.getName().length() - 6); className = className.replace('/', '.'); try { cl.loadClass(className); } catch (Throwable ex) { String error = "Error loadin class: " + className; _logger.error(error); } } } catch (Throwable e) { String error = "Unexpected error loading class for file: " + input.getName() + " - " + e.getMessage(); _logger.error(error, e); throw new Exception(error, e); } } }
From source file:org.apache.storm.utils.ServerUtils.java
public void extractDirFromJarImpl(String jarpath, String dir, File destdir) { try (JarFile jarFile = new JarFile(jarpath)) { Enumeration<JarEntry> jarEnums = jarFile.entries(); while (jarEnums.hasMoreElements()) { JarEntry entry = jarEnums.nextElement(); if (!entry.isDirectory() && entry.getName().startsWith(dir)) { File aFile = new File(destdir, entry.getName()); aFile.getParentFile().mkdirs(); try (FileOutputStream out = new FileOutputStream(aFile); InputStream in = jarFile.getInputStream(entry)) { IOUtils.copy(in, out); }/*w w w .j a va 2s . c o m*/ } } } catch (IOException e) { LOG.info("Could not extract {} from {}", dir, jarpath); } }
From source file:net.rim.ejde.internal.packaging.PackagingJob.java
/** * If the cod file represented by the given <code>codFilePath</code> contains sibling cod file, un-zip it and copy all sibling * cod files to the <code>destinationFolderPath</code>. If the cod file is a single cod file, just copy it to the * <code>destinationFolderPath</code>. * * @param codFilePath//from w ww. ja v a2 s . c o m * @param destinationFolderPath * @throws CoreException */ private void copySiblingCod(IPath codFilePath, IPath destinationFolderPath) throws CoreException { boolean hasSiblingCod = false; File codFile = codFilePath.toFile(); try { JarFile zipFile = new JarFile(codFile); Enumeration<JarEntry> entries = zipFile.entries(); if (entries.hasMoreElements()) { hasSiblingCod = true; JarEntry entry; for (; entries.hasMoreElements();) { entry = entries.nextElement(); if (entry.isDirectory()) { // this should not happen continue; } InputStream is = zipFile.getInputStream(entry); File outputFile = destinationFolderPath.append(entry.getName()).toFile(); PackagingManager.copyInputStream(is, new BufferedOutputStream(new FileOutputStream(outputFile))); } } else { hasSiblingCod = false; } } catch (IOException e) { if (codFile.exists()) { // if the cod file does not contain any sibling file, we get IOException hasSiblingCod = false; } else { _log.error(e); } } finally { if (!hasSiblingCod) { // if the cod file is a single cod file, copy it to the destination DeploymentHelper.executeCopy(codFile, destinationFolderPath.append(codFile.getName()).toFile()); } } }
From source file:org.hyperic.snmp.MIBTree.java
public boolean parse(JarFile jar, String[] accept) throws IOException { AcceptFilter filter = new AcceptFilter(accept); for (Enumeration e = jar.entries(); e.hasMoreElements();) { JarEntry entry = (JarEntry) e.nextElement(); if (entry.isDirectory()) { continue; }/* w w w . ja va 2 s. c o m*/ if (!entry.getName().startsWith("mibs/")) { continue; } String name = entry.getName().substring(5); if (!filter.accept(name)) { continue; } if (hasParsedFile(new File(name))) { continue; } String where = jar.getName() + "!" + entry.getName(); parse(where, jar.getInputStream(entry)); } return true; }
From source file:com.opensymphony.xwork2.util.finder.ClassFinder.java
private List<String> jar(JarInputStream jarStream) throws IOException { List<String> classNames = new ArrayList<String>(); JarEntry entry; while ((entry = jarStream.getNextJarEntry()) != null) { if (entry.isDirectory() || !entry.getName().endsWith(".class")) { continue; }//from www . java 2s . c o m String className = entry.getName(); className = className.replaceFirst(".class$", ""); //war files are treated as .jar files, so takeout WEB-INF/classes className = StringUtils.removeStart(className, "WEB-INF/classes/"); className = className.replace('/', '.'); classNames.add(className); } return classNames; }
From source file:org.hyperic.hq.product.server.session.ProductPluginDeployer.java
private void unpackJar(File pluginJarFile, File destDir, String prefix) throws Exception { JarFile jar = null;/*from www.jav a 2 s . c om*/ try { jar = new JarFile(pluginJarFile); for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements();) { JarEntry entry = e.nextElement(); String name = entry.getName(); if (name.startsWith(prefix)) { name = name.substring(prefix.length()); if (name.length() == 0) { continue; } File file = new File(destDir, name); if (entry.isDirectory()) { file.mkdirs(); } else { FileUtil.copyStream(jar.getInputStream(entry), new FileOutputStream(file)); } } } } catch (Throwable t) { t.printStackTrace(); } finally { if (jar != null) jar.close(); } }
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();// ww w . j a va2s . c o 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()); } }
From source file:com.stacksync.desktop.Environment.java
public void copyResourcesFromJar(JarURLConnection jarConnection, File destDir) { try {/*from w w w .jav a 2 s . c o m*/ JarFile jarFile = jarConnection.getJarFile(); /** * Iterate all entries in the jar file. */ for (Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements();) { JarEntry jarEntry = e.nextElement(); String jarEntryName = jarEntry.getName(); String jarConnectionEntryName = jarConnection.getEntryName(); /** * Extract files only if they match the path. */ if (jarEntryName.startsWith(jarConnectionEntryName)) { String filename = jarEntryName.startsWith(jarConnectionEntryName) ? jarEntryName.substring(jarConnectionEntryName.length()) : jarEntryName; File currentFile = new File(destDir, filename); if (jarEntry.isDirectory()) { currentFile.mkdirs(); } else { InputStream is = jarFile.getInputStream(jarEntry); OutputStream out = FileUtils.openOutputStream(currentFile); IOUtils.copy(is, out); is.close(); out.close(); } } } } catch (IOException e) { // TODO add logger e.printStackTrace(); } }
From source file:org.exist.repo.Deployment.java
public DocumentImpl getDescriptor(File jar) throws IOException, PackageException { final InputStream istream = new BufferedInputStream(new FileInputStream(jar)); final JarInputStream jis = new JarInputStream(istream); JarEntry entry; DocumentImpl doc = null;/* ww w . ja v a2 s. c o m*/ while ((entry = jis.getNextJarEntry()) != null) { if (!entry.isDirectory() && "expath-pkg.xml".equals(entry.getName())) { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); int c; final byte[] b = new byte[4096]; while ((c = jis.read(b)) > 0) { bos.write(b, 0, c); } bos.close(); final byte[] data = bos.toByteArray(); final ByteArrayInputStream bis = new ByteArrayInputStream(data); try { doc = DocUtils.parse(broker.getBrokerPool(), null, bis); } catch (final XPathException e) { throw new PackageException("Error while parsing expath-pkg.xml: " + e.getMessage(), e); } break; } } jis.close(); return doc; }
From source file:streamflow.service.TopologyService.java
private void embedFrameworkResources(JarBuilder jarBuilder, byte[] frameworkJar) { JarEntry jarEntry; JarInputStream jarInputStream; try {/*from w w w . j a va2 s. com*/ jarInputStream = new JarInputStream(new ByteArrayInputStream(frameworkJar)); while ((jarEntry = jarInputStream.getNextJarEntry()) != null) { // A resource file is defined as a non *.class file that is a real file if (!jarEntry.isDirectory() && !jarEntry.getName().endsWith(".class")) { // Ignore the resource files in the META-INF folder if (!jarEntry.getName().startsWith("META-INF") && !jarEntry.getName().startsWith("STREAMFLOW-INF")) { // Create the handle to the target resource file in the topology jar if (!jarBuilder.addFile(jarEntry.getName(), IOUtils.toByteArray(jarInputStream))) { LOG.error("Error occurred while writing a framework resource to the topology jar: " + jarEntry.getName()); } } } } } catch (IOException ex) { LOG.error("Exception while embedding framework resource: " + ex.getMessage()); } }