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


Java JarFile.close方法代码示例

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


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

示例1: main

import java.util.jar.JarFile; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {

    HashSet<String> pkg_set = new HashSet<>();
    String path = "C:/Program Files/Java/jre1.8.0_60/lib/rt.jar";

    JarFile jar_file = new JarFile(new File(path));

    /*
     * jar_file.stream().forEach( (entry)->pkg_set.add( PathUtil.getPkgName(
     * entry.getName() ) ) );
     */

    jar_file.stream().forEach((entry) -> {
      PathUtil.getSubPkgNames(entry.getName(), "/").stream().forEach((sub_pkg) -> {
        /* out.println(sub_pkg); */ pkg_set.add(sub_pkg);
      });
    });

    pkg_set.stream().forEach((str) -> out.println(str));

    jar_file.close();

  }
 
开发者ID:Samsung,项目名称:MeziLang,代码行数:24,代码来源:JarInputStreamTest.java

示例2: copyResourceFolder

import java.util.jar.JarFile; //导入方法依赖的package包/类
public static void copyResourceFolder(String resourceFolder, String destDir)
		throws IOException {
	final File jarFile = new File(Util.class.getProtectionDomain()
			.getCodeSource().getLocation().getPath());
	if (jarFile.isFile()) { // Run with JAR file
		resourceFolder = StringUtils.strip(resourceFolder, "/");
		final JarFile jar = new JarFile(jarFile);
		// gives ALL entries in jar
		final Enumeration<JarEntry> entries = jar.entries();
		while (entries.hasMoreElements()) {
			JarEntry element = entries.nextElement();
			final String name = element.getName();
			// filter according to the path
			if (name.startsWith(resourceFolder + "/")) {
				String resDestDir = Util.combineFilePath(destDir,
						name.replaceFirst(resourceFolder + "/", ""));
				if (element.isDirectory()) {
					File newDir = new File(resDestDir);
					if (!newDir.exists()) {
						boolean mkdirRes = newDir.mkdirs();
						if (!mkdirRes) {
							logger.error("Failed to create directory "
									+ resDestDir);
						}
					}
				} else {
					InputStream inputStream = null;
					try {
						inputStream = Util.class.getResourceAsStream("/"
								+ name);
						if (inputStream == null) {
							logger.error("No resource is found:" + name);
						} else {
							Util.outputFile(inputStream, resDestDir);
						}

						/* compress js files */
						inputStream = Util.class.getResourceAsStream("/"
								+ name);
						compressor.compress(inputStream, name, destDir);
					} finally {
						if (inputStream != null) {
							inputStream.close();
						}
					}
				}
			}
		}
		jar.close();
	} else { // Run with IDE
		final URL url = Util.class.getResource(resourceFolder);
		if (url != null) {
			try {
				final File src = new File(url.toURI());
				File dest = new File(destDir);
				FileUtils.copyDirectory(src, dest);
				Util.compressFilesInDir(src, destDir);
			} catch (URISyntaxException ex) {
				logger.error(ex);
			}
		}
	}
}
 
开发者ID:WinRoad-NET,项目名称:wrdocletbase,代码行数:64,代码来源:Util.java

示例3: getRenameMap

