本文整理汇总了Java中java.util.jar.JarFile.getJarEntry方法的典型用法代码示例。如果您正苦于以下问题:Java JarFile.getJarEntry方法的具体用法?Java JarFile.getJarEntry怎么用?Java JarFile.getJarEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.jar.JarFile
的用法示例。
在下文中一共展示了JarFile.getJarEntry方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadLocalizedBundlesFromPlatform
import java.util.jar.JarFile; //导入方法依赖的package包/类
private void loadLocalizedBundlesFromPlatform(final BrandableModule moduleEntry,
final String bundleEntry, final Set<String> keys, final Set<BundleKey> bundleKeys) throws IOException {
Properties p = new Properties();
JarFile module = new JarFile(moduleEntry.getJarLocation());
JarEntry je = module.getJarEntry(bundleEntry);
InputStream is = module.getInputStream(je);
File bundle = new File(getModuleEntryDirectory(moduleEntry),bundleEntry);
try {
p.load(is);
} finally {
is.close();
}
for (String key : NbCollections.checkedMapByFilter(p, String.class, String.class, true).keySet()) {
if (keys.contains(key)) {
String value = p.getProperty(key);
bundleKeys.add(new BundleKey(moduleEntry, bundle, key, value));
}
}
}
示例2: getEntry
import java.util.jar.JarFile; //导入方法依赖的package包/类
/** Getter for entry.
*/
private final JarEntry getEntry(String file) {
JarFile j = null;
try {
synchronized (closeSync) {
j = reOpenJarFile();
JarEntry je = null;
if (j != null) {
je = j.getJarEntry(file);
}
if (je != null) {
return je;
}
}
} catch (IOException iox) {
}
return new JarEntry(file);
}
示例3: findClassInJarFile
import java.util.jar.JarFile; //导入方法依赖的package包/类
protected Class<?> findClassInJarFile(String qualifiedClassName) throws ClassNotFoundException {
URI classUri = URIUtil.buildUri(StandardLocation.CLASS_OUTPUT, qualifiedClassName);
String internalClassName = classUri.getPath().substring(1);
JarFile jarFile = null;
try {
for (int i = 0; i < jarFiles.size(); i++) {
jarFile = jarFiles.get(i);
JarEntry jarEntry = jarFile.getJarEntry(internalClassName);
if (jarEntry != null) {
InputStream inputStream = jarFile.getInputStream(jarEntry);
try {
byte[] byteCode = new byte[(int) jarEntry.getSize()];
ByteStreams.read(inputStream, byteCode, 0, byteCode.length);
return defineClass(qualifiedClassName, byteCode, 0, byteCode.length);
} finally {
Closeables.closeQuietly(inputStream);
}
}
}
} catch (IOException e) {
throw new IllegalStateException(String.format("Failed to lookup class %s in jar file %s", qualifiedClassName, jarFile), e);
}
return null;
}
示例4: 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();
}
}
示例5: setUp
import java.util.jar.JarFile; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
URI jarFileURI = Test_ConfigurationParser.class.getResource( "/agenttest.jar" ).toURI();
JarFile jarFile = new JarFile( new File( jarFileURI ) );
JarEntry entry = jarFile.getJarEntry( "META-INF/agent_descriptor.xml" );
descriptorFileStream = jarFile.getInputStream( entry );
jarFileAbsolutePath = ( new File( jarFileURI ) ).getAbsolutePath();
}
示例6: findClass
import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
* Finds the <code>.class</code> file for a given class.
*
* @param className Class name
* @return File for the class.
*/
public static InputStream findClass(String className) {
for(File path : paths) {
// JAR File
if(path.isFile()) {
try {
JarFile jar = new JarFile(path);
JarEntry entry = jar.getJarEntry(className + ".class");
if(entry != null) {
return jar.getInputStream(entry);
}
} catch(IOException e) {
// Just go to next path.
}
// Directory
} else {
try {
return new FileInputStream(new File(path, className + ".class"));
} catch (FileNotFoundException ex) {
// Just go to next path.
}
}
}
return null;
}
示例7: findResourcesInJarFiles
import java.util.jar.JarFile; //导入方法依赖的package包/类
protected void findResourcesInJarFiles(List<URL> result, String resource) throws MalformedURLException {
for (JarFile jarFile : jarFiles) {
JarEntry entry = jarFile.getJarEntry(resource);
if (entry != null) {
result.add(new URL("jar", "", String.format("file:%s!%s", jarFile.getName(), resource)));
}
}
}
示例8: findEntry
import java.util.jar.JarFile; //导入方法依赖的package包/类
private static JarEntry findEntry(JarFile jar, String headerName, String defaultPath) throws IOException {
String path = defaultPath;
String headerPath = jar.getManifest().getMainAttributes().getValue(headerName);
if (headerPath != null) {
path = headerPath.trim();
}
if (path == null) {
// Could happen if no default and no header
return null;
}
return jar.getJarEntry(path);
}
示例9: validateJarFile
import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
* Check the specified JAR file, and return <code>true</code> if it does
* not contain any of the trigger classes.
*
* @param jarfile The JAR file to be checked
*
* @exception IOException if an input/output error occurs
*/
protected boolean validateJarFile(File jarfile)
throws IOException {
if (triggers == null)
return (true);
JarFile jarFile = new JarFile(jarfile);
for (int i = 0; i < triggers.length; i++) {
Class clazz = null;
try {
if (parent != null) {
clazz = parent.loadClass(triggers[i]);
} else {
clazz = Class.forName(triggers[i]);
}
} catch (Throwable t) {
clazz = null;
}
if (clazz == null)
continue;
String name = triggers[i].replace('.', '/') + ".class";
if (log.isDebugEnabled())
log.debug(" Checking for " + name);
JarEntry jarEntry = jarFile.getJarEntry(name);
if (jarEntry != null) {
log.info("validateJarFile(" + jarfile +
") - jar not loaded. See Servlet Spec 2.3, "
+ "section 9.7.2. Offending class: " + name);
jarFile.close();
return (false);
}
}
jarFile.close();
return (true);
}
示例10: validateJarFile
import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
* Check the specified JAR file, and return <code>true</code> if it does
* not contain any of the trigger classes.
*
// * @param jarFile The JAR file to be checked
*
* @exception IOException if an input/output error occurs
*/
private boolean validateJarFile(File jarfile)
throws IOException {
if (triggers == null)
return (true);
JarFile jarFile = new JarFile(jarfile);
for (int i = 0; i < triggers.length; i++) {
Class clazz = null;
try {
if (parent != null) {
clazz = parent.loadClass(triggers[i]);
} else {
clazz = Class.forName(triggers[i]);
}
} catch (Throwable t) {
clazz = null;
}
if (clazz == null)
continue;
String name = triggers[i].replace('.', '/') + ".class";
if (debug >= 2)
log(" Checking for " + name);
JarEntry jarEntry = jarFile.getJarEntry(name);
if (jarEntry != null) {
log("validateJarFile(" + jarfile +
") - jar not loaded. See Servlet Spec 2.3, "
+ "section 9.7.2. Offending class: " + name);
jarFile.close();
return (false);
}
}
jarFile.close();
return (true);
}
示例11: isFileUriExist
import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
* Verifies whether the file resource exists.
*
* @param uri the URI to locate the resource
* @param openJarFile a flag to indicate whether a JAR file should be
* opened. This operation may be expensive.
* @return true if the resource exists, false otherwise.
*/
static boolean isFileUriExist(URI uri, boolean openJarFile) {
if (uri != null && uri.isAbsolute()) {
if (null != uri.getScheme()) {
switch (uri.getScheme()) {
case SCHEME_FILE:
String path = uri.getPath();
File f1 = new File(path);
if (f1.isFile()) {
return true;
}
break;
case SCHEME_JAR:
String tempUri = uri.toString();
int pos = tempUri.indexOf("!");
if (pos < 0) {
return false;
}
if (openJarFile) {
String jarFile = tempUri.substring(SCHEME_JARFILE.length(), pos);
String entryName = tempUri.substring(pos + 2);
try {
JarFile jf = new JarFile(jarFile);
JarEntry je = jf.getJarEntry(entryName);
if (je != null) {
return true;
}
} catch (IOException ex) {
return false;
}
} else {
return true;
}
break;
}
}
}
return false;
}
示例12: readFile
import java.util.jar.JarFile; //导入方法依赖的package包/类
private byte[] readFile(String internalPath) throws Exception {
JarFile jarFile = new JarFile(path);
JarEntry jarEntry = jarFile.getJarEntry(internalPath);
if (jarEntry == null)
return null;
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
byte[] buf = new byte[100 * 1024];
int len;
InputStream is = jarFile.getInputStream(jarEntry);
while ((len = is.read(buf)) != -1) {
byteBuffer.write(buf, 0, len);
}
return byteBuffer.toByteArray();
}
示例13: findJarEntry
import java.util.jar.JarFile; //导入方法依赖的package包/类
private JarEntryInfo findJarEntry(String sName) {
for (JarFileInfo jarFileInfo : lstJarFile) {
JarFile jarFile = jarFileInfo.jarFile;
JarEntry jarEntry = jarFile.getJarEntry(sName);
if (jarEntry != null) {
return new JarEntryInfo(jarFileInfo, jarEntry);
}
}
return null;
}
示例14: findJarEntries
import java.util.jar.JarFile; //导入方法依赖的package包/类
private List<JarEntryInfo> findJarEntries(String sName) {
List<JarEntryInfo> lst = new ArrayList<JarEntryInfo>();
for (JarFileInfo jarFileInfo : lstJarFile) {
JarFile jarFile = jarFileInfo.jarFile;
JarEntry jarEntry = jarFile.getJarEntry(sName);
if (jarEntry != null) {
lst.add(new JarEntryInfo(jarFileInfo, jarEntry));
}
}
return lst;
}
示例15: addJar
import java.util.jar.JarFile; //导入方法依赖的package包/类
public static void addJar(JarFile jar) throws IOException
{
Manifest manifest = jar.getManifest();
String atList = manifest.getMainAttributes().getValue("FMLAT");
if (atList == null) return;
for (String at : atList.split(" "))
{
JarEntry jarEntry = jar.getJarEntry("META-INF/"+at);
if (jarEntry != null)
{
embedded.put(String.format("%s!META-INF/%s", jar.getName(), at),
new JarByteSource(jar,jarEntry).asCharSource(Charsets.UTF_8).read());
}
}
}