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


Java JarFile.getName方法代码示例

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


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

示例1: getFromJarFile

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * Browse a jar file for the desired class.
 * @param jarFile The jar file to browse.
 * @param name The full name of the class to find.
 * @return A ClassFile in case of success, null otherwise.
 * @throws ClassFileException Thrown on fatal errors loading or parsing a class file.
 * @throws IOException Thrown on fatal problems reading or writing to the file system.
 */
private ClassFile getFromJarFile(JarFile jarFile, String name) throws ClassFileException, IOException {
	Enumeration<JarEntry> entries = jarFile.entries();
	while (entries.hasMoreElements()) {
		/*
		 * Just browse trough all entries, they probably will not be shown hierarchically or in
		 * a sorted order.
		 */
		JarEntry entry = entries.nextElement();
		if (entry != null && entry.getName().equals(name)) {
			// Construct the full path to the class file.
			String fullPath = jarFile.getName() + "|" + entry.getName();

			// Return the ClassFile.
			try {
				return new ClassFile(this, jarFile.getInputStream(entry), jarFile
						.getInputStream(entry), entry.getSize(), fullPath);
			} catch(Exception e) {
				e.printStackTrace();
				return null;
			}
		}
	}
	return null;
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:33,代码来源:MugglClassLoader.java

示例2: compareJars

import java.util.jar.JarFile; //导入方法依赖的package包/类
public static void compareJars(JarFile jf1, JarFile jf2) throws Exception {
    try {
        if (jf1.size() != jf2.size()) {
            throw new Exception("Jars " + jf1.getName() + " and " + jf2.getName()
                    + " have different number of entries");
        }
        for (JarEntry elem1 : Collections.list(jf1.entries())) {
            JarEntry elem2 = jf2.getJarEntry(elem1.getName());
            if (elem2 == null) {
                throw new Exception("Element " + elem1.getName() + " is missing from " + jf2.getName());
            }
            if (!elem1.isDirectory() && elem1.getCrc() != elem2.getCrc()) {
                throw new Exception("The crc of " + elem1.getName() + " is different.");
            }
        }
    } finally {
        jf1.close();
        jf2.close();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:TestNormal.java

示例3: getTemporaryInputStream

import java.util.jar.JarFile; //导入方法依赖的package包/类
private InputStream getTemporaryInputStream(JarFile jf, JarEntry je, boolean forceRecreate)
throws IOException {
    String filePath = jf.getName();
    String entryPath = je.getName();
    StringBuffer jarCacheFolder = new StringBuffer("jarfscache"); //NOI18N
    jarCacheFolder.append(System.getProperty("user.name")).append("/"); //NOI18N        

    File jarfscache = new File(System.getProperty("java.io.tmpdir"), jarCacheFolder.toString()); //NOI18N

    if (!jarfscache.exists()) {
        jarfscache.mkdirs();
    }

    File f = new File(jarfscache, temporaryName(filePath, entryPath));

    boolean createContent = !f.exists();

    if (createContent) {
        f.createNewFile();
    } else {
        forceRecreate |= (Math.abs((System.currentTimeMillis() - f.lastModified())) > 10000);
    }

    if (createContent || forceRecreate) {
        // JDK 1.3 contains bug #4336753
        //is = j.getInputStream (je);
        try (InputStream is = getInputStream4336753(jf, je); OutputStream os = Files.newOutputStream(f.toPath())) {
            FileUtil.copy(is, os);
        } catch (InvalidPathException ex) {
            throw new IOException(ex);
        }
    }

    f.deleteOnExit();

    return Files.newInputStream(f.toPath());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:JarFileSystem.java

示例4: logJarVersions

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * Logs the names, versions and commit SHAs of relevant JAR files.
 */
private void logJarVersions() {
    Collection<File> jarFiles = null;

    List<JarFile> jars = new LinkedList<>();
    JarFile mainJar = JarUtil.getJarFile(TestActor.class);
    if (mainJar != null) {
        jars.add(mainJar);
        File mainJarFile = new File(mainJar.getName());
        jarFiles = FileUtils.listFiles(mainJarFile.getParentFile(), new String[]{"jar"}, true);
    } else {
        jarFiles = FileUtils.listFiles(new File("."), new String[]{"jar"}, true);
    }

    if (jarFiles != null && jarFiles.size() > 0) {
        Logger.debug("Test actor JAR versions:");

        for (File childFile : jarFiles) {
            if (childFile.getName().matches("dtest.+\\.jar|opentest.+\\.jar")) {
                try {
                    JarFile jar = new JarFile(childFile);
                    Logger.debug(String.format("  %s: %s %s",
                            new File(jar.getName()).getName(),
                            JarUtil.getManifestAttribute(jar, "Build-Time"),
                            JarUtil.getManifestAttribute(jar, "Implementation-Version")));
                } catch (IOException ex) {
                    Logger.warning(String.format("Failed to determine version for JAR %s",
                            childFile.getName()));
                }
            }
        }
    }
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:36,代码来源:TestActor.java

示例5: loadPluginDescription

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * 加载插件信息
 *
 * @param file 插件 Jar 文件
 * @return 插件信息
 */
public PluginDescription loadPluginDescription(JarFile file) throws PluginException {
	PluginDescription description = getDescription(file);
	if (description == null) {
		throw new PluginException("could not load plugin description in plugin file " + file.getName());
	}

	descriptions.put(file.getName(), description);
	return description;
}
 
开发者ID:Him188,项目名称:JPRE,代码行数:16,代码来源:PluginManager.java

示例6: add

import java.util.jar.JarFile; //导入方法依赖的package包/类
public static void add(JarFile jarfile, JarEntry e, ClassFile cf)
        throws ConstantPoolException
{
    String realName = SharedSecrets.javaUtilJarAccess().getRealName(jarfile, e);
    if (realName.startsWith(META_INF_VERSIONS)) {
        int len = META_INF_VERSIONS.length();
        int n = realName.indexOf('/', len);
        if (n > 0) {
            String version = realName.substring(len, n);
            assert (Integer.parseInt(version) > 8);
            String name = cf.getName().replace('/', '.');
            if (nameToVersion.containsKey(name)) {
                if (!version.equals(nameToVersion.get(name))) {
                    throw new MultiReleaseException(
                            "err.multirelease.version.associated",
                            name, nameToVersion.get(name), version
                    );
                }
            } else {
                nameToVersion.put(name, version);
            }
        } else {
            throw new MultiReleaseException("err.multirelease.jar.malformed",
                    jarfile.getName(), realName);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:VersionHelper.java

示例7: scanJarFile

import java.util.jar.JarFile; //导入方法依赖的package包/类
@Override protected void scanJarFile(ClassLoader loader, JarFile file) throws IOException {
  this.found = new File(file.getName());
  throw new StopScanningException();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:5,代码来源:ClassPathTest.java

示例8: getCurrentClassPath

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * Get the basic class path and replace the first class path entry
 * with it.
 */
protected void getCurrentClassPath() {
	// Get the current class path.
	if (this.directoryTree.getSelection().length > 0) {
		String newEntry = "";
		TreeItem item = this.directoryTree.getSelection()[0];
		Object data = item.getData();
		if (data instanceof JarFileEntry) {
			// just add the jar file as the class path entry
			JarFileEntry jfe = (JarFileEntry) data;
			JarFile jf = jfe.getJarFile();
			newEntry = jf.getName();
			this.currentClassPackage = jfe.getFileName().replace("/", ".").replace("\\", ".");
		} else if (data instanceof File && ((File) data).isFile()) {
			// It is just a single file, so add the path to it.
			newEntry =  ((File) data).getPath();
			this.currentClassPackage = "";
		} else {
			// Try to find out if we are somewhere in a structure with a root dir "bin". Otherwise just add the current dir.
			String fullPath = "";
			boolean resetClassPackage = true;
			while (item != null) {
				fullPath = item.getText() + "/" + fullPath;
				if (item.getText().toLowerCase().equals("bin")) {
					fullPath = fullPath.replace("/", ".").replace("\\", ".");
					if (fullPath.contains(".")) {
						fullPath = fullPath.substring(fullPath.indexOf(".") + 1);
					}
					this.currentClassPackage = fullPath;
					resetClassPackage = false;
					fullPath = "/bin"; // Forget where this leads to.
				}
				item = item.getParentItem();
			}
			if (resetClassPackage) {
				this.currentClassPackage = "";
			}
			fullPath = fullPath.replace("\\/", "/");
			fullPath = fullPath.replace("\\", "/");
			fullPath = fullPath.replace("//", "/");
			newEntry = fullPath;
			if (!newEntry.substring(newEntry.length() - 1).equals("/")) newEntry += "/";
		}

		// Set the entry.
		if (Options.getInst().classPathEntries.size() == 0) {
			Options.getInst().classPathEntries.add(newEntry);
		} else {
			Options.getInst().classPathEntries.set(0, newEntry);
		}

		// Update the classLoader.
		this.classLoader.updateClassPath(StaticGuiSupport.arrayList2StringArray(Options.getInst().classPathEntries), !Options.getInst().doNotClearClassLoaderCache);
	}
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:59,代码来源:FileSelectionComposite.java

示例9: extractFingerPrints

import java.util.jar.JarFile; //导入方法依赖的package包/类
public void extractFingerPrints() throws IOException, ClassHierarchyException, ClassNotFoundException {
	long starttime = System.currentTimeMillis();
	
	logger.info("Process library: " + libraryFile.getName());
	logger.info("Library description:");
	for (String desc: libDesc.getDescription())
		logger.info(desc);
	
	// create analysis scope and generate class hierarchy
	final AnalysisScope scope = AnalysisScope.createJavaAnalysisScope();
	
	JarFile jf = libraryFile.getName().endsWith(".aar")? new AarFile(libraryFile).getJarFile() : new JarFile(libraryFile); 
	scope.addToScope(ClassLoaderReference.Application, jf);
	scope.addToScope(ClassLoaderReference.Primordial, new JarFile(CliOptions.pathToAndroidJar));

	IClassHierarchy cha = ClassHierarchy.make(scope);
	getChaStats(cha);
	
	// cleanup tmp files if library input was an .aar file
	if (libraryFile.getName().endsWith(".aar")) {
		File tmpJar = new File(jf.getName());
		tmpJar.delete();
		logger.debug(Utils.indent() + "tmp jar-file deleted at " + tmpJar.getName());
	}
	
	PackageTree pTree = Profile.generatePackageTree(cha);
	if (pTree.getRootPackage() == null) {
		logger.warn(Utils.INDENT + "Library contains multiple root packages");
	}

	List<HashTree> hTrees = Profile.generateHashTrees(cha);

	// if hash tree is empty do not dump a profile
	if (hTrees.isEmpty() || hTrees.get(0).getNumberOfClasses() == 0) {
		logger.error("Empty Hash Tree generated - SKIP");
		return;
	}		
		
	// serialize lib profiles to disk (<profilesDir>/<lib-category>/libName_libVersion.lib)
	logger.info("");
	File targetDir = new File(CliOptions.profilesDir + File.separator + libDesc.category.toString());
	logger.info("Serialize library fingerprint to disk (dir: " + targetDir + ")");
	String proFileName = libDesc.name.replaceAll(" ", "-") + "_" + libDesc.version + "." + FILE_EXT_LIB_PROFILE;
	LibProfile lp = new LibProfile(libDesc, pTree, hTrees);
	
	Utils.object2Disk(new File(targetDir + File.separator + proFileName), lp);
	
	logger.info("");
	logger.info("Processing time: " + Utils.millisecondsToFormattedTime(System.currentTimeMillis() - starttime));
}
 
开发者ID:reddr,项目名称:LibScout,代码行数:51,代码来源:LibraryProfiler.java


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