List of usage examples for org.apache.commons.compress.archivers.zip ZipArchiveEntry isDirectory
public boolean isDirectory()
From source file:org.xwiki.xar.XarPackage.java
/** * Find and add the entries located in the passed XAR file. * /*from w w w . j a v a 2 s. c o m*/ * @param zipFile the XAR file * @throws IOException when failing to read the file * @throws XarException when failing to parse the XAR package */ public void read(ZipFile zipFile) throws IOException, XarException { Enumeration<ZipArchiveEntry> zipEntries = zipFile.getEntries(); while (zipEntries.hasMoreElements()) { ZipArchiveEntry entry = zipEntries.nextElement(); if (!entry.isDirectory()) { InputStream stream = zipFile.getInputStream(entry); try { readEntry(stream, entry); } finally { stream.close(); } } } }
From source file:org.yes.cart.utils.impl.ZipUtils.java
private void unzipEntry(final ZipFile zipfile, final ZipArchiveEntry entry, final File outputDir) throws IOException { if (entry.isDirectory()) { createDir(new File(outputDir, entry.getName())); return;//from w ww .java2 s .co m } File outputFile = new File(outputDir, entry.getName()); if (!outputFile.getParentFile().exists()) { createDir(outputFile.getParentFile()); } BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry)); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); try { IOUtils.copy(inputStream, outputStream); } finally { outputStream.close(); inputStream.close(); } }
From source file:stroom.util.zip.StroomZipFile.java
public StroomZipNameSet getStroomZipNameSet() throws IOException { if (stroomZipNameSet == null) { stroomZipNameSet = new StroomZipNameSet(false); Enumeration<ZipArchiveEntry> entryE = getZipFile().getEntries(); while (entryE.hasMoreElements()) { ZipArchiveEntry entry = entryE.nextElement(); // Skip Dir's if (!entry.isDirectory()) { String fileName = entry.getName(); stroomZipNameSet.add(fileName); }//from ww w . j a v a 2s. co m long entrySize = entry.getSize(); if (entrySize == -1 || totalSize == -1) { // Can nolonger sum } else { totalSize += entrySize; } } } return stroomZipNameSet; }
From source file:uk.ac.ebi.metabolights.utils.Zipper.java
public static void unzip2(String strZipFile, String folder) throws IOException, ArchiveException { //Check if the file exists FileUtil.fileExists(strZipFile, true); final InputStream is = new FileInputStream(strZipFile); ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream("zip", is); ZipArchiveEntry entry = null; OutputStream out = null;/* w w w. j a v a 2s . co m*/ while ((entry = (ZipArchiveEntry) in.getNextEntry()) != null) { //create directories if required. File zipPath = new File(folder); File destinationFilePath = new File(zipPath, entry.getName()); destinationFilePath.getParentFile().mkdirs(); //if the entry is directory, leave it. Otherwise extract it. if (entry.isDirectory()) { continue; } else { out = new FileOutputStream(new File(folder, entry.getName())); IOUtils.copy(in, out); out.close(); } } in.close(); }
From source file:uk.ac.ebi.metabolights.webservice.utils.Zipper.java
public static void unzip2(String strZipFile, String folder) throws IOException, ArchiveException { // Remove any previous content of the unzip folder. File uf = new File(folder); FileUtil.deleteDir(uf);/*from w w w .j av a 2 s . com*/ // Create it again, this time it will be empty.. uf.mkdir(); //Check if the file exists FileUtil.fileExists(strZipFile, true); final InputStream is = new FileInputStream(strZipFile); ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream("zip", is); ZipArchiveEntry entry = null; OutputStream out = null; while ((entry = (ZipArchiveEntry) in.getNextEntry()) != null) { //create directories if required. File zipPath = new File(folder); File destinationFilePath = new File(zipPath, entry.getName()); destinationFilePath.getParentFile().mkdirs(); //if the entry is directory, leave it. Otherwise extract it. if (entry.isDirectory()) { continue; } else { out = new FileOutputStream(new File(folder, entry.getName())); IOUtils.copy(in, out); out.close(); } } in.close(); }
From source file:uk.nhs.cfh.dsp.srth.distribution.FileDownloader.java
private void extractZipFileContents(File file) { Enumeration entries;/* w w w . jav a 2s . co m*/ try { logger.info("Extracting zip file contents..."); ZipFile zipFile = new ZipFile(file); entries = zipFile.getEntries(); while (entries.hasMoreElements()) { ZipArchiveEntry entry = (ZipArchiveEntry) entries.nextElement(); if (entry.isDirectory()) { logger.info("Extracting directory: " + entry.getName()); File dir = new File(file.getParent(), entry.getName()); boolean canWrite = dir.exists(); if (!canWrite) { canWrite = dir.mkdir(); } if (canWrite) { continue; } else { logger.warning("Error creating directory during extraction"); } } logger.info("Extracting file: " + entry.getName()); copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream( new FileOutputStream(new File(file.getParent(), entry.getName())))); } zipFile.close(); logger.info("Closed zip file."); } catch (IOException e) { logger.warning("Nested exception is : " + e.fillInStackTrace()); } }