当前位置: 首页>>代码示例>>Java>>正文


Java JarFile.entries方法代码示例

本文整理汇总了Java中java.util.jar.JarFile.entries方法的典型用法代码示例。如果您正苦于以下问题:Java JarFile.entries方法的具体用法?Java JarFile.entries怎么用?Java JarFile.entries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.jar.JarFile的用法示例。


在下文中一共展示了JarFile.entries方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveJar

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * 解析jar包中的类
 * @param jarFile			表示jar文件
 * @param packageLocation	扫描的包路径
 * @throws Exception 反射时的异常
 */
private void resolveJar(JarFile jarFile, String packageLocation) throws Exception {
	Enumeration<JarEntry> entries = jarFile.entries();
	while (entries.hasMoreElements()) {
		String classLocation = entries.nextElement().getName();
		// 当jar文件中的路径是以packageLocation指定的路径开头,并且是以.class结尾时
		if (classLocation.startsWith(packageLocation) && classLocation.endsWith(".class")) {
			String location = classLocation.replace(".class", "").replace("/", ".");
			Class<?> forName = Class.forName(location);
			configurationBeansHandler(forName);
			Annotation[] annos = forName.getAnnotations();
			if (AnnoUtil.exist(annos, Bean.class) && !forName.isInterface()) {
				beansInitializedHandler(forName);
			}
		}
	}
}
 
开发者ID:NymphWeb,项目名称:nymph,代码行数:23,代码来源:ScannerNymphBeans.java

示例2: findClasses

