List of usage examples for java.util.jar JarEntry isDirectory
public boolean isDirectory()
From source file:org.openmrs.module.ModuleUtil.java
/** * This loops over all FILES in this jar to get the package names. If there is an empty * directory in this jar it is not returned as a providedPackage. * * @param file jar file to look into/*from w w w . java2s .c o m*/ * @return list of strings of package names in this jar */ public static Collection<String> getPackagesFromFile(File file) { // End early if we're given a non jar file if (!file.getName().endsWith(".jar")) { return Collections.<String>emptySet(); } Set<String> packagesProvided = new HashSet<String>(); JarFile jar = null; try { jar = new JarFile(file); Enumeration<JarEntry> jarEntries = jar.entries(); while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); if (jarEntry.isDirectory()) { // skip over directory entries, we only care about files continue; } String name = jarEntry.getName(); // Skip over some folders in the jar/omod if (name.startsWith("lib") || name.startsWith("META-INF") || name.startsWith("web/module")) { continue; } Integer indexOfLastSlash = name.lastIndexOf("/"); if (indexOfLastSlash <= 0) { continue; } String packageName = name.substring(0, indexOfLastSlash); packageName = packageName.replaceAll("/", "."); if (packagesProvided.add(packageName)) { if (log.isTraceEnabled()) { log.trace("Adding module's jarentry with package: " + packageName); } } } jar.close(); } catch (IOException e) { log.error("Error while reading file: " + file.getAbsolutePath(), e); } finally { if (jar != null) { try { jar.close(); } catch (IOException e) { // Ignore quietly } } } return packagesProvided; }
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 w ww . j a v a 2 s .c o m*/ } }
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;//from w w w . ja v a 2 s . c o m } } } return _results; }
From source file:org.eclipse.licensing.eclipse_licensing_plugin.InjectLicensingMojo.java
private void extractLicensingBaseFiles() throws IOException { JarFile jar = new JarFile(getLicensingBasePlugin()); Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); String entryName = entry.getName(); if (entryName.startsWith("org")) { File file = new File(classesDirectory, entryName); if (entry.isDirectory()) { file.mkdir();//from www. ja v a2s. c om } else { InputStream is = jar.getInputStream(entry); FileOutputStream fos = new FileOutputStream(file); while (is.available() > 0) { fos.write(is.read()); } fos.close(); is.close(); } } } jar.close(); }
From source file:com.topclouders.releaseplugin.helper.FileHelper.java
private void copyJarEntry(final JarEntry jarEntry, File destinationDirectory) { final String fileName = this.getFileName(jarEntry); final File currentFile = new File(destinationDirectory, fileName); if (jarEntry.isDirectory()) { currentFile.mkdirs();// ww w .j a v a2 s. c om } else { try (OutputStream out = FileUtils.openOutputStream(currentFile); InputStream is = this.jarFile.getInputStream(jarEntry)) { IOUtils.copy(is, out); } catch (Exception e) { } } }
From source file:org.paxle.gui.impl.StyleManager.java
public void setStyle(String name) { if (name.equals("default")) { ((ServletManager) this.servletManager).unregisterAllResources(); ((ServletManager) this.servletManager).addResources("/css", "/resources/templates/layout/css"); ((ServletManager) this.servletManager).addResources("/js", "/resources/js"); ((ServletManager) this.servletManager).addResources("/images", "/resources/images"); return;// w ww.j a v a 2 s . c om } try { File styleFile = new File(this.dataPath, name); HttpContext httpContextStyle = new HttpContextStyle(styleFile); JarFile styleJarFile = new JarFile(styleFile); Enumeration<?> jarEntryEnum = styleJarFile.entries(); while (jarEntryEnum.hasMoreElements()) { JarEntry entry = (JarEntry) jarEntryEnum.nextElement(); if (entry.isDirectory()) { String alias = "/" + entry.getName().substring(0, entry.getName().length() - 1); ((ServletManager) this.servletManager).removeResource(alias); ((ServletManager) this.servletManager).addResources(alias, alias, httpContextStyle); } } } catch (IOException e) { logger.error("io: " + e); e.printStackTrace(); } return; }
From source file:jp.co.tis.gsp.tools.dba.mojo.ImportSchemaMojo.java
/** * Jar?????/* w ww . j ava2 s . c om*/ * * @param jar * @param destDir * @throws IOException */ private void extractJarAll(JarFile jar, String destDir) throws IOException { Enumeration<JarEntry> enumEntries = jar.entries(); while (enumEntries.hasMoreElements()) { java.util.jar.JarEntry file = (java.util.jar.JarEntry) enumEntries.nextElement(); java.io.File f = new java.io.File(destDir + java.io.File.separator + file.getName()); if (file.isDirectory()) { f.mkdir(); continue; } java.io.InputStream is = jar.getInputStream(file); java.io.FileOutputStream fos = new java.io.FileOutputStream(f); while (is.available() > 0) { fos.write(is.read()); } fos.close(); is.close(); } }
From source file:net.ontopia.utils.ResourcesDirectoryReader.java
private void findResourcesFromJar(URL jarPath) { try {//from w w w . j a va 2 s .com JarURLConnection jarConnection = (JarURLConnection) jarPath.openConnection(); JarFile jarFile = jarConnection.getJarFile(); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); String resourcePath = entry.getName(); if ((!entry.isDirectory()) && (resourcePath.startsWith(directoryPath)) && (searchSubdirectories || !resourcePath.substring(directoryPath.length()).contains("/")) && (filtersApply(resourcePath))) { // cannot do new URL(jarPath, resourcePath), somehow leads to duplicated path // retest on java 8 Enumeration<URL> urls = classLoader.getResources(resourcePath); while (urls.hasMoreElements()) { URL url = urls.nextElement(); if (url.toExternalForm().startsWith(jarPath.toExternalForm())) { resources.add(url); } } } } } catch (IOException e) { } }
From source file:abs.backend.erlang.ErlApp.java
private void copyJarDirectory(JarFile jarFile, String inname, String outname) throws IOException { InputStream is = null;//from w w w.j a v a 2 s . co m for (JarEntry entry : Collections.list(jarFile.entries())) { if (entry.getName().startsWith(inname)) { String relFilename = entry.getName().substring(inname.length()); if (!entry.isDirectory()) { is = jarFile.getInputStream(entry); ByteStreams.copy(is, Files.newOutputStreamSupplier(new File(outname, relFilename))); } else { new File(outname, relFilename).mkdirs(); } } } is.close(); }
From source file:javadepchecker.Main.java
/** * Scan jar for classes to be processed by ASM * * @param jar jar file to be processed//from ww w . jav a2s .com * @throws IOException */ public void processJar(JarFile jar) throws IOException { Collections.list(jar.entries()).stream() .filter((JarEntry entry) -> (!entry.isDirectory() && entry.getName().endsWith("class"))) .forEach((JarEntry entry) -> { InputStream is = null; try { Main.this.mCurrent.add(entry.getName()); is = jar.getInputStream(entry); new ClassReader(is).accept(Main.this, 0); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (is != null) is.close(); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } }); }