本文整理汇总了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;
}
}
示例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);
}
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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()]);
}
示例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();
}
}
}
示例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;
}
示例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();
}
}