List of usage examples for java.util.jar JarFile entries
public Enumeration<JarEntry> entries()
From source file:com.asual.summer.onejar.OneJarServer.java
private static String getCurrentWarFile() throws IOException { JarFile jarFile = new JarFile(System.getProperty("java.class.path")); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { String name = entries.nextElement().getName(); if (name.endsWith(".war")) { File war = new File(new File(System.getProperty("java.io.tmpdir")), "summer-onejar-" + System.currentTimeMillis() + ".war"); InputStream input = jarFile.getInputStream(new ZipEntry(name)); FileOutputStream output = new FileOutputStream(war); IOUtils.copy(input, output); IOUtils.closeQuietly(input); IOUtils.closeQuietly(output); war.deleteOnExit();//from ww w . j a v a 2 s . c o m return war.getAbsolutePath(); } } return null; }
From source file:org.lilyproject.lilyservertestfw.ConfUtil.java
public static void copyFromJar(File confDir, String confResourcePath, JarURLConnection jarConnection) throws IOException { JarFile jarFile = jarConnection.getJarFile(); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.getName().startsWith(confResourcePath)) { String fileName = StringUtils.removeStart(entry.getName(), confResourcePath); if (entry.isDirectory()) { File subDir = new File(confDir, fileName); subDir.mkdirs();/*from ww w . j a v a 2 s. com*/ } else { InputStream entryInputStream = null; try { entryInputStream = jarFile.getInputStream(entry); FileUtils.copyInputStreamToFile(entryInputStream, new File(confDir, fileName)); } finally { if (entryInputStream != null) { entryInputStream.close(); } } } } } }
From source file:Main.java
/** * Iterates over APK (jar entries) to populate * /*from ww w . j a v a 2 s. c o m*/ * @param projectFile * @return * @throws IOException * @throws CertificateException */ public static List<Certificate> populateCertificate(File projectFile) throws IOException, CertificateException { List<Certificate> certList = new ArrayList<Certificate>(); JarFile jar = new JarFile(projectFile); Enumeration<JarEntry> jarEntries = jar.entries(); while (jarEntries.hasMoreElements()) { JarEntry entry = jarEntries.nextElement(); if (entry.getName().toLowerCase().contains(DSA) || entry.getName().toLowerCase().contains(RSA)) { certList.addAll(extractCertificate(jar, entry)); } } return certList; }
From source file:com.athomas.androidkickstartr.util.ResourcesUtils.java
private static void copyResourcesToFromJar(File target, URL url) throws IOException { JarURLConnection connection = (JarURLConnection) url.openConnection(); JarFile jarFile = connection.getJarFile(); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); InputStream is = jarFile.getInputStream(jarEntry); String entryPath = jarEntry.getName(); File file = null;/*w ww . j a va 2 s . c o m*/ String dirs = ""; if (entryPath.contains("/")) { int lastIndexOf = entryPath.lastIndexOf("/"); dirs = (String) entryPath.subSequence(0, lastIndexOf + 1); } File parent = new File(target, dirs); parent.mkdirs(); if (!jarEntry.isDirectory()) { String[] splitedPath = entryPath.split("/"); String fileName = splitedPath[splitedPath.length - 1]; file = new File(parent, fileName); FileUtils.copyInputStreamToFile(is, file); } } }
From source file:com.zb.app.common.file.FileUtils.java
public static void unJar(File jarFile, File toDir) throws IOException { JarFile jar = new JarFile(jarFile); try {/* w w w . java 2s. c o m*/ Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); if (!entry.isDirectory()) { InputStream in = jar.getInputStream(entry); try { File file = new File(toDir, entry.getName()); if (!file.getParentFile().mkdirs()) { if (!file.getParentFile().isDirectory()) { throw new IOException("Mkdirs failed to create " + file.getParentFile().toString()); } } OutputStream out = new FileOutputStream(file); try { byte[] buffer = new byte[8192]; int i; while ((i = in.read(buffer)) != -1) { out.write(buffer, 0, i); } } finally { out.close(); } } finally { in.close(); } } } } finally { jar.close(); } }
From source file:org.eclipse.wb.internal.swing.laf.LafUtils.java
/** * Opens given <code>jarFile</code>, loads every class inside own {@link ClassLoader} and checks * loaded class for to be instance of {@link LookAndFeel}. Returns the array of {@link LafInfo} * containing all found {@link LookAndFeel} classes. * /* ww w. j a va2 s . c o m*/ * @param jarFileName * the absolute OS path pointing to source JAR file. * @param monitor * the progress monitor which checked for interrupt request. * @return the array of {@link UserDefinedLafInfo} containing all found {@link LookAndFeel} * classes. */ public static UserDefinedLafInfo[] scanJarForLookAndFeels(String jarFileName, IProgressMonitor monitor) throws Exception { List<UserDefinedLafInfo> lafList = Lists.newArrayList(); File jarFile = new File(jarFileName); URLClassLoader ucl = new URLClassLoader(new URL[] { jarFile.toURI().toURL() }); JarFile jar = new JarFile(jarFile); Enumeration<?> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); String entryName = entry.getName(); if (entry.isDirectory() || !entryName.endsWith(".class") || entryName.indexOf('$') >= 0) { continue; } String className = entryName.replace('/', '.').replace('\\', '.'); className = className.substring(0, className.lastIndexOf('.')); Class<?> clazz = null; try { clazz = ucl.loadClass(className); } catch (Throwable e) { continue; } // check loaded class to be a non-abstract subclass of javax.swing.LookAndFeel class if (LookAndFeel.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) { // use the class name as name of LAF String shortClassName = CodeUtils.getShortClass(className); // strip trailing "LookAndFeel" String lafName = StringUtils.chomp(shortClassName, "LookAndFeel"); lafList.add(new UserDefinedLafInfo(StringUtils.isEmpty(lafName) ? shortClassName : lafName, className, jarFileName)); } // check for Cancel button pressed if (monitor.isCanceled()) { return lafList.toArray(new UserDefinedLafInfo[lafList.size()]); } // update ui while (DesignerPlugin.getStandardDisplay().readAndDispatch()) { } } return lafList.toArray(new UserDefinedLafInfo[lafList.size()]); }
From source file:org.apache.stratos.cartridge.agent.statistics.publisher.PluginLoader.java
public static List<Class> loadPluginClassesFromJar(File jarPath, Class pluginInterface) { List<Class> listeners = new LinkedList<Class>(); try {/* w w w . j av a 2 s. co m*/ URLClassLoader loader = new URLClassLoader(new URL[] { jarPath.toURI().toURL() }); JarFile jar = new JarFile(jarPath); Enumeration<? extends JarEntry> jarEnum = jar.entries(); log.trace("Scanning jar file " + jarPath); while (jarEnum.hasMoreElements()) { ZipEntry zipEntry = jarEnum.nextElement(); String fileName = zipEntry.getName(); if (fileName.endsWith(".class")) { log.trace("Considering jar entry " + fileName); try { String className = fileName.replace(".class", "").replace("/", "."); Class cls = loader.loadClass(className); log.trace("Loaded class " + className); if (hasInterface(cls, pluginInterface)) { log.trace("Class has " + pluginInterface.getName() + " interface; adding "); listeners.add(cls); } } catch (ClassNotFoundException e) { log.error("Unable to load class from " + fileName + " in " + jarPath); } } } } catch (IOException e) { log.error("Unable to open JAR file " + jarPath, e); } return listeners; }
From source file:org.apache.hadoop.hbase.util.RunTrigger.java
public static void unJar(File jarFile, File toDir) throws IOException { JarFile jar = new JarFile(jarFile); try {//from ww w. j av a2s. c om Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); if (!entry.isDirectory()) { InputStream in = jar.getInputStream(entry); try { File file = new File(toDir, entry.getName()); if (!file.getParentFile().mkdirs()) { if (!file.getParentFile().isDirectory()) { throw new IOException("Mkdirs failed to create " + file.getParentFile().toString()); } } OutputStream out = new FileOutputStream(file); try { byte[] buffer = new byte[8192]; int i; while ((i = in.read(buffer)) != -1) { out.write(buffer, 0, i); } } finally { out.close(); } } finally { in.close(); } } } } finally { jar.close(); } }
From source file:org.tangram.util.SetupUtils.java
private static Set<String> getResourceListing(URL pathUrl, String prefix, String suffix) throws URISyntaxException, IOException { Set<String> result = new HashSet<>(); if ("file".equals(pathUrl.getProtocol())) { for (String name : new File(pathUrl.toURI()).list()) { if (name.endsWith(suffix)) { result.add(prefix + "/" + name); } // if } // for//from www . ja v a 2 s. com } // if if ("jar".equals(pathUrl.getProtocol())) { String jarPath = pathUrl.getPath().substring(5, pathUrl.getPath().indexOf("!")); // only the JAR file JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8")); for (Enumeration<JarEntry> entries = jar.entries(); entries.hasMoreElements();) { String name = entries.nextElement().getName(); if (name.startsWith(prefix) && name.endsWith(suffix)) { result.add(name); } // if } // for jar.close(); } // if return result; }
From source file:com.katsu.dwm.reflection.JarUtils.java
/** * Return a list of resources inside the jar file that their URL start with path * @param jar//from ww w. ja v a2s . c om * @param path * @return */ public static List<JarEntry> getJarContent(File jar, String path) { try { JarFile jf = new JarFile(jar); Enumeration<JarEntry> enu = jf.entries(); List<JarEntry> result = new ArrayList<JarEntry>(); while (enu.hasMoreElements()) { JarEntry je = enu.nextElement(); if (je.getName().startsWith(path)) result.add(je); } return result; } catch (Exception e) { logger.error(e); } return null; }