import java.util.jar.JarFile; //导入方法依赖的package包/类
public Map<String, String> getRenameMap(String jarFilePath) {
    Map<String, String> map = new HashMap<>();
    try {
        File jarFile = new File(jarFilePath);
        JarFile file = new JarFile(jarFile);
        Enumeration<JarEntry> enumeration = file.entries();
        while (enumeration.hasMoreElements()) {
            JarEntry jarEntry = enumeration.nextElement();
            String entryName = jarEntry.getName();
            String className;
            if (entryName.endsWith(".class")) {
                className = Utils.path2Classname(entryName);
                String simpleName = className.substring(className.lastIndexOf('.') + 1);
                if (Utils.isProguardedName(simpleName)) {
                    map.put(className, getNewClassName(className, simpleName));
                }
            }
        }
        file.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return map;
}
 
开发者ID:BryanSharp,项目名称:Jar2Java,代码行数:26,代码来源:JarAnalyzer.java

示例4: getJarAttribute

import java.util.jar.JarFile; //导入方法依赖的package包/类
public static String getJarAttribute(
        final File file,
        final String name) throws IOException {
    JarFile jar = new JarFile(file);
    
    try {
        return jar.getManifest().getMainAttributes().getValue(name);
    } finally {
        try {
            jar.close();
        } catch (IOException e) {
            ErrorManager.notifyDebug(ResourceUtils.getString(
                    FileUtils.class, ERROR_CANT_CLOSE_JAR_KEY, jar.getName()), e);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:FileUtils.java

示例5: packInternally

import java.util.jar.JarFile; //导入方法依赖的package包/类
@SuppressWarnings("CallToThreadDumpStack")
public static boolean packInternally(final File source,
        final File target) throws IOException {
    try {
        JarFile jarFile = new JarFile(source);
        FileOutputStream outputStream = new FileOutputStream(target);

        
        String output = "Packing jarFile: " + jarFile + " to " + target;
        if (project != null) {
            project.log("            " + output);
        } else {
            System.out.println(output);
        }

        packer.pack(jarFile, outputStream);

        jarFile.close();
        outputStream.close();
        target.setLastModified(source.lastModified());
    } catch (IOException exc) {
        exc.printStackTrace();
        return false;
    }
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:Utils.java

示例6: modifyOutputStream

import java.util.jar.JarFile; //导入方法依赖的package包/类
@Override
public void modifyOutputStream(JarOutputStream jos) throws IOException {

	if (location == null) {
		logger.warn("Can not append artifacts! Artifacts location not provided!");
		return;
	}

	if (!location.exists() || !location.isDirectory()) {
		logger.warn("Can not append artifacts! `{}` is not a valid directory!", location);
		return;
	}

	File[] files = location.listFiles();
	if (files != null) {
		for (File file : files) {
			JarFile jarFile = new JarFile(file);
			jarFile.stream().forEach(entry -> {
				if (!entry.getName().startsWith("META-INF/MANIFEST.MF")) {
					try {
						jos.putNextEntry(new JarEntry(entry.getName()));
						IOUtil.copy(jarFile.getInputStream(entry), jos);
					} catch (IOException e) {
						if (e instanceof ZipException && e.getMessage().startsWith("duplicate entry")) {
							logger.debug("Skipped existing file " + entry.getName());
						} else {
							logger.warn("Could not copy file '" + entry.getName() + "' from '" + jarFile.getName() + "' to the generated jar", e);
						}
					}
				}
			});
			jarFile.close();
		}
	}

	done = true;
}
 
开发者ID:commsen,项目名称:EM,代码行数:38,代码来源:AppendArtifactsTrnasformer.java

示例7: getClasses

import java.util.jar.JarFile; //导入方法依赖的package包/类
public static Class<?>[] getClasses(JarInfo info) {
    if (ReflectiveStorage.getJars().containsKey(info))
        return ReflectiveStorage.getJars().get(info);

    Set<Class<?>> classes = new HashSet<>();
    try {
        JarFile file = new JarFile(info.getJarFile());
        for (Enumeration<JarEntry> entry = file.entries(); entry.hasMoreElements(); ) {
            JarEntry jarEntry = entry.nextElement();
            String jarName = jarEntry.getName().replace('/', '.');

            if (info.needsPckg) {
                if (jarName.startsWith(info.getPckg()) && jarName.endsWith(".class")) {
                    classes.add(getClass(jarName.substring(0, jarName.length() - 6), false));
                }
            } else if (jarName.endsWith(".class")) {
                classes.add(getClass(jarName.substring(0, jarName.length() - 6), false));
            }
        }
        file.close();
    } catch (IOException ex) {
        Bukkit.getLogger().severe("Error ocurred at getting classes, log: " + ex);
    }

    Class<?>[] classArray = classes.toArray(new Class[classes.size()]);

    ReflectiveStorage.getJars().put(info, classArray);

    return classArray;
}
 
开发者ID:AlphaHelixDev,项目名称:AlphaLibary,代码行数:31,代码来源:ReflectionUtil.java

示例8: 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

示例9: extractJar

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * Extracts all class file names from a JAR file (possibly nested with more JARs).
 * 
 * @param file The name of the file.
 * @param classes Class names will be stored in here.
 */
public static void extractJar(String file, HashSet<String> classes) {
	try {
		// open JAR file
		JarFile jarFile = new JarFile(file);
		Enumeration<JarEntry> entries = jarFile.entries();

		// iterate JAR entries
		while (entries.hasMoreElements()) {
			JarEntry entry = entries.nextElement();
			String entryName = entry.getName();

			if (entryName.endsWith(".class")) {
				classes.add(entryName);
			} else if (entryName.endsWith(".jar")) {
				// load nested JAR
				extractJar(entryName, classes);
			}
		}

		// close JAR file
		jarFile.close();

	} catch (IOException e) {
		throw new RuntimeException("Error reading from JAR file: " + file);
	}
}
 
开发者ID:isstac,项目名称:kelinci,代码行数:33,代码来源:JarFileIO.java

示例10: addJarClassPath

import java.util.jar.JarFile; //导入方法依赖的package包/类
private void addJarClassPath(String jarFileName, boolean warn) {
            try {
                String jarParent = new File(jarFileName).getParent();
                JarFile jar = new JarFile(jarFileName);

                try {
                    Manifest man = jar.getManifest();
                    if (man == null) return;

                    Attributes attr = man.getMainAttributes();
                    if (attr == null) return;

                    String path = attr.getValue(Attributes.Name.CLASS_PATH);
                    if (path == null) return;

                    for (StringTokenizer st = new StringTokenizer(path);
                        st.hasMoreTokens();) {
                        String elt = st.nextToken();
                        if (jarParent != null)
                            elt = new File(jarParent, elt).getCanonicalPath();
                        addFile(elt, warn);
                    }
                } finally {
                    jar.close();
                }
            } catch (IOException e) {
//              log.error(Position.NOPOS,
//                        "error.reading.file", jarFileName,
//                        e.getLocalizedMessage());
            }
        }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:BatchEnvironment.java

示例11: 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

示例12: loadManifest

import java.util.jar.JarFile; //导入方法依赖的package包/类
private static Manifest loadManifest(File jar) throws IOException {
    JarFile j = new JarFile(jar);
    try {
        return j.getManifest();
    } finally {
        j.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ModuleManagerTest.java

示例13: isSigned

import java.util.jar.JarFile; //导入方法依赖的package包/类
public static boolean isSigned(
        final File file) throws IOException {
    JarFile jar = new JarFile(file);

    try {
        Enumeration<JarEntry> entries = jar.entries();
        boolean signatureInfoPresent = false;
        boolean signatureFilePresent = false;
        while (entries.hasMoreElements()) {
            String entryName = entries.nextElement().getName();
            if (entryName.startsWith("META-INF/")) {
                if (entryName.endsWith(".RSA") || entryName.endsWith(".DSA")) {
                    signatureFilePresent = true;
                    if(signatureInfoPresent) {
                        break;
                    }
                } else if (entryName.endsWith(".SF")) {
                    signatureInfoPresent = true;
                    if(signatureFilePresent) {
                        break;
                    }
                }
            }
        }
        return signatureFilePresent && signatureInfoPresent;
    } finally {
        jar.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:FileUtils.java

示例14: get

import java.util.jar.JarFile; //导入方法依赖的package包/类
JarFile get(URL url, boolean useCaches) throws IOException {

        JarFile result;
        JarFile local_result;

        if (useCaches) {
            synchronized (instance) {
                result = getCachedJarFile(url);
            }
            if (result == null) {
                local_result = URLJarFile.getJarFile(url, this);
                synchronized (instance) {
                    result = getCachedJarFile(url);
                    if (result == null) {
                        fileCache.put(URLUtil.urlNoFragString(url), local_result);
                        urlCache.put(local_result, url);
                        result = local_result;
                    } else {
                        if (local_result != null) {
                            local_result.close();
                        }
                    }
                }
            }
        } else {
            result = URLJarFile.getJarFile(url, this);
        }
        if (result == null)
            throw new FileNotFoundException(url.toString());

        return result;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:JarFileFactory.java

示例15: openTemplate

import java.util.jar.JarFile; //导入方法依赖的package包/类
public void openTemplate() {
	if (Defaults.getAsBoolean("showTemplateDialog")) {
		JOptionPane.showMessageDialog(parent, "Each template has some default values for the parameters. "
					+ "Once instantiated you may change them according to your needs.");
		Defaults.set("showTemplateDialog", "false");
		Defaults.save();
	}

	int selectedRow = templateTable.getSelectedRow();
	if (selectedRow != -1 && templateTable.getRowCount() != 0) {
		// close the template panel dialog
		SwingUtilities.getWindowAncestor(parent).setVisible(false);
		try {
			File template = templates[selectedRow].getFile();
			File copy = File.createTempFile(template.getName(), "");
			FileUtils.copyFile(templates[selectedRow].getFile(), copy);
			JarFile templateJarFile = new JarFile(copy);

			// get the path of template
			Manifest m = templateJarFile.getManifest();
			String mainClass = m.getMainAttributes().getValue("Main-Class").toString();

			URL url = new URL("file:" + copy.getAbsolutePath());
			URLClassLoader myLoader = new URLClassLoader(new URL[] { url }, Thread.currentThread().getContextClassLoader());
			Class<?> myClass = myLoader.loadClass(mainClass);

			// instantiate the template
			myTemp = (ITemplate) myClass.getConstructor(mediator.getClass()).newInstance(mediator);
			// shows the input panel of the template
			myTemp.showDialog(mediator.getMainWindow());

			templateJarFile.close();
			myLoader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:39,代码来源:TemplatePanel.java


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