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


Java JarFile.getJarEntry方法代码示例

本文整理汇总了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));
        } 
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:BrandingSupport.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:JarFileSystem.java

示例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;
}
 
开发者ID:twosigma,项目名称:beaker-notebook-archive,代码行数:25,代码来源:SimpleClassLoader.java

示例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();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:TestNormal.java

示例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();
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:12,代码来源:Test_ConfigurationParser.java

示例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;
}
 
开发者ID:adnanmitf09,项目名称:Rubus,代码行数:33,代码来源:ClassFinder.java

示例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)));
        }
    }
}
 
开发者ID:twosigma,项目名称:beaker-notebook-archive,代码行数:9,代码来源:SimpleClassLoader.java

示例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);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:15,代码来源:DeploymentInstaller.java

示例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);

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:44,代码来源:WebappClassLoader.java

示例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);

    }
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:44,代码来源:WebappClassLoader.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:47,代码来源:Util.java

示例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();
}
 
开发者ID:baidu,项目名称:OASP,代码行数:16,代码来源:OASPVerify.java

示例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;
}
 
开发者ID:Energyxxer,项目名称:Vanilla-Injection,代码行数:11,代码来源:JarClassLoader.java

示例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;
}
 
开发者ID:Energyxxer,项目名称:Vanilla-Injection,代码行数:12,代码来源:JarClassLoader.java

示例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());
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:16,代码来源:ModAccessTransformer.java


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