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


Java JarEntry类代码示例

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


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

示例1: getPluginDescription

import java.util.jar.JarEntry; //导入依赖的package包/类
@Override
public PluginDescription getPluginDescription(File file) {
    try (JarFile jar = new JarFile(file)) {
        JarEntry entry = jar.getJarEntry("nukkit.yml");
        if (entry == null) {
            entry = jar.getJarEntry("plugin.yml");
            if (entry == null) {
                return null;
            }
        }
        try (InputStream stream = jar.getInputStream(entry)) {
            return new PluginDescription(Utils.readFile(stream));
        }
    } catch (IOException e) {
        return null;
    }
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:18,代码来源:JavaPluginLoader.java

示例2: resolveJar

import java.util.jar.JarEntry; //导入依赖的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

示例3: copyJar

import java.util.jar.JarEntry; //导入依赖的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: writeJarEntry

import java.util.jar.JarEntry; //导入依赖的package包/类
private static void writeJarEntry(JarOutputStream jos, String path, File f) throws IOException, FileNotFoundException {
    JarEntry je = new JarEntry(path);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    InputStream is = new FileInputStream(f);
    try {
        copyStreams(is, baos);
    } finally {
        is.close();
    }
    byte[] data = baos.toByteArray();
    je.setSize(data.length);
    CRC32 crc = new CRC32();
    crc.update(data);
    je.setCrc(crc.getValue());
    jos.putNextEntry(je);
    jos.write(data);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:SetupHid.java

示例5: createAgent

import java.util.jar.JarEntry; //导入依赖的package包/类
public static File createAgent(Class<?> agent, Class<?>... resources) throws IOException {
    File jarFile = File.createTempFile("agent", ".jar");
    jarFile.deleteOnExit();
    Manifest manifest = new Manifest();
    Attributes mainAttributes = manifest.getMainAttributes();
    mainAttributes.put(Name.MANIFEST_VERSION, "1.0");
    mainAttributes.put(new Name("Agent-Class"), agent.getName());
    mainAttributes.put(new Name("Can-Retransform-Classes"), "true");
    mainAttributes.put(new Name("Can-Redefine-Classes"), "true");
    JarOutputStream jos = new JarOutputStream(new FileOutputStream(jarFile), manifest);
    jos.putNextEntry(new JarEntry(agent.getName().replace('.', '/') + ".class"));
    jos.write(getBytesFromStream(agent.getClassLoader().getResourceAsStream(unqualify(agent))));
    jos.closeEntry();
    for (Class<?> clazz : resources) {
        String name = unqualify(clazz);
        jos.putNextEntry(new JarEntry(name));
        jos.write(getBytesFromStream(clazz.getClassLoader().getResourceAsStream(name)));
        jos.closeEntry();
    }

    jos.close();
    return jarFile;
}
 
开发者ID:OmarAhmed04,项目名称:Agent,代码行数:24,代码来源:Agent.java

示例6: doJar

import java.util.jar.JarEntry; //导入依赖的package包/类
private static void doJar(String a, File source, File dest,
                          ClassReader options, String encoding,
                          Boolean contError) throws IOException {
    try {
        JarFile jf = new JarFile(source);
        for (JarEntry je : Collections.list(jf.entries())) {
            String name = je.getName();
            if (!name.endsWith(".class")) {
                continue;
            }
            try {
                doStream(name, jf.getInputStream(je), dest, options, encoding);
            } catch (Exception e) {
                if (contError) {
                    System.out.println("Error processing " + source + ": " + e);
                    e.printStackTrace();
                    continue;
                }
            }
        }
    } catch (IOException ioe) {
        throw ioe;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:ClassReader.java

示例7: getRenameMap

import java.util.jar.JarEntry; //导入依赖的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: getClassName

import java.util.jar.JarEntry; //导入依赖的package包/类
/**
 * Converts a jar entry to a class name.
 * 
 * @param entry <code>JarEntry</code> to process.
 * @return The classname of the jar entry or <code>null</code> if it cannot be 
 *      devised.
 */
private static String getClassName(JarEntry entry) {
    final String name = entry.getName();
    
    if (name.endsWith(".class")) { // NOI18N
        final String className = 
                name.substring(0, name.length() - 6).replace('/', '.'); // NOMAGI
        if (className.matches(
                "([a-zA-Z][a-zA-Z0-9_]+\\.)+[a-zA-Z][a-zA-Z0-9_]+")) { // NOI18N
            return className;
        } else {
            return null;
        }
    }
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:VerifyFile.java

示例9: JarClassIterator

import java.util.jar.JarEntry; //导入依赖的package包/类
public JarClassIterator(JarFile jar) {
	m_jar = jar;
	
	// get the jar entries that correspond to classes
	List<JarEntry> classEntries = Lists.newArrayList();
	Enumeration<JarEntry> entries = m_jar.entries();
	while (entries.hasMoreElements()) {
		JarEntry entry = entries.nextElement();
		
		// is this a class file?
		if (entry.getName().endsWith(".class")) {
			classEntries.add(entry);
		}
	}
	m_iter = classEntries.iterator();
}
 
开发者ID:cccssw,项目名称:enigma-vk,代码行数:17,代码来源:JarClassIterator.java

示例10: loadAllClass

import java.util.jar.JarEntry; //导入依赖的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

示例11: findJarNativeEntry

import java.util.jar.JarEntry; //导入依赖的package包/类
/**
 * Finds native library entry.
 *
 * @param sLib Library name. For example for the library name "Native"
 *  - Windows returns entry "Native.dll"
 *  - Linux returns entry "libNative.so"
 *  - Mac returns entry "libNative.jnilib" or "libNative.dylib"
 *    (depending on Apple or Oracle JDK and/or JDK version)
 * @return Native library entry.
 */
private JarEntryInfo findJarNativeEntry(String sLib) {
    String sName = System.mapLibraryName(sLib);
    for (JarFileInfo jarFileInfo : lstJarFile) {
        JarFile jarFile = jarFileInfo.jarFile;
        Enumeration<JarEntry> en = jarFile.entries();
        while (en.hasMoreElements()) {
            JarEntry je = en.nextElement();
            if (je.isDirectory()) {
                continue;
            }
            // Example: sName is "Native.dll"
            String sEntry = je.getName(); // "Native.dll" or "abc/xyz/Native.dll"
            // sName "Native.dll" could be found, for example
            //   - in the path: abc/Native.dll/xyz/my.dll <-- do not load this one!
            //   - in the partial name: abc/aNative.dll   <-- do not load this one!
            String[] token = sEntry.split("/"); // the last token is library name
            if (token.length > 0 && token[token.length - 1].equals(sName)) {
                logInfo(LogArea.NATIVE, "Loading native library '%s' found as '%s' in JAR %s",
                        sLib, sEntry, jarFileInfo.simpleName);
                return new JarEntryInfo(jarFileInfo, je);
            }
        }
    }
    return null;
}
 
开发者ID:Energyxxer,项目名称:Vanilla-Injection,代码行数:36,代码来源:JarClassLoader.java

示例12: getClasses

import java.util.jar.JarEntry; //导入依赖的package包/类
private Class<?>[] getClasses(File jarFile) {
    Set<Class<?>> classes = new HashSet<>();
    try {
        JarFile file = new JarFile(jarFile);
        for (Enumeration<JarEntry> entry = file.entries(); entry.hasMoreElements(); ) {
            JarEntry jarEntry = entry.nextElement();
            String jarName = jarEntry.getName().replace('/', '.');

            if (jarName.endsWith(".class")) {
                if (!jarName.contains("1_8") && !jarName.contains("1_9") && !jarName.contains("1_10") && !jarName.contains("1_11") && !jarName.contains("1_7"))
                    classes.add(Class.forName(jarName.substring(0, jarName.length() - 6)));
            }
        }
        file.close();
    } catch (IOException | ClassNotFoundException ex) {
        Bukkit.getLogger().severe("Error ocurred at getting classes, log: " + ex);
    }

    return classes.toArray(new Class[classes.size()]);
}
 
开发者ID:AlphaHelixDev,项目名称:AlphaLibary,代码行数:21,代码来源:AlphaLibary.java

示例13: writeFileObjects

import java.util.jar.JarEntry; //导入依赖的package包/类
private void writeFileObjects(JarOutputStream jos) throws IOException {
    for (FileObject fo : fileObjects) {
        String p = guessPath(fo);
        JarEntry e = new JarEntry(p);
        jos.putNextEntry(e);
        try {
            byte[] buf = new byte[1024];
            try (BufferedInputStream in = new BufferedInputStream(fo.openInputStream())) {
                int n;
                while ((n = in.read(buf)) > 0)
                    jos.write(buf, 0, n);
            } catch (IOException ex) {
                error("Exception while adding " + fo.getName() + " to jar file", ex);
            }
    } finally {
            jos.closeEntry();
    }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:JarTask.java

示例14: listTestsFromJar

import java.util.jar.JarEntry; //导入依赖的package包/类
private static Collection<String> listTestsFromJar(File archive) {
    Collection<String> result = new LinkedList<String>();

    try {
        JarFile jf = new JarFile(archive);
        Enumeration<JarEntry> entries = jf.entries();

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

            if (entry.getName().endsWith(".test")) {
                result.add(entry.getName());
            }
        }
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
    
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:DeclarativeHintsTestBase.java

示例15: createRealJarFile

import java.util.jar.JarEntry; //导入依赖的package包/类
public void createRealJarFile(File f) throws Exception {
        OutputStream os = new FileOutputStream(f);
        try {
            JarOutputStream jos = new JarOutputStream(os);
//            jos.setMethod(ZipEntry.STORED);
            JarEntry entry = new JarEntry("foo.txt");
//            entry.setSize(0L);
//            entry.setTime(System.currentTimeMillis());
//            entry.setCrc(new CRC32().getValue());
            jos.putNextEntry(entry);
            jos.flush();
            jos.close();
        } finally {
            os.close();
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:JavaProjectGeneratorTest.java


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