List of usage examples for java.util.jar JarFile close
public void close() throws IOException
From source file:org.jvnet.hudson.update_center.MavenArtifact.java
public Manifest getManifest() throws IOException { if (manifest == null) { File f = resolve();//from w w w .j a v a 2 s . c o m try { JarFile jar = new JarFile(f); ZipEntry e = jar.getEntry("META-INF/MANIFEST.MF"); timestamp = e.getTime(); manifest = jar.getManifest(); jar.close(); } catch (IOException x) { throw (IOException) new IOException("Failed to open " + f).initCause(x); } } return manifest; }
From source file:com.zb.app.common.file.FileUtils.java
public static void unJar(File jarFile, File toDir) throws IOException { JarFile jar = new JarFile(jarFile); try {/*from w w w. j a v a 2 s . co m*/ Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); if (!entry.isDirectory()) { InputStream in = jar.getInputStream(entry); try { File file = new File(toDir, entry.getName()); if (!file.getParentFile().mkdirs()) { if (!file.getParentFile().isDirectory()) { throw new IOException("Mkdirs failed to create " + file.getParentFile().toString()); } } OutputStream out = new FileOutputStream(file); try { byte[] buffer = new byte[8192]; int i; while ((i = in.read(buffer)) != -1) { out.write(buffer, 0, i); } } finally { out.close(); } } finally { in.close(); } } } } finally { jar.close(); } }
From source file:com.eviware.soapui.actions.MockAsWarActionTest.java
private void assertValidWarFile(String warFileName) throws IOException { JarFile jarFile = new JarFile(warFileName); try {//w w w. ja va 2s. c om for (String fileName : getExpectedWarContents()) { JarEntry jarEntry = jarFile.getJarEntry(fileName); assertNotNull(jarEntry); } } finally { jarFile.close(); } }
From source file:org.apache.bcel.BCELBenchmark.java
@Benchmark public void parser(Blackhole bh) throws IOException { JarFile jar = getJarFile(); for (JarEntry entry : getClasses(jar)) { byte[] bytes = IOUtils.toByteArray(jar.getInputStream(entry)); JavaClass clazz = new ClassParser(new ByteArrayInputStream(bytes), entry.getName()).parse(); bh.consume(clazz);//w ww .j a va 2 s . co m } jar.close(); }
From source file:org.sonar.updatecenter.common.PluginManifest.java
/** * Load the manifest from a JAR file.// w w w . j a va2 s . com */ public PluginManifest(File file) throws IOException { JarFile jar = new JarFile(file); try { if (jar.getManifest() != null) { loadManifest(jar.getManifest()); } } finally { jar.close(); } }
From source file:net.technicpack.launchercore.util.ZipUtils.java
public static void copyMinecraftJar(File minecraft, File output) throws IOException { String[] security = { "MOJANG_C.DSA", "MOJANG_C.SF", "CODESIGN.RSA", "CODESIGN.SF" }; JarFile jarFile = new JarFile(minecraft); try {/*w ww . ja v a2s .c o m*/ String fileName = jarFile.getName(); String fileNameLastPart = fileName.substring(fileName.lastIndexOf(File.separator)); JarOutputStream jos = new JarOutputStream(new FileOutputStream(output)); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (containsAny(entry.getName(), security)) { continue; } InputStream is = jarFile.getInputStream(entry); //jos.putNextEntry(entry); //create a new entry to avoid ZipException: invalid entry compressed size jos.putNextEntry(new JarEntry(entry.getName())); byte[] buffer = new byte[4096]; int bytesRead = 0; while ((bytesRead = is.read(buffer)) != -1) { jos.write(buffer, 0, bytesRead); } is.close(); jos.flush(); jos.closeEntry(); } jos.close(); } finally { jarFile.close(); } }
From source file:simpleserver.minecraft.MinecraftWrapper.java
private String getCommand() { int minimumMemory = MINIMUM_MEMORY; String arguments = ""; if (options.contains("javaArguments")) { arguments = options.get("javaArguments"); }//from w w w . j a v a2s .c o m if (options.getInt("memory") < minimumMemory) { minimumMemory = options.getInt("memory"); } if (!options.getBoolean("overwriteArguments")) { String memoryArgs; if (options.getBoolean("useXincgc")) { memoryArgs = String.format(XINCGC_FORMAT, options.get("memory")); } else { memoryArgs = String.format(MEMORY_FORMAT, minimumMemory, options.get("memory")); } arguments = String.format("%s %s %s", arguments, memoryArgs, DEFAULT_ARGUMENTS); } if (options.getBoolean("enablePlugins")) { String mainclass = null; try { JarFile jarFile = new JarFile(getServerJar()); mainclass = jarFile.getManifest().getMainAttributes().getValue("Main-Class"); jarFile.close(); } catch (IOException e) { System.out.println("[SimpleServer] " + e); System.out.println("[SimpleServer] FATAL ERROR: Could not read minecraft_server.jar!"); System.exit(-1); } String[] plugins = new File("plugins").list(new WildcardFileFilter("*.zip")); if (plugins == null) { plugins = new String[0]; } Arrays.sort(plugins); ArrayList<String> plugstrs = new ArrayList<String>(plugins.length + 1); for (String fname : plugins) { plugstrs.add("plugins/" + fname); } plugstrs.add(getServerJar()); String clspath = StringUtils.join(plugstrs, ":"); return String.format(COMMAND_FORMAT_PLUGINS, arguments, clspath, mainclass, modArguments()); } else { return String.format(COMMAND_FORMAT, arguments, getServerJar(), modArguments()); } }
From source file:org.ow2.bonita.runtime.AbstractClassLoader.java
private void releaseConnection(URL url) { if (LOG.isLoggable(Level.INFO)) { LOG.info("Releasing class loader: " + this); }// www. ja va 2s. co m try { final URLConnection conn = url.openConnection(); if (LOG.isLoggable(Level.INFO)) { LOG.info("Getting connection of url: " + url + ", conn=" + conn); } final String fileURLConnectionClassName = "sun.net.www.protocol.file.FileURLConnection"; if (conn instanceof JarURLConnection) { JarFile jarfile = ((JarURLConnection) conn).getJarFile(); if (LOG.isLoggable(Level.INFO)) { LOG.info("Closing jar file: " + jarfile.getName()); } jarfile.close(); } else if (conn.getClass().getName().equals(fileURLConnectionClassName)) { if (LOG.isLoggable(Level.INFO)) { LOG.info("Closing connection (" + fileURLConnectionClassName + ": " + conn); } Method close = conn.getClass().getMethod("close", (Class[]) null); close.invoke(conn, (Object[]) null); } } catch (Exception e) { if (LOG.isLoggable(Level.WARNING)) { LOG.warning("Error while releasing classloader: " + this + ": " + Misc.getStackTraceFrom(e)); } e.printStackTrace(); } close(); }
From source file:org.nosphere.honker.deptree.DepTreeManifestLoader.java
private DepTreeData.Manifest loadFromZip(File zipFile) throws IOException { JarFile jar = null; try {//from w w w. j av a2 s . c om jar = new JarFile(zipFile); Manifest mf = jar.getManifest(); if (mf == null) { return DepTreeData.Manifest.EMPTY; } return loadData(mf); } finally { if (jar != null) { try { jar.close(); } catch (IOException ignored) { // Ignored } } } }
From source file:org.apache.hadoop.hbase.util.RunTrigger.java
public static void unJar(File jarFile, File toDir) throws IOException { JarFile jar = new JarFile(jarFile); try {/*ww w . j a v a 2 s . co m*/ Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); if (!entry.isDirectory()) { InputStream in = jar.getInputStream(entry); try { File file = new File(toDir, entry.getName()); if (!file.getParentFile().mkdirs()) { if (!file.getParentFile().isDirectory()) { throw new IOException("Mkdirs failed to create " + file.getParentFile().toString()); } } OutputStream out = new FileOutputStream(file); try { byte[] buffer = new byte[8192]; int i; while ((i = in.read(buffer)) != -1) { out.write(buffer, 0, i); } } finally { out.close(); } } finally { in.close(); } } } } finally { jar.close(); } }