List of usage examples for java.util.zip ZipEntry isDirectory
public boolean isDirectory()
From source file:be.fedict.eid.applet.service.signer.odf.ODFUtil.java
/** * Check if a file / zip entry is to be signed * /*w w w. j ava2 s . c om*/ * @param zipEntry * @return true if zip entry is to be signed */ public static boolean isToBeSigned(ZipEntry zipEntry) { String name = zipEntry.getName(); /* OOo 3.0/3.1 bug: don't sign mimetype stream nor the manifest */ /* * if (zipEntry.isDirectory() || name.equals(MIMETYPE_FILE) || * name.equals(MANIFEST_FILE) || */ /* Corrected in OOo 3.2 */ if (zipEntry.isDirectory() || name.equals(SIGNATURE_FILE)) { return false; } return true; }
From source file:azkaban.utils.Utils.java
public static void unzip(ZipFile source, File dest) throws IOException { Enumeration<?> entries = source.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); File newFile = new File(dest, entry.getName()); if (entry.isDirectory()) { newFile.mkdirs();/*from w w w . j a va 2s . com*/ } else { newFile.getParentFile().mkdirs(); InputStream src = source.getInputStream(entry); try { OutputStream output = new BufferedOutputStream(new FileOutputStream(newFile)); try { IOUtils.copy(src, output); } finally { output.close(); } } finally { src.close(); } } } }
From source file:Main.java
public static void unpack(InputStream in, File targetDir) throws IOException { ZipInputStream zin = new ZipInputStream(in); ZipEntry entry; while ((entry = zin.getNextEntry()) != null) { String extractFilePath = entry.getName(); if ((extractFilePath.startsWith("/")) || (extractFilePath.startsWith("\\"))) { extractFilePath = extractFilePath.substring(1); }/*from w ww .j a v a2s . c o m*/ File extractFile = new File(new StringBuilder().append(targetDir.getPath()).append(File.separator) .append(extractFilePath).toString()); if (entry.isDirectory()) { if (!extractFile.exists()) extractFile.mkdirs(); } else { File parent = extractFile.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } FileOutputStream os = new FileOutputStream(extractFile); copyFile(zin, os); os.flush(); os.close(); } } }
From source file:com.fluidops.iwb.luxid.LuxidExtractor.java
/** * extracts a zip-file and returns references to the unziped files. If the file passed to this method * is not a zip-file, a reference to the file is returned. * /* ww w . j av a2 s . com*/ * @param fileName * @return * @throws Exception */ public static Set<File> extractZip(String fileName) throws Exception { File zipf = new File((new StringBuilder("luxid/")).append(fileName).toString()); Set<File> toBeUploaded = new HashSet<File>(); if (zipf.getName().endsWith(".zip")) { ZipFile zip = new ZipFile(zipf); for (Enumeration<? extends ZipEntry> entries = zip.entries(); entries.hasMoreElements();) { ZipEntry entry = (ZipEntry) entries.nextElement(); if (entry.isDirectory()) { logger.info((new StringBuilder("Extracting directory: ")).append(entry.getName()).toString()); GenUtil.mkdir(new File(entry.getName())); } else { logger.info((new StringBuilder("Extracting file: ")).append(entry.getName()).toString()); String entryPath = "luxid/" + entry.getName(); FileOutputStream fileOutputStream = null; InputStream zipEntryStream = zip.getInputStream(entry); try { fileOutputStream = new FileOutputStream(entryPath); IOUtils.copy(zipEntryStream, fileOutputStream); } finally { closeQuietly(zipEntryStream); closeQuietly(fileOutputStream); } toBeUploaded.add(new File(entryPath)); } } zip.close(); } else { toBeUploaded.add(zipf); } return toBeUploaded; }
From source file:org.bonitasoft.platform.setup.PlatformSetupTestUtils.java
private static void extractZipEntries(final ZipInputStream zipInputstream, final File outputFolder) throws IOException { ZipEntry zipEntry; while ((zipEntry = zipInputstream.getNextEntry()) != null) { try {/*from w ww . j a v a2 s . c o m*/ // For each entry, a file is created in the output directory "folder" final File outputFile = new File(outputFolder.getAbsolutePath(), zipEntry.getName()); // If the entry is a directory, it creates in the output folder, and we go to the next entry (continue). if (zipEntry.isDirectory()) { outputFile.mkdirs(); continue; } writeZipInputToFile(zipInputstream, outputFile); } finally { zipInputstream.closeEntry(); } } }
From source file:com.edgenius.core.util.ZipFileUtil.java
public static void expandZipToFolder(InputStream is, String destFolder) throws ZipFileUtilException { // got our directory, so write out the input file and expand the zip file // this is really a hack - write it out temporarily then read it back in again! urg!!!! ZipInputStream zis = new ZipInputStream(is); int count;/*w w w. j av a 2 s . co m*/ byte data[] = new byte[BUFFER_SIZE]; ZipEntry entry = null; BufferedOutputStream dest = null; String entryName = null; try { // work through each file, creating a node for each file while ((entry = zis.getNextEntry()) != null) { entryName = entry.getName(); if (!entry.isDirectory()) { String destName = destFolder + File.separator + entryName; //It must sort out the directory information to current OS. //e.g, if zip file is zipped under windows, but unzip in linux. destName = FileUtil.makeCanonicalPath(destName); prepareDirectory(destName); FileOutputStream fos = new FileOutputStream(destName); dest = new BufferedOutputStream(fos, BUFFER_SIZE); while ((count = zis.read(data, 0, BUFFER_SIZE)) != -1) { dest.write(data, 0, count); } dest.flush(); IOUtils.closeQuietly(dest); dest = null; } else { String destName = destFolder + File.separator + entryName; destName = FileUtil.makeCanonicalPath(destName); new File(destName).mkdirs(); } } } catch (IOException ioe) { log.error("Exception occured processing entries in zip file. Entry was " + entryName, ioe); throw new ZipFileUtilException( "Exception occured processing entries in zip file. Entry was " + entryName, ioe); } finally { IOUtils.closeQuietly(dest); IOUtils.closeQuietly(zis); } }
From source file:com.microsoft.intellij.AzurePlugin.java
private static void unzip(String zipFilePath, String destDirectory) throws IOException { File destDir = new File(destDirectory); if (!destDir.exists()) { destDir.mkdir();// ww w.j a va 2 s . c o m } ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath)); ZipEntry entry = zipIn.getNextEntry(); while (entry != null) { String filePath = destDirectory + File.separator + entry.getName(); if (!entry.isDirectory()) { extractFile(zipIn, filePath); } else { File dir = new File(filePath); dir.mkdir(); } zipIn.closeEntry(); entry = zipIn.getNextEntry(); } zipIn.close(); }
From source file:de.uni_hildesheim.sse.ant.versionReplacement.PluginVersionReplacer.java
/** * Unpacks an existing JAR/Zip archive./* ww w . j av a 2s . c o m*/ * * @param zipFile The Archive file to unzip. * @param outputFolder The destination folder where the unzipped content shall be saved. * @see <a href="http://www.mkyong.com/java/how-to-decompress-files-from-a-zip-file/"> * http://www.mkyong.com/java/how-to-decompress-files-from-a-zip-file/</a> */ private static void unZipIt(File zipFile, File outputFolder) { byte[] buffer = new byte[1024]; try { // create output directory is not exists File folder = outputFolder; if (folder.exists()) { FileUtils.deleteDirectory(folder); } folder.mkdir(); // get the zip file content ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); // get the zipped file list entry ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder, fileName); // create all non exists folders // else you will hit FileNotFoundException for compressed folder new File(newFile.getParent()).mkdirs(); if (!ze.isDirectory()) { FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); } ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:com.aurel.track.dbase.InitReportTemplateBL.java
/** * Unzip a ZIP file into a directory/*ww w.j a v a2 s .co m*/ * @param zipFile * @param dir */ private static void unzipFileIntoDirectory(ZipFile zipFile, File dir) { Enumeration files = zipFile.entries(); File f = null; FileOutputStream fos = null; while (files.hasMoreElements()) { try { ZipEntry entry = (ZipEntry) files.nextElement(); InputStream eis = zipFile.getInputStream(entry); byte[] buffer = new byte[1024]; int bytesRead = 0; f = new File(dir.getAbsolutePath() + File.separator + entry.getName()); if (entry.isDirectory()) { f.mkdirs(); continue; } else { f.getParentFile().mkdirs(); f.createNewFile(); } fos = new FileOutputStream(f); while ((bytesRead = eis.read(buffer)) != -1) { fos.write(buffer, 0, bytesRead); } } catch (IOException e) { LOGGER.debug(ExceptionUtils.getStackTrace(e)); continue; } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { // ignore } } } } }
From source file:com.amalto.core.jobox.util.JoboxUtil.java
public static void extract(String zipPathFile, String destinationPath) throws Exception { FileInputStream fins = new FileInputStream(zipPathFile); ZipInputStream zipInputStream = new ZipInputStream(fins); try {//www. j a v a 2s .c om ZipEntry ze; byte ch[] = new byte[256]; while ((ze = zipInputStream.getNextEntry()) != null) { File zipFile = new File(destinationPath + ze.getName()); File zipFilePath = new File(zipFile.getParentFile().getPath()); if (ze.isDirectory()) { if (!zipFile.exists()) { if (!zipFile.mkdirs()) { LOGGER.error("Create folder failed for '" + zipFile.getAbsolutePath() + "'."); //$NON-NLS-1$ //$NON-NLS-2$ } } zipInputStream.closeEntry(); } else { if (!zipFilePath.exists()) { if (!zipFilePath.mkdirs()) { LOGGER.error("Create folder failed for '" + zipFilePath.getAbsolutePath() + "'."); //$NON-NLS-1$ //$NON-NLS-2$ } } FileOutputStream fileOutputStream = new FileOutputStream(zipFile); try { int i; while ((i = zipInputStream.read(ch)) != -1) { fileOutputStream.write(ch, 0, i); } zipInputStream.closeEntry(); } finally { fileOutputStream.close(); } } } } finally { IOUtils.closeQuietly(fins); IOUtils.closeQuietly(zipInputStream); } }