本文整理汇总了Java中java.util.jar.JarEntry.getName方法的典型用法代码示例。如果您正苦于以下问题:Java JarEntry.getName方法的具体用法?Java JarEntry.getName怎么用?Java JarEntry.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.jar.JarEntry
的用法示例。
在下文中一共展示了JarEntry.getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processJar
import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
* Store all class names found in this jar file
*/
private static LinkedList<String> processJar(File jarfile, String basepath) {
// System.out.println("Processing JAR " + jarfile.getPath());
LinkedList<String> addlist = new LinkedList<String>();
try {
JarInputStream jarIS = new JarInputStream(new FileInputStream(
jarfile));
JarEntry entry = null;
while ((entry = jarIS.getNextJarEntry()) != null) {
String name = entry.getName();
if (name.endsWith(".class")) {
// System.out.println( entry.getAttributes().toString() );
if (!add(name, jarfile.getPath(), basepath).isEmpty())
addlist.addAll(add(name, jarfile.getPath(), basepath));
}
}
} catch (Exception e) {
}
return addlist;
}
示例2: main
import java.util.jar.JarEntry; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
if (args.length >= 1) {
JarFile file = new JarFile(args[0]);
Enumeration<JarEntry> entries = file.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
String fileInfo = "Name: " + entry.getName();
if (entry.getLastModifiedTime() != null) {
fileInfo += ", Last Modified Time: " + entry.getLastModifiedTime();
}
if (entry.getAttributes() != null) {
fileInfo += ", Attributes: " + entry.getAttributes().entrySet();
}
System.out.println(fileInfo);
}
} else {
System.out.println("Example arguments: \"gamepack_127.jar\"");
}
}
示例3: findJarDirectory
import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
* Finds the directory within the zip-file in case the data file
* has been renamed.
*
* @param file The zip-file.
* @return The name of the base directory in the zip-file.
*/
private static String findJarDirectory(File file) {
String expected = file.getName().substring(0, file.getName().lastIndexOf('.'));
try (
JarFile jf = new JarFile(file);
) {
final JarEntry entry = jf.entries().nextElement();
final String en = entry.getName();
final int index = en.lastIndexOf('/');
String name = "";
if (index > 0) {
name = en.substring(0, index + 1);
}
return name;
} catch (Exception e) {
logger.log(Level.WARNING, "Exception while reading data file.", e);
return expected;
}
}
示例4: setRootMethods
import java.util.jar.JarEntry; //导入方法依赖的package包/类
protected void setRootMethods(String jarFile) throws Exception {
JarFile file = new JarFile(jarFile);
HashSet<String> list = new HashSet(8);
for (Enumeration<JarEntry> entries = file.entries(); entries.hasMoreElements();) {
JarEntry entry = entries.nextElement();
if (entry.getName().endsWith(".class")) {
String name = entry.getName();
int idx = name.lastIndexOf('/');
String packageName = (idx == -1) ? name : name.substring(0, idx);
packageName = packageName.replace('/', '.');
list.add(packageName);
}
}
ClientUtils.SourceCodeSelection[] ret = new ClientUtils.SourceCodeSelection[list.size()];
String[] cls = list.toArray(new String[0]);
for (int i = 0; i < list.size(); i++) {
ret[i] = new ClientUtils.SourceCodeSelection(cls[i] + ".", "", ""); //NOI18N
}
settings.setInstrumentationRootMethods(ret);
}
示例5: scanJar
import java.util.jar.JarEntry; //导入方法依赖的package包/类
protected void scanJar(URL jarUrl, Map<String, ResourceInfo> resInfos) throws IOException {
JarInputStream jarInput = new JarInputStream(jarUrl.openStream(), false);
JarEntry entry = null;
while((entry = jarInput.getNextJarEntry()) != null) {
String entryName = entry.getName();
if(entryName != null && entryName.endsWith(".class")) {
final String className = entryName.substring(0,
entryName.length() - 6).replace('/', '.');
if(!resInfos.containsKey(className)) {
ClassReader classReader = new ClassReader(jarInput);
ResourceInfo resInfo = new ResourceInfo(null, className, null);
ResourceInfoVisitor visitor = new ResourceInfoVisitor(resInfo);
classReader.accept(visitor, ClassReader.SKIP_CODE |
ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
if(visitor.isCreoleResource()) {
resInfos.put(className, resInfo);
}
}
}
}
jarInput.close();
}
示例6: loadImplementationsInJar
import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
* Finds matching classes within a jar files that contains a folder structure
* matching the package structure. If the File is not a JarFile or does not exist a warning
* will be logged, but no error will be raised.
*
* @param test a Test used to filter the classes that are discovered
* @param file the jar file to be examined for classes
* @return List of packages to export.
*/
List<String> loadImplementationsInJar(Test test, File file) {
List<String> localClsssOrPkgs = new ArrayList<String>();
Set<String> packages = jarContentCache.get(file.getPath());
if (packages == null) {
packages = new HashSet<String>();
try {
JarFile jarFile = new JarFile(file);
for (Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements(); ) {
JarEntry entry = e.nextElement();
String name = entry.getName();
if (!entry.isDirectory()) {
if (name.endsWith(SUFFIX_CLASS)) {
localClsssOrPkgs.add(name);
}
}
}
} catch (IOException ioe) {
log.error("Could not search jar file '" + file + "' for classes matching criteria: "
+ test + " due to an IOException" + ioe);
return Collections.emptyList();
} finally {
jarContentCache.put(file.getPath(), packages);
}
}
return localClsssOrPkgs;
}
示例7: analyzeDependencies
import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
* Analyze the dependencies of all classes in the given JAR file. The
* method updates knownTypes and unknownRefs as part of the analysis.
*/
static void analyzeDependencies(Path jarpath) throws Exception {
System.out.format("Analyzing %s%n", jarpath);
try (JarFile jf = new JarFile(jarpath.toFile())) {
Enumeration<JarEntry> entries = jf.entries();
while (entries.hasMoreElements()) {
JarEntry e = entries.nextElement();
String name = e.getName();
if (name.endsWith(".class")) {
ClassFile cf = ClassFile.read(jf.getInputStream(e));
for (Dependency d : finder.findDependencies(cf)) {
String origin = toClassName(d.getOrigin().getName());
String target = toClassName(d.getTarget().getName());
// origin is now known
unknownRefs.remove(origin);
knownTypes.add(origin);
// if the target is not known then record the reference
if (!knownTypes.contains(target)) {
Set<String> refs = unknownRefs.get(target);
if (refs == null) {
// first time seeing this unknown type
refs = new HashSet<>();
unknownRefs.put(target, refs);
}
refs.add(origin);
}
}
}
}
}
}
示例8: extractClassesFromJAR
import java.util.jar.JarEntry; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static List<Class<Class>> extractClassesFromJAR(File jar, ClassLoader cl) throws IOException {
List<Class<Class>> classes = new ArrayList<Class<Class>>();
JarInputStream jaris = new JarInputStream(new FileInputStream(jar));
JarEntry ent = null;
while ((ent = jaris.getNextJarEntry()) != null) {
if (ent.getName().toLowerCase().endsWith(".class")) {
try {
Class<Class> cls = (Class<Class>) cl.loadClass(ent.getName().substring(0, ent.getName().length() - 6).replace('/', '.'));
if (JPluginLoader.isPluggableClass(cls)) {
classes.add((Class<Class>)cls);
}
} catch (ClassNotFoundException e) {
String msg = "";
if(lang != null) {
msg = String.format(lang.getProperty("cant_load_class", "Could not load Class \"%s\""), ent.getName());
} else {
msg = "Can't load Class " + ent.getName();
}
if(logger != null) {
logger.logErr(msg, false);
} else {
System.err.println(msg);
}
e.printStackTrace();
}
}
}
jaris.close();
return classes;
}
示例9: getEntriesWithoutInnerClasses
import java.util.jar.JarEntry; //导入方法依赖的package包/类
public List<String> getEntriesWithoutInnerClasses() {
List<String> mass = new ArrayList<>();
Enumeration<JarEntry> entries = jfile.entries();
Set<String> possibleInnerClasses = new HashSet<String>();
Set<String> baseClasses = new HashSet<String>();
while (entries.hasMoreElements()) {
JarEntry e = entries.nextElement();
if (!e.isDirectory()) {
String entryName = e.getName();
if (entryName != null && entryName.trim().length() > 0) {
entryName = entryName.trim();
if (!entryName.endsWith(".class")) {
mass.add(entryName);
// com/acme/Model$16.class
} else if (entryName.matches(".*[^(/|\\\\)]+\\$[^(/|\\\\)]+$")) {
possibleInnerClasses.add(entryName);
} else {
baseClasses.add(entryName);
mass.add(entryName);
}
}
}
}
// keep Badly$Named but not inner classes
for (String inner : possibleInnerClasses) {
// com/acme/Connection$Conn$1.class -> com/acme/Connection
String innerWithoutTail = inner.replaceAll("\\$[^(/|\\\\)]+\\.class$", "");
if (!baseClasses.contains(innerWithoutTail + ".class")) {
mass.add(inner);
}
}
return mass;
}
示例10: setClasses
import java.util.jar.JarEntry; //导入方法依赖的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][]);
}
示例11: nextEntry
import java.util.jar.JarEntry; //导入方法依赖的package包/类
protected JarEntry nextEntry() {
while (entries.hasMoreElements()) {
JarEntry e = entries.nextElement();
String name = e.getName();
if (name.endsWith(".class")) {
return e;
}
}
return null;
}
示例12: getClassSet
import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
* 获取包名下的所有类
*/
public static Set<Class<?>> getClassSet(String packageName){
Set<Class<?>> classSet = new HashSet<Class<?>>();
try{
Enumeration<URL> urls = getClassLoader().getResources(packageName.replace(".","/"));
while(urls.hasMoreElements()){
URL url = urls.nextElement();
if(url != null){
String protocol = url.getProtocol();
if (protocol.equals("file")){
String packagePath = url.getPath().replaceAll("%20"," ");
addClass(classSet,packagePath,packageName);
}else if(protocol.equals("jar")){
JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
if (jarURLConnection != null){
JarFile jarFile = jarURLConnection.getJarFile();
if(jarFile != null){
Enumeration<JarEntry> jarEnties = jarFile.entries();
while(jarEnties.hasMoreElements()){
JarEntry jarEntry = jarEnties.nextElement();
String jarEntryName = jarEntry.getName();
if (jarEntryName.endsWith(".class")){
String className= jarEntryName.substring(0,jarEntryName.lastIndexOf(".")).replaceAll("/",".");
doAddClass(classSet,className);
}
}
}
}
}
}
}
}catch (Exception e){
LOGGER.error("get class set failure", e);
throw new RuntimeException(e);
}
return classSet;
}
示例13: getClassNameByJar
import java.util.jar.JarEntry; //导入方法依赖的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;
}
示例14: buildEntryNameToEntry
import java.util.jar.JarEntry; //导入方法依赖的package包/类
private static Map<String, JarEntry> buildEntryNameToEntry(
JarFile jarFile) throws IOException {
Map<String, JarEntry> entryNameToEntry = new HashMap<>();
Enumeration<? extends JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
String name = entry.getName();
entryNameToEntry.put(name, entry);
}
return entryNameToEntry;
}
示例15: test
import java.util.jar.JarEntry; //导入方法依赖的package包/类
@Override
public boolean test(JarEntry je) {
String name = je.getName();
// ## no support for excludes. Is it really needed?
return !name.endsWith(MODULE_INFO) && !je.isDirectory();
}