List of usage examples for java.util.zip ZipInputStream closeEntry
public void closeEntry() throws IOException
From source file:wordnice.utils.JavaUtils.java
public static void getClassesZip(VHandler<String> handler, ZipInputStream zip) throws Exception { ZipEntry ent = null;/*from ww w . j av a 2 s . c o m*/ while ((ent = zip.getNextEntry()) != null) { if (!ent.isDirectory()) { String clsn = ent.getName(); if (clsn.endsWith(".class") && clsn.indexOf('$') == -1) { handler.handle(clsn.substring(0, clsn.length() - 6).replace(File.separatorChar, '.')); } } zip.closeEntry(); } zip.close(); }
From source file:de.pksoftware.springstrap.sapi.util.WebappZipper.java
/** * Unzip it//w w w . j a v a 2s . com * @param zipFile input zip file * @param output zip file output folder */ public static void unzip(String zipFile, String outputFolder) { logger.info("Unzipping {} into {}.", zipFile, outputFolder); byte[] buffer = new byte[1024]; try { //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) { if (ze.isDirectory()) { ze = zis.getNextEntry(); continue; } String fileName = ze.getName(); File newFile = new File(outputFolder + File.separator + fileName); logger.debug("Unzipping: {}", newFile.getAbsoluteFile()); //create all non exists folders //else you will hit FileNotFoundException for compressed folder new File(newFile.getParent()).mkdirs(); 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(); logger.debug("Unzipping {} completed.", zipFile); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:eu.freme.eservices.epublishing.Unzipper.java
public static void unzip(ZipInputStream zis, File outputFolder) throws IOException { //create output directory is not exists if (!outputFolder.exists() && !outputFolder.mkdirs()) { throw new IOException("Cannot create directory " + outputFolder); }/*from w ww . j a v a 2 s . c o m*/ //get the zipped file list entry ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder, fileName); logger.debug("file unzip : " + newFile.getAbsoluteFile()); //create all non exists folders //else you will hit FileNotFoundException for compressed folder File parentDir = newFile.getParentFile(); if (!parentDir.exists() && !parentDir.mkdirs()) { throw new IOException("Cannot create directory " + newFile.getParent()); } if (ze.isDirectory()) { newFile.mkdirs(); } else { try (FileOutputStream fos = new FileOutputStream(newFile)) { IOUtils.copyLarge(zis, fos); } } ze = zis.getNextEntry(); } zis.closeEntry(); }
From source file:prototypes.ws.proxy.soap.commons.io.Files.java
/** * * @param zipFile/*from w ww.ja va 2s . c om*/ * @return */ public static String unzipFile(String zipFile) { FileOutputStream fos = null; try { File folder = createTempDirectory(); byte[] buffer = new byte[1024]; // create output directory is not exists if (!folder.exists()) { 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(folder.getAbsolutePath() + File.separator + fileName); LOGGER.debug("file unzip : {}", newFile.getAbsoluteFile()); // create all non exists folders // else you will hit FileNotFoundException for compressed folder new File(newFile.getParent()).mkdirs(); 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(); return folder.getAbsolutePath(); } catch (IOException ex) { LOGGER.error(ex.getMessage(), ex); } finally { if (fos != null) { try { fos.close(); } catch (IOException ex) { LOGGER.warn(Messages.MSG_ERROR_DETAILS, ex); } } } return null; }
From source file:lucee.commons.io.compress.CompressUtil.java
private static void unzip(Resource zipFile, Resource targetDir) throws IOException { /*if(zipFile instanceof File){ unzip((File)zipFile, targetDir);//from w w w . j a va2 s .c o m return; }*/ ZipInputStream zis = null; try { zis = new ZipInputStream(IOUtil.toBufferedInputStream(zipFile.getInputStream())); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { Resource target = targetDir.getRealResource(entry.getName()); if (entry.isDirectory()) { target.mkdirs(); } else { Resource parent = target.getParentResource(); if (!parent.exists()) parent.mkdirs(); IOUtil.copy(zis, target, false); } target.setLastModified(entry.getTime()); zis.closeEntry(); } } finally { IOUtil.closeEL(zis); } }
From source file:org.wso2.carbon.ei.migration.util.Utility.java
/** * Unzip the zip file/*from w ww.j av a2s . co m*/ * * @param zipFile input zip file * @param outputFolder zip file output folder */ public static void unZipIt(String zipFile, String outputFolder) throws MigrationClientException { byte[] buffer = new byte[1024]; try { //create output directory is not exists File folder = new File(outputFolder); if (!folder.exists()) { 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(); if (fileName.toLowerCase().endsWith(".xml") || fileName.toLowerCase().endsWith(".wsdl") || fileName.toLowerCase().endsWith(".bpel") || fileName.endsWith("README")) { File newFile = new File(outputFolder + File.separator + fileName); //create all non exists folders //else you will hit FileNotFoundException for compressed folder new File(newFile.getParent()).mkdirs(); 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 e) { throw new MigrationClientException(e.getMessage()); } }
From source file:com.cip.crane.agent.utils.FileExtractUtils.java
/** * Unzip an input file into an output file. * <p>/*from ww w. jav a 2s . c o m*/ * The output file is created in the output folder, having the same name * as the input file, minus the '.zip' extension. * * @param inputFile the input .zip file * @param outputDir the output directory file. * @throws IOException * @throws FileNotFoundException * * @return The {@File} with the ungzipped content. */ public static void unZip(final File inputFile, final File outputDir) throws FileNotFoundException, IOException { LOG.debug( String.format("Unzipping %s to dir %s.", inputFile.getAbsolutePath(), outputDir.getAbsolutePath())); byte[] buf = new byte[1024]; ZipInputStream zipinputstream = null; ZipEntry zipentry; zipinputstream = new ZipInputStream(new FileInputStream(inputFile)); zipentry = zipinputstream.getNextEntry(); while (zipentry != null) { //for each entry to be extracted String entryName = outputDir + "/" + zipentry.getName(); entryName = entryName.replace('/', File.separatorChar); entryName = entryName.replace('\\', File.separatorChar); int n; FileOutputStream fileoutputstream; File newFile = new File(entryName); if (zipentry.isDirectory()) { if (!newFile.mkdirs()) { break; } zipentry = zipinputstream.getNextEntry(); continue; } fileoutputstream = new FileOutputStream(entryName); while ((n = zipinputstream.read(buf, 0, 1024)) > -1) { fileoutputstream.write(buf, 0, n); } fileoutputstream.close(); zipinputstream.closeEntry(); zipentry = zipinputstream.getNextEntry(); } //while zipinputstream.close(); }
From source file:net.ftb.util.FileUtils.java
public static void backupExtract(String zipLocation, String outputLocation) { Logger.logInfo("Extracting (Backup way)"); byte[] buffer = new byte[1024]; ZipInputStream zis = null; ZipEntry ze;/*from w ww . j a va2s. c o m*/ try { File folder = new File(outputLocation); if (!folder.exists()) { folder.mkdir(); } zis = new ZipInputStream(new FileInputStream(zipLocation)); ze = zis.getNextEntry(); while (ze != null) { File newFile = new File(outputLocation, ze.getName()); newFile.getParentFile().mkdirs(); if (!ze.isDirectory()) { FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.flush(); fos.close(); } ze = zis.getNextEntry(); } } catch (IOException ex) { Logger.logError("Error while extracting zip", ex); } finally { try { zis.closeEntry(); zis.close(); } catch (IOException e) { } } }
From source file:utils.APIImporter.java
/** * function to unzip the imported folder * @param zipFile zip file path//ww w. jav a 2s. c o m * @param outputFolder folder to copy the zip content * @throws APIImportException */ private static void unzipFolder(String zipFile, String outputFolder) throws APIImportException { byte[] buffer = new byte[1024]; try { ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); //get the zipped file list entry ZipEntry ze = zis.getNextEntry(); FileOutputStream fos = null; while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder + File.separator + fileName); //create all non exists folders //else you will hit FileNotFoundException for compressed folder new File(newFile.getParent()).mkdirs(); fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); ze = zis.getNextEntry(); } zis.closeEntry(); IOUtils.closeQuietly(zis); IOUtils.closeQuietly(fos); // ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); // //get the zipped file list entry // ZipEntry ze = zis.getNextEntry(); // FileOutputStream fos = null; // while(ze!=null){ // String fileName = ze.getName(); // File newFile = new File(outputFolder + File.separator + fileName); // //create all non exists folders // //else it hit FileNotFoundException for compressed folder // boolean directoryStatus = new File(newFile.getParent()).mkdirs(); // while (directoryStatus){ // fos = new FileOutputStream(newFile); // int len; // while ((len = zis.read(buffer)) > 0) { // fos.write(buffer, 0, len); // } // ze = zis.getNextEntry(); // } // } // zis.closeEntry(); // IOUtils.closeQuietly(fos); // IOUtils.closeQuietly(zis); } catch (IOException e) { String errorMsg = "Cannot extract the zip entries "; log.error(errorMsg, e); throw new APIImportException(errorMsg, e); } }
From source file:net.ftb.util.FileUtils.java
/** * Extracts given zip to given location/*from w w w . j a va2s . c om*/ * @param zipLocation - the location of the zip to be extracted * @param outputLocation - location to extract to */ public static void extractZipTo(String zipLocation, String outputLocation) { ZipInputStream zipinputstream = null; try { byte[] buf = new byte[1024]; zipinputstream = new ZipInputStream(new FileInputStream(zipLocation)); ZipEntry zipentry = zipinputstream.getNextEntry(); while (zipentry != null) { String entryName = zipentry.getName(); int n; if (!zipentry.isDirectory() && !entryName.equalsIgnoreCase("minecraft") && !entryName.equalsIgnoreCase(".minecraft") && !entryName.equalsIgnoreCase("instMods")) { new File(outputLocation + File.separator + entryName).getParentFile().mkdirs(); FileOutputStream fileoutputstream = new FileOutputStream( outputLocation + File.separator + entryName); while ((n = zipinputstream.read(buf, 0, 1024)) > -1) { fileoutputstream.write(buf, 0, n); } fileoutputstream.close(); } zipinputstream.closeEntry(); zipentry = zipinputstream.getNextEntry(); } } catch (Exception e) { Logger.logError("Error while extracting zip", e); backupExtract(zipLocation, outputLocation); } finally { try { zipinputstream.close(); } catch (IOException e) { } } }