import java.util.jar.JarFile; //导入方法依赖的package包/类
protected void findClasses(Set<Class<?>> classes, ClassLoader classLoader,
        String packageName, JarURLConnection connection) throws IOException {
    JarFile jarFile = connection.getJarFile();
    if (jarFile == null) {
        return;
    }
    Enumeration<JarEntry> entries = jarFile.entries();
    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();
        String name = entry.getName();
        if (name.endsWith(CLASS_SUFFIX) && name.startsWith(packageName)) {
            String className = name.replace('/', '.').replace(CLASS_SUFFIX, "");
            try {
                Class<?> c = ClassUtils.forName(className, classLoader);
                classes.add(c);
            } catch (ClassNotFoundException e) {
                // ignore
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:devefx,项目名称:validator-web,代码行数:23,代码来源:ClassPathScanner.java

示例3: copyJar

import java.util.jar.JarFile; //导入方法依赖的package包/类
private File copyJar(File file, String manifest) throws IOException {
    File ret = File.createTempFile(file.getName(), "2ndcopy", file.getParentFile());
    JarFile jar = new JarFile(file);
    JarOutputStream os = new JarOutputStream(new FileOutputStream(ret), new Manifest(
        new ByteArrayInputStream(manifest.getBytes())
    ));
    Enumeration<JarEntry> en = jar.entries();
    while (en.hasMoreElements()) {
        JarEntry elem = en.nextElement();
        if (elem.getName().equals("META-INF/MANIFEST.MF")) {
            continue;
        }
        os.putNextEntry(elem);
        InputStream is = jar.getInputStream(elem);
        copyStreams(is, os);
        is.close();
    }
    os.close();
    return ret;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ModuleManagerTest.java

示例4: loadAllClass

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * 加载jar的所有类
 * 
 * @param jarFiles
 * @param loader
 * @return
 * @throws ClassNotFoundException
 * @throws IOException
 */
protected Set<Class<?>> loadAllClass(File jarFile, ScriptClassLoader loader) throws Exception {
	Set<Class<?>> clzzs = new HashSet<Class<?>>();
	JarFile jf = new JarFile(jarFile);
	try {
		loader.addURL(jarFile.toURI().toURL());// 添加文件到加载器
		Enumeration<JarEntry> it = jf.entries();
		while (it.hasMoreElements()) {
			JarEntry jarEntry = it.nextElement();
			if (jarEntry.getName().endsWith(".class")) {
				String className = jarEntry.getName().replace("/", ".").replaceAll(".class", "");
				clzzs.add(loader.findClass(className));
			}
		}
	} finally {
		jf.close();
	}
	return clzzs;
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:28,代码来源:AbstractLibScriptFactory.java

示例5: checkJarFile

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * Private helper method.
 *
 * @param connection
 *            the connection to the jar
 * @param pckgname
 *            the package name to search for
 * @param classes
 *            the current ArrayList of all classes. This method will simply
 *            add new classes.
 * @throws ClassNotFoundException
 *             if a file isn't loaded but still is in the jar file
 * @throws IOException
 *             if it can't correctly read from the jar file.
 */
private static void checkJarFile(JarURLConnection connection,
                                 String pckgname, ArrayList<Class<?>> classes)
        throws ClassNotFoundException, IOException {
    final JarFile jarFile = connection.getJarFile();
    final Enumeration<JarEntry> entries = jarFile.entries();
    String name;

    for (JarEntry jarEntry = null; entries.hasMoreElements()
            && ((jarEntry = entries.nextElement()) != null);) {
        name = jarEntry.getName();

        if (name.contains(".class")) {
            name = name.substring(0, name.length() - 6).replace('/', '.');

            if (name.contains(pckgname)) {
                classes.add(Class.forName(name));
            }
        }
    }
}
 
开发者ID:fr1kin,项目名称:ForgeHax,代码行数:36,代码来源:ClassLoaderHelper.java

示例6: loadClassFromJarFile

import java.util.jar.JarFile; //导入方法依赖的package包/类
private static List<Class<?>> loadClassFromJarFile(URL url) {
    List<Class<?>> list = new LinkedList<>();
    try {
        JarURLConnection connection = (JarURLConnection) url.openConnection();
        JarFile jarFile = connection.getJarFile();
        Enumeration<JarEntry> jarEntries = jarFile.entries();
        while (jarEntries.hasMoreElements()) {
            String entryName = jarEntries.nextElement().getName();
            if (entryName.endsWith(".class")) {
                list.add(loadClass(entryName.substring(0, entryName.length() - 6).replace("/", ".")));
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return list;
}
 
开发者ID:omsfuk,项目名称:Samurai,代码行数:18,代码来源:ClassUtil.java

示例7: getRenameMap

import java.util.jar.JarFile; //导入方法依赖的package包/类
public Map<String, String> getRenameMap(String jarFilePath) {
    Map<String, String> map = new HashMap<>();
    try {
        File jarFile = new File(jarFilePath);
        JarFile file = new JarFile(jarFile);
        Enumeration<JarEntry> enumeration = file.entries();
        while (enumeration.hasMoreElements()) {
            JarEntry jarEntry = enumeration.nextElement();
            String entryName = jarEntry.getName();
            String className;
            if (entryName.endsWith(".class")) {
                className = Utils.path2Classname(entryName);
                String simpleName = className.substring(className.lastIndexOf('.') + 1);
                if (Utils.isProguardedName(simpleName)) {
                    map.put(className, getNewClassName(className, simpleName));
                }
            }
        }
        file.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return map;
}
 
开发者ID:BryanSharp,项目名称:Jar2Java,代码行数:26,代码来源:JarAnalyzer.java

示例8: checkJarFile

import java.util.jar.JarFile; //导入方法依赖的package包/类
private void checkJarFile(final ClassLoader classLoader, final URL url, final String pckgname) throws IOException {
    final JarURLConnection conn = (JarURLConnection) url.openConnection();
    final JarFile jarFile = conn.getJarFile();
    final Enumeration<JarEntry> entries = jarFile.entries();

    while (entries.hasMoreElements()) {
        final JarEntry jarEntry = entries.nextElement();

        String name = jarEntry.getName();

        if (name.endsWith(".class")) {
            name = name.substring(0, name.length() - 6).replace('/', '.');

            if (name.startsWith(pckgname)) {
                addClass(classLoader, name);
            }
        }
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:20,代码来源:ClassPathScanner.java

示例9: getClassNameByJar

import java.util.jar.JarFile; //导入方法依赖的package包/类
/** 
  * Get all classes from jar under a package
  * @param jarPath  the jar file path
  * @param childPackage  whether to traverse the sub package
  * @return the full name of the class 
  */  
 private static List<String> getClassNameByJar(String jarPath, boolean childPackage) {  
     List<String> myClassName = new ArrayList<String>();  
     String[] jarInfo = jarPath.split("!");  
     String jarFilePath = jarInfo[0].substring(jarInfo[0].indexOf("/"));  
     String packagePath = jarInfo[1].substring(1);  
     try {  
         @SuppressWarnings("resource")
JarFile jarFile = new JarFile(jarFilePath);  
         Enumeration<JarEntry> entrys = jarFile.entries();  
         while (entrys.hasMoreElements()) {  
             JarEntry jarEntry = entrys.nextElement();  
             String entryName = jarEntry.getName();  
             if (entryName.endsWith(".class")) {  
                 if (childPackage) {  
                     if (entryName.startsWith(packagePath)) {  
                         entryName = entryName.replace("/", ".").substring(0, entryName.lastIndexOf("."));  
                         myClassName.add(entryName);  
                     }  
                 } else {  
                     int index = entryName.lastIndexOf("/");  
                     String myPackagePath;  
                     if (index != -1) {  
                         myPackagePath = entryName.substring(0, index);  
                     } else {  
                         myPackagePath = entryName;  
                     }  
                     if (myPackagePath.equals(packagePath)) {  
                         entryName = entryName.replace("/", ".").substring(0, entryName.lastIndexOf("."));  
                         myClassName.add(entryName);  
                     }  
                 }  
             }  
         }  
     } catch (Exception e) {  
         e.printStackTrace();  
     }  
     return myClassName;  
 }
 
开发者ID:395299296,项目名称:librec-to-movies,代码行数:45,代码来源:Util.java

示例10: changeManifest

import java.util.jar.JarFile; //导入方法依赖的package包/类
protected File changeManifest(File orig, String manifest) throws IOException {
    File f = new File(getWorkDir(), orig.getName());
    Manifest mf = new Manifest(new ByteArrayInputStream(manifest.getBytes("utf-8")));
    mf.getMainAttributes().putValue("Manifest-Version", "1.0");
    JarOutputStream os = new JarOutputStream(new FileOutputStream(f), mf);
    JarFile jf = new JarFile(orig);
    Enumeration<JarEntry> en = jf.entries();
    InputStream is;
    while (en.hasMoreElements()) {
        JarEntry e = en.nextElement();
        if (e.getName().equals("META-INF/MANIFEST.MF")) {
            continue;
        }
        os.putNextEntry(e);
        is = jf.getInputStream(e);
        byte[] arr = new byte[4096];
        for (;;) {
            int len = is.read(arr);
            if (len == -1) {
                break;
            }
            os.write(arr, 0, len);
        }
        is.close();
        os.closeEntry();
    }
    os.close();
    return f;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:SetupHid.java

示例11: listClasses

import java.util.jar.JarFile; //导入方法依赖的package包/类
private void listClasses(URLClassLoader loader, JarFile jarFile) {
    for (Enumeration<JarEntry> entries = jarFile.entries();
         entries.hasMoreElements(); ) {
        JarEntry entry = entries.nextElement();
        final String className = withoutExt(entry.getName()).replaceAll("/", ".");
        try {
            listClass(loader, className);
        } catch (ClassNotFoundException | NoClassDefFoundError e) {
            log.info("File [{}]{} does not seem to be a class of {}, probably resource file", jarFile.getName(), entry.getName(), className);
        }
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-By-Example,代码行数:13,代码来源:ClassLister.java

示例12: testUnusualFileSize

import java.util.jar.JarFile; //导入方法依赖的package包/类
/** Too large or too small (empty) files are suspicious.
 *  There should be just couple of them: splash image
 */
public void testUnusualFileSize() throws Exception {
    SortedSet<Violation> violations = new TreeSet<Violation>();
    for (File f: org.netbeans.core.startup.Main.getModuleSystem().getModuleJars()) {
        // check JAR files only
        if (!f.getName().endsWith(".jar"))
            continue;
        
        JarFile jar = new JarFile(f);
        Enumeration<JarEntry> entries = jar.entries();
        JarEntry entry;
        BufferedImage img;
        while (entries.hasMoreElements()) {
            entry = entries.nextElement();
            if (entry.isDirectory())
                continue;
            
            long len = entry.getSize();
            if (len >= 0 && len < 10) {
                violations.add(new Violation(entry.getName(), jar.getName(), " is too small ("+len+" bytes)"));
            }
            if (len >= 200 * 1024) {
                violations.add(new Violation(entry.getName(), jar.getName(), " is too large ("+len+" bytes)"));
            }
        }
    }
    if (!violations.isEmpty()) {
        StringBuilder msg = new StringBuilder();
        msg.append("Some files have extreme size ("+violations.size()+"):\n");
        for (Violation viol: violations) {
            msg.append(viol).append('\n');
        }
        fail(msg.toString());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:ResourcesTest.java

示例13: setClasses

import java.util.jar.JarFile; //导入方法依赖的package包/类
protected void setClasses(String jarPath) throws Exception {
    ArrayList<String> names = new ArrayList(16);
    ArrayList<byte[]> bytes = new ArrayList(16);
    JarFile file = new JarFile(jarPath);
    Enumeration<JarEntry> entries = file.entries();
    ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
    int read = 0;
    byte[] buffer = new byte[1024];

    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();

        if (entry.getName().endsWith(".class")) {
            String nm = entry.getName();
            nm = nm.substring(0, nm.lastIndexOf('.'));
            names.add(nm);

            BufferedInputStream bis = new BufferedInputStream(file.getInputStream(entry));

            while ((read = bis.read(buffer)) > -1) {
                bos.write(buffer, 0, read);
            }

            bis.close();
            bytes.add(bos.toByteArray());
            bos.reset();
        }
    }

    classNames = names.toArray(new String[0]);
    classesBytes = bytes.toArray(new byte[0][]);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:InstrumentationTest.java

示例14: doRetrieveMatchingJarEntries

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * Extract entries from the given jar by pattern.
 * @param jarFilePath the path to the jar file
 * @param entryPattern the pattern for jar entries to match
 * @param result the Set of matching Resources to add to
 */
private void doRetrieveMatchingJarEntries(String jarFilePath, String entryPattern, Set<Resource> result) {
	if (logger.isDebugEnabled()) {
		logger.debug("Searching jar file [" + jarFilePath + "] for entries matching [" + entryPattern + "]");
	}
	try {
		JarFile jarFile = new JarFile(jarFilePath);
		try {
			for (Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
				JarEntry entry = entries.nextElement();
				String entryPath = entry.getName();
				if (getPathMatcher().match(entryPattern, entryPath)) {
					result.add(new UrlResource(
							ResourceUtils.URL_PROTOCOL_JAR,
							ResourceUtils.FILE_URL_PREFIX + jarFilePath + ResourceUtils.JAR_URL_SEPARATOR + entryPath));
				}
			}
		}
		finally {
			jarFile.close();
		}
	}
	catch (IOException ex) {
		if (logger.isWarnEnabled()) {
			logger.warn("Cannot search for matching resources in jar file [" + jarFilePath +
					"] because the jar cannot be opened through the file system", ex);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:ServletContextResourcePatternResolver.java

示例15: inject

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * The injection of code for the specified jar package
 *
 * @param inJar
 * @param outJar
 * @throws IOException
 * @throws NotFoundException
 * @throws CannotCompileException
 */
public static List<String> inject(ClassPool pool,
                                  File inJar,
                                  File outJar,
                                  InjectParam injectParam) throws Exception {
    List<String> errorFiles = new ArrayList<String>();
    JarFile jarFile = newJarFile(inJar);

    outJar.getParentFile().mkdirs();
    FileOutputStream fileOutputStream = new FileOutputStream(outJar);
    JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(fileOutputStream));
    Enumeration<JarEntry> jarFileEntries = jarFile.entries();
    JarEntry jarEntry = null;
    while (jarFileEntries.hasMoreElements()) {
        jarEntry = jarFileEntries.nextElement();
        String name = jarEntry.getName();
        String className = StringUtils.replace(name, File.separator, "/");
        className = StringUtils.replace(className, "/", ".");
        className = StringUtils.substring(className, 0, className.length() - 6);
        if (!StringUtils.endsWithIgnoreCase(name, ".class")) {
            InputStream inputStream = jarFile.getInputStream(jarEntry);
            copyStreamToJar(inputStream, jos, name, jarEntry.getTime(), jarEntry);
            IOUtils.closeQuietly(inputStream);
        } else {
            byte[] codes;

            codes = inject(pool, className, injectParam);
            InputStream classInstream = new ByteArrayInputStream(codes);
            copyStreamToJar(classInstream, jos, name, jarEntry.getTime(), jarEntry);

        }
    }
    jarFile.close();
    IOUtils.closeQuietly(jos);
    return errorFiles;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:45,代码来源:CodeInjectByJavassist.java


注:本文中的java.util.jar.JarFile.entries方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。