List of usage examples for java.util.zip ZipFile close
public void close() throws IOException
From source file:org.jahia.utils.zip.ZipEntryCharsetDetector.java
private static boolean canRead(File file, Charset charset) throws IOException { boolean canRead = true; ZipFile zip = null; try {/*w w w .ja v a2 s .c o m*/ zip = charset != null ? new ZipFile(file, charset) : new ZipFile(file); Enumeration<? extends ZipEntry> entries = zip.entries(); try { while (entries.hasMoreElements()) { entries.nextElement(); } } catch (IllegalArgumentException e) { canRead = false; } } finally { if (zip != null) { try { zip.close(); } catch (IOException e) { // ignore } } } return canRead; }
From source file:Main.java
public static File UpdateZipFromPath(String sZipFile, String sPath) throws Exception { File tmpFile = File.createTempFile("z4zip-tmp-", ".zip"); tmpFile.deleteOnExit();/*from w w w .j a v a2 s . c om*/ ZipFile inZip = new ZipFile(sZipFile); ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream(tmpFile.getPath())); Enumeration<? extends ZipEntry> entries = inZip.entries(); while (entries.hasMoreElements()) { ZipEntry e = entries.nextElement(); outZip.putNextEntry(e); if (!e.isDirectory()) { File f = new File(sPath + "/" + e.getName()); if (f.exists()) { copy(new FileInputStream(f.getPath()), outZip); } else { copy(inZip.getInputStream(e), outZip); } } outZip.closeEntry(); } inZip.close(); outZip.close(); return tmpFile; }
From source file:org.reficio.p2.utils.JarUtils.java
public static boolean containsSignature(File jarToUnsign) { try {//from w w w.ja va2s . c o m ZipFile zip = new ZipFile(jarToUnsign); try { for (Enumeration list = zip.entries(); list.hasMoreElements();) { ZipEntry entry = (ZipEntry) list.nextElement(); String name = entry.getName(); if (!entry.isDirectory() && (name.endsWith(".RSA") || name.endsWith(".DSA") || name.endsWith(".SF"))) { return true; } } return false; } finally { zip.close(); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.termmed.utils.ResourceUtils.java
/** * Gets the resources from jar file.//from w w w . j av a2s . c o m * * @param file the file * @param pattern the pattern * @return the resources from jar file */ private static Collection<String> getResourcesFromJarFile(final File file, final Pattern pattern) { final ArrayList<String> retval = new ArrayList<String>(); ZipFile zf; try { zf = new ZipFile(file); } catch (final ZipException e) { throw new Error(e); } catch (final IOException e) { throw new Error(e); } final Enumeration e = zf.entries(); while (e.hasMoreElements()) { final ZipEntry ze = (ZipEntry) e.nextElement(); final String fileName = ze.getName(); final boolean accept = pattern.matcher(fileName).matches(); if (accept) { retval.add(fileName); } } try { zf.close(); } catch (final IOException e1) { throw new Error(e1); } return retval; }
From source file:com.enioka.jqm.tools.Helpers.java
static void closeQuietly(ZipFile zf) { try {// w w w . j av a 2 s. c o m if (zf != null) { zf.close(); } } catch (Exception e) { jqmlogger.warn("could not close jar file", e); } }
From source file:org.meshkeeper.deployer.util.ZipUtil.java
public static final void unzipFile(File zip, File targetDir) throws ZipException, IOException { Enumeration<? extends ZipEntry> entries; ZipFile zipFile; zipFile = new ZipFile(zip); entries = zipFile.entries();//from www .jav a 2 s.c o m while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.isDirectory()) { // Assume directories are stored parents first then children. // This is not robust, just for demonstration purposes. (new File(targetDir, entry.getName())).mkdirs(); continue; } copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(new File(targetDir, entry.getName())))); } zipFile.close(); }
From source file:org.neo4j.ha.upgrade.Utils.java
public static List<File> unzip(File zipFile, File targetDir) throws IOException { List<File> files = new ArrayList<File>(); ZipFile zip = new ZipFile(zipFile); try {//from w w w . j a v a2 s. c om zip = new ZipFile(zipFile); for (ZipEntry entry : Collections.list(zip.entries())) { File target = new File(targetDir, entry.getName()); target.getParentFile().mkdirs(); if (!entry.isDirectory()) { InputStream input = zip.getInputStream(entry); try { copyInputStreamToFile(input, target); files.add(target); } finally { closeQuietly(input); } } } return files; } finally { zip.close(); } }
From source file:Utils.java
/** * Unpack a zip file/* w w w .jav a2s .c o m*/ * * @param theFile * @param targetDir * @return the file * @throws IOException */ public static File unpackArchive(File theFile, File targetDir) throws IOException { if (!theFile.exists()) { throw new IOException(theFile.getAbsolutePath() + " does not exist"); } if (!buildDirectory(targetDir)) { throw new IOException("Could not create directory: " + targetDir); } ZipFile zipFile = new ZipFile(theFile); for (Enumeration entries = zipFile.entries(); entries.hasMoreElements();) { ZipEntry entry = (ZipEntry) entries.nextElement(); File file = new File(targetDir, File.separator + entry.getName()); if (!buildDirectory(file.getParentFile())) { throw new IOException("Could not create directory: " + file.getParentFile()); } if (!entry.isDirectory()) { copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(new FileOutputStream(file))); } else { if (!buildDirectory(file)) { throw new IOException("Could not create directory: " + file); } } } zipFile.close(); return theFile; }
From source file:com.aurel.track.admin.server.dbbackup.DatabaseBackupBL.java
public static Properties getBackupInfo(File backupFile) throws DatabaseBackupBLException { Properties prop = new Properties(); ZipFile zipFile = null; try {/*from w ww . ja v a2s .c o m*/ zipFile = new ZipFile(backupFile, ZipFile.OPEN_READ); } catch (IOException e) { throw new DatabaseBackupBLException(e.getMessage(), e); } ZipEntry zipEntryInfo = zipFile.getEntry(DataReader.FILE_NAME_INFO); if (zipEntryInfo == null) { try { zipFile.close(); } catch (IOException e) { throw new DatabaseBackupBLException(e.getMessage(), e); } throw new DatabaseBackupBLException("Invalid backup. No file info"); } try { prop.load(zipFile.getInputStream(zipEntryInfo)); } catch (IOException e) { throw new DatabaseBackupBLException(e.getMessage(), e); } try { zipFile.close(); } catch (IOException e) { throw new DatabaseBackupBLException(e.getMessage(), e); } return prop; }
From source file:org.blockartistry.mod.Restructured.assets.ZipProcessor.java
private static void traverseZips(final File path, final Predicate<ZipEntry> test, final Predicate<Object[]> process) { for (final File file : getZipFiles(path)) { try {//from www .j a v a 2s .c o m final ZipFile zip = new ZipFile(file); final String prefix = StringUtils.removeEnd(file.getName(), ".zip").toLowerCase().replaceAll("[-.]", "_"); Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { final ZipEntry entry = entries.nextElement(); if (test.apply(entry)) { final InputStream stream = zip.getInputStream(entry); final String name = StringUtils.removeEnd(entry.getName(), ".schematic"); process.apply(new Object[] { prefix, name, stream }); stream.close(); } } zip.close(); } catch (final Exception ex) { ex.printStackTrace(); } } }