當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。