Java 8 JarFile - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 JarFile class.

This code example shows how to use the following methods:getEntry, getInputStream, close
		} 
 
		URL krollAptJarUrl = codeSource.getLocation();
		String mobileAndroidDir = new File(krollAptJarUrl.toURI()).getParent();
 
		JarFile titaniumJar = new JarFile(new File(mobileAndroidDir, "titanium.jar"));
		ZipEntry jsonEntry = titaniumJar.getEntry("org/appcelerator/titanium/bindings/titanium.json");
		InputStream jsonStream = titaniumJar.getInputStream(jsonEntry);
 
		Map<String, Object> properties = (Map<String, Object>)
			JSONValue.parseWithException(new InputStreamReader(jsonStream));
		jsonStream.close();
		titaniumJar.close();
 
		tiProxies.putAll(jsonUtils.getStringMap(properties, "proxies"));
		tiModules.putAll(jsonUtils.getStringMap(properties, "modules"));
	} 
 
	protected void generateApiTree() 
	{ 
8
CodeRank
This code example shows how to use the following methods:getEntry, getInputStream, getName
  } 
 
  @Override 
  public File getSourceFile()
  { 
    return new File(_jarFile.getName());
  } 
 
  @Override 
  public InputStream asInputStream(StringBuilder errorMessageBuilder)
  { 
    InputStream inputStream = null;
    try 
    { 
      ZipEntry zipEntry = _jarFile.getEntry(_pathInJar);
      if (zipEntry != null)
      { 
        inputStream = _jarFile.getInputStream(zipEntry);
      } 
    } 

8
CodeRank
This code example shows how to use the following methods:getName
    public ModuleDefinition getValue() throws IllegalStateException, IllegalArgumentException { 
        return moduleDefinition;
    } 
 
    private static void addResourceRoot(final ModuleSpec.Builder specBuilder, final JarFile file) {
        specBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(ResourceLoaders.createJarResourceLoader(
                    file.getName(), file)));
    } 
 
} 
8
CodeRank
This code example shows how to use the following methods:getEntry, getInputStream, close
        if (fileName.toLowerCase().startsWith("surefire")){
            return; 
        } 
        JarFile module = null;
        try { 
            module = new JarFile(classPath);
            ZipEntry entry = module.getEntry(searchFor);
            if (entry != null){
                InputStream is = module.getInputStream(entry); 
                processInputStream(xmlList, is);
            } 
        } catch (java.util.zip.ZipException e) {
            logger.info("Unable to check jar file "+fileName+" for ebean-orm.xml");
        } finally { 
            if (module != null){
                module.close();
            } 
        } 
    } 
 
     
8
CodeRank
This code example shows how to use the following methods:getInputStream, getJarEntry
    // Regression test for issue introduced by HARMONY-4569: signed archives containing files with size 0 could not get verified. 
    public void testJarVerificationEmptyEntry() throws IOException { 
        Support_Resources.copyFile(resources, null, emptyEntryJar);
        File f = new File(resources, emptyEntryJar);
 
        JarFile jarFile = new JarFile(f);
 
        ZipEntry zipEntry = jarFile.getJarEntry(emptyEntry1);
        int res = jarFile.getInputStream(zipEntry).read(new byte[100], 0, 100);
        assertEquals("Wrong length of empty jar entry", -1, res);
 
        zipEntry = jarFile.getJarEntry(emptyEntry2);
        res = jarFile.getInputStream(zipEntry).read(new byte[100], 0, 100);
        assertEquals("Wrong length of empty jar entry", -1, res);
 
        zipEntry = jarFile.getJarEntry(emptyEntry3);
        res = jarFile.getInputStream(zipEntry).read();
        assertEquals("Wrong length of empty jar entry", -1, res);
    } 
} 

7
CodeRank
This code example shows how to use the following methods:getEntry, getInputStream
	} 
 
	public InputStream openStream() throws IOException {
		// 注:JarFile与File的设计是不一样的,File相当于C#的FileInfo,只持有信息, 
		// 而JarFile构造时即打开流,所以每次读取数据时,重新new新的实例,而不作为属性字段持有。 
		JarFile jarFile = new JarFile(file);
		return jarFile.getInputStream(jarFile.getEntry(getName()));
	} 
 
	public long getLastModified() { 
		return file.lastModified();
	} 
 
	public long getLength() { 
		try { 
			JarFile jarFile = new JarFile(file);
			try { 
				return jarFile.getEntry(getName()).getSize();
			} finally { 
				jarFile.close();
7
CodeRank
This code example shows how to use the following methods:getManifest, close
    @Nullable 
    public static Manifest getManifestFromJar(@NotNull File library) {
        if (!library.canRead()) return null;
 
        try { 
            JarFile jarFile = new JarFile(library);
            try { 
                return jarFile.getManifest();
            } 
            finally { 
                jarFile.close();
            } 
        } 
        catch (IOException ignored) {
            return null; 
        } 
    } 
 
    @Nullable 
    public static Attributes getManifestMainAttributesFromJar(@NotNull File library) {
7
CodeRank
This code example shows how to use the following methods:getInputStream, getJarEntry, getManifest
	 */ 
	@Override 
	protected Class<?> findClass(String name) throws ClassNotFoundException {
		try { 
			String pathName = transformName(name);
			JarEntry jarEntry = tempJarFile.getJarEntry(pathName);
			if (jarEntry != null) {
				long size = jarEntry.getSize();
				InputStream jarEntryInputStream = tempJarFile.getInputStream(jarEntry);
				ByteArrayOutputStream classBytesOutputStream = new ByteArrayOutputStream((int) size);
				FileUtil.copy(jarEntryInputStream, classBytesOutputStream, size);
				classBytesOutputStream.close();
				jarEntryInputStream.close();
				byte[] classBytes = classBytesOutputStream.toByteArray();
 
				definePackage(name);
					 
				Class<?> clazz = defineClass(name, classBytes, 0, classBytes.length);
				return clazz;
			} 

7
CodeRank
This code example shows how to use the following methods:close
public final class Utils { 
 
    public static void safeClose(JarFile jf){
        try{ 
            if(jf != null) {
                jf.close();
            } 
        }catch(Exception e){
 
        } 
    } 
 
    public static void safelyClose(InputStream is){
        try{ 
            if(is != null) {
                is.close();
            } 
        }catch(Exception e){
 
        } 
7
CodeRank
This code example shows how to use the following methods:getEntry, getInputStream, getName
  } 
 
  @Override 
  public File getSourceFile()
  { 
    return new File(_jarFile.getName());
  } 
 
  @Override 
  public InputStream asInputStream(StringBuilder errorMessageBuilder)
  { 
    InputStream inputStream = null;
    try 
    { 
      ZipEntry zipEntry = _jarFile.getEntry(_pathInJar);
      if (zipEntry != null)
      { 
        inputStream = _jarFile.getInputStream(zipEntry);
      } 
    } 

7
CodeRank

Related Java 8 JarFile Questions & Answers:

See Code Examples for Java 8 JarFile Methods: