List of usage examples for java.util.jar JarFile entries
public Enumeration<JarEntry> entries()
From source file:org.javaan.bytecode.JarFileLoader.java
private void processJar(String path, String fileName, JarFile jar, List<Type> classes) throws IOException { try {//w w w .j a v a 2s . c o m Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { processEntry(path, fileName, jar, classes, entries.nextElement()); } } finally { jar.close(); } }
From source file:dk.netarkivet.common.utils.batch.ByteJarLoader.java
/** * Constructor for the ByteLoader.//from w w w . j a v a 2 s .com * * @param files * An array of files, which are assumed to be jar-files, but * they need not have the extension .jar */ public ByteJarLoader(File... files) { ArgumentNotValid.checkNotNull(files, "File ... files"); ArgumentNotValid.checkTrue(files.length != 0, "Should not be empty array"); for (File file : files) { try { JarFile jarFile = new JarFile(file); for (Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements();) { JarEntry entry = e.nextElement(); String name = entry.getName(); InputStream in = jarFile.getInputStream(entry); ByteArrayOutputStream out = new ByteArrayOutputStream((int) entry.getSize()); StreamUtils.copyInputStreamToOutputStream(in, out); log.trace("Entering data for class '" + name + "'"); binaryData.put(name, out.toByteArray()); } } catch (IOException e) { throw new IOFailure("Failed to load jar file '" + file.getAbsolutePath() + "': " + e); } } }
From source file:it.polito.tellmefirst.web.rest.utils.LangDetectUtils.java
/** A private Constructor prevents any other class from instantiating. */ private LangDetectUtils() { try {/*from w w w .j a va 2 s . co m*/ String dirname = "profiles/"; Enumeration<URL> en = Detector.class.getClassLoader().getResources(dirname); List<String> profiles = new ArrayList<String>(); if (en.hasMoreElements()) { URL url = en.nextElement(); JarURLConnection urlcon = (JarURLConnection) url.openConnection(); JarFile jar = urlcon.getJarFile(); Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { String entry = entries.nextElement().getName(); if (entry.startsWith(dirname)) { InputStream in = Detector.class.getClassLoader().getResourceAsStream(entry); profiles.add(IOUtils.toString(in)); } } } DetectorFactory.loadProfile(profiles); } catch (LangDetectException e) { LOG.error("Error loading profiles directory " + e.getMessage()); } catch (Exception e) { LOG.error("Error loading profiles directory " + e.getMessage()); } }
From source file:org.adscale.testtodoc.TestToDoc.java
void handleJar(String jarName, List<String> tests) throws Exception { JarFile jarFile = new JarFile(jarName); Enumeration<JarEntry> entries = jarFile.entries(); URLClassLoader loader = createClassLoader(jarName); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); handleEntry(tests, loader, jarEntry); }//from ww w. ja v a 2 s.co m }
From source file:hermes.impl.LoaderSupport.java
/** * Return ClassLoader given the list of ClasspathConfig instances. The * resulting loader can then be used to instantiate providers from those * libraries.// w w w .j av a 2s. c o m */ static List lookForFactories(final List loaderConfigs, final ClassLoader baseLoader) throws IOException { final List rval = new ArrayList(); for (Iterator iter = loaderConfigs.iterator(); iter.hasNext();) { final ClasspathConfig lConfig = (ClasspathConfig) iter.next(); if (lConfig.getFactories() != null) { log.debug("using cached " + lConfig.getFactories()); for (StringTokenizer tokens = new StringTokenizer(lConfig.getFactories(), ","); tokens .hasMoreTokens();) { rval.add(tokens.nextToken()); } } else if (lConfig.isNoFactories()) { log.debug("previously scanned " + lConfig.getJar()); } else { Runnable r = new Runnable() { public void run() { final List localFactories = new ArrayList(); boolean foundFactory = false; StringBuffer factoriesAsString = null; try { log.debug("searching " + lConfig.getJar()); ClassLoader l = createClassLoader(loaderConfigs, baseLoader); JarFile jarFile = new JarFile(lConfig.getJar()); ProgressMonitor monitor = null; int entryNumber = 0; if (HermesBrowser.getBrowser() != null) { monitor = new ProgressMonitor(HermesBrowser.getBrowser(), "Looking for factories in " + lConfig.getJar(), "Scanning...", 0, jarFile.size()); monitor.setMillisToDecideToPopup(0); monitor.setMillisToPopup(0); monitor.setProgress(0); } for (Enumeration iter = jarFile.entries(); iter.hasMoreElements();) { ZipEntry entry = (ZipEntry) iter.nextElement(); entryNumber++; if (monitor != null) { monitor.setProgress(entryNumber); monitor.setNote("Checking entry " + entryNumber + " of " + jarFile.size()); } if (entry.getName().endsWith(".class")) { String s = entry.getName().substring(0, entry.getName().indexOf(".class")); s = s.replaceAll("/", "."); try { if (s.startsWith("hermes.browser") || s.startsWith("hermes.impl") || s.startsWith("javax.jms")) { // NOP } else { Class clazz = l.loadClass(s); if (!clazz.isInterface()) { if (implementsOrExtends(clazz, ConnectionFactory.class)) { foundFactory = true; localFactories.add(s); if (factoriesAsString == null) { factoriesAsString = new StringBuffer(); factoriesAsString.append(clazz.getName()); } else { factoriesAsString.append(",").append(clazz.getName()); } log.debug("found " + clazz.getName()); } } /** * TODO: remove Class clazz = l.loadClass(s); * Class[] interfaces = clazz.getInterfaces(); * for (int i = 0; i < interfaces.length; i++) { * if * (interfaces[i].equals(TopicConnectionFactory.class) || * interfaces[i].equals(QueueConnectionFactory.class) || * interfaces[i].equals(ConnectionFactory.class)) { * foundFactory = true; localFactories.add(s); * if (factoriesAsString == null) { * factoriesAsString = new * StringBuffer(clazz.getName()); } else { * factoriesAsString.append(",").append(clazz.getName()); } * log.debug("found " + clazz.getName()); } } */ } } catch (Throwable t) { // NOP } } } } catch (IOException e) { log.error("unable to access jar/zip " + lConfig.getJar() + ": " + e.getMessage(), e); } if (!foundFactory) { lConfig.setNoFactories(true); } else { lConfig.setFactories(factoriesAsString.toString()); rval.addAll(localFactories); } } }; r.run(); } } return rval; }
From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.TypeLibraryUtil.java
/** * Adding the TypeLibProtocal to the name for the xsd entry. * * @param typeLibName the type lib name//from w w w . j av a 2s. co m * @param baseLocation the base location * @return the dependency stream * @throws CoreException the core exception * @throws IOException Signals that an I/O exception has occurred. */ public static InputStream getDependencyStream(String typeLibName, String baseLocation) throws CoreException, IOException { if (baseLocation.toLowerCase().startsWith("jar:file:/")) { JarFile jarFile = new JarFile(getJarFile(baseLocation.substring(10, baseLocation.length()))); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.getName().startsWith(SOATypeLibraryConstants.INFO_DEP_XML_PATH_IN_JAR) && entry.getName().endsWith(SOATypeLibraryConstants.FILE_TYPE_DEP_XML)) { return jarFile.getInputStream(entry); } } } else { IProject project = WorkspaceUtil.getProject(typeLibName); if (project.isAccessible() && project.hasNature(GlobalRepositorySystem.instanceOf() .getActiveRepositorySystem().getProjectNatureId(SupportedProjectType.TYPE_LIBRARY))) { return project.getFile(SOATypeLibraryConstants.FOLDER_META_SRC_META_INF + WorkspaceUtil.PATH_SEPERATOR + project.getName() + WorkspaceUtil.PATH_SEPERATOR + SOATypeLibraryConstants.FILE_TYPE_DEP_XML).getContents(); } } throw new IOException("InpuStream could not be obtained with the type lib Name " + typeLibName + " and base location " + baseLocation); }
From source file:com.eviware.soapui.plugins.JarClassLoader.java
private boolean containsLibraries(JarFile jarFile) { Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); if (isLibrary(jarEntry)) { return true; }//from w w w . j a v a 2 s . c o m } return false; }
From source file:com.eviware.soapui.plugins.JarClassLoader.java
private boolean containsScripts(JarFile jarFile) { Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); if (isScript(jarEntry)) { return true; }//w w w .java 2 s . co m } return false; }
From source file:org.apache.bcel.BCELBenchmark.java
private Iterable<JarEntry> getClasses(JarFile jar) { return new IteratorIterable<>( new FilterIterator<>(new EnumerationIterator<>(jar.entries()), new Predicate<JarEntry>() { @Override// ww w.j a v a 2 s. c o m public boolean evaluate(JarEntry entry) { return entry.getName().endsWith(".class"); } })); }
From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.TypeLibraryUtil.java
/** * Gets the project name from wtp base location. * * @param baseLocationStr the base location str * @return the project name from wtp base location * @throws ParserConfigurationException the parser configuration exception * @throws SAXException the sAX exception * @throws IOException Signals that an I/O exception has occurred. */// w w w . ja v a 2 s .co m public static String getProjectNameFromWTPBaseLocation(String baseLocationStr) throws ParserConfigurationException, SAXException, IOException { IPath path = new Path(baseLocationStr); // this is a jar location if base location starts with jar for eg: // "jar:file:/D:/Views/soapost22/v3jars/services/MarketPlaceServiceCommonTypeLibrary/3.0.0/java50/MarketPlaceServiceCommonTypeLibrary.jar!/types/BaseServiceResponse.xsd" if (baseLocationStr.toLowerCase().startsWith("jar:file:/")) { JarFile jarFile = new JarFile(getJarFile(baseLocationStr.substring(10, baseLocationStr.length()))); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.getName().startsWith(SOATypeLibraryConstants.INFO_DEP_XML_PATH_IN_JAR) && entry.getName().endsWith(SOATypeLibraryConstants.FILE_TYPE_INFO_XML)) { return getTypeLibName(entry, jarFile); } } } else { // New style has the type library name also. So removing an // additional segment at the end. if (isNewStyleBaseLocation(baseLocationStr)) { path = path.removeLastSegments(4); } else { // removing meta-src/types/abcd.xsd path = path.removeLastSegments(3); } } return path.lastSegment(); }