List of usage examples for org.apache.commons.compress.archivers.zip ZipFile getInputStream
public InputStream getInputStream(ZipArchiveEntry ze) throws IOException, ZipException
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;// w w w . j av a 2 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:uk.nhs.cfh.dsp.srth.distribution.FileDownloader.java
private void extractZipFileContents(File file) { Enumeration entries;/*from w w w.j a va 2s . c om*/ 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()); } }