List of usage examples for java.util.zip ZipFile entries
public Enumeration<? extends ZipEntry> entries()
From source file:com.photon.maven.plugins.android.phase09package.ApkMojo.java
private void computeDuplicateFiles(File jar) throws IOException { ZipFile file = new ZipFile(jar); Enumeration<? extends ZipEntry> list = file.entries(); while (list.hasMoreElements()) { ZipEntry ze = list.nextElement(); if (!(ze.getName().contains("META-INF/") || ze.isDirectory())) { // Exclude // META-INF // and // Directories List<File> l = m_jars.get(ze.getName()); if (l == null) { l = new ArrayList<File>(); m_jars.put(ze.getName(), l); }/*w w w.j av a2 s . c om*/ l.add(jar); } } }
From source file:org.docx4j.openpackaging.io.LoadFromZipNG.java
public OpcPackage get(File f) throws Docx4JException { log.info("Filepath = " + f.getPath()); ZipFile zf = null; try {/* w ww.j av a 2s . c o m*/ if (!f.exists()) { log.info("Couldn't find " + f.getPath()); } zf = new ZipFile(f); } catch (IOException ioe) { ioe.printStackTrace(); throw new Docx4JException("Couldn't get ZipFile", ioe); } HashMap<String, ByteArray> partByteArrays = new HashMap<String, ByteArray>(); Enumeration entries = zf.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); log.info("\n\n" + entry.getName() + "\n"); InputStream in = null; try { byte[] bytes = getBytesFromInputStream(zf.getInputStream(entry)); partByteArrays.put(entry.getName(), new ByteArray(bytes)); } catch (Exception e) { e.printStackTrace(); } } // At this point, we've finished with the zip file try { zf.close(); } catch (IOException exc) { exc.printStackTrace(); } return process(partByteArrays); }
From source file:com.taobao.android.TPatchTool.java
/** * ?patchpatchInfo// w ww . j av a 2 s . c o m * * @param fileName * @return */ public PatchInfo createBasePatchInfo(File file) { PatchInfo patchInfo = new PatchInfo(); patchInfo.setPatchVersion(newApkBO.getVersionName()); patchInfo.setTargetVersion(baseApkBO.getVersionName()); patchInfo.setFileName(file.getName()); Set<String> modifyBundles = new HashSet<>(); ZipFile zipFile = newZipFile(file); Enumeration<? extends ZipEntry> enumeration = zipFile.entries(); while (enumeration.hasMoreElements()) { ZipEntry zipEntry = enumeration.nextElement(); if (zipEntry.getName().startsWith("lib") && zipEntry.getName().indexOf("/") != -1) { modifyBundles .add(zipEntry.getName().substring(3, zipEntry.getName().indexOf("/")).replace("_", ".")); } else if (zipEntry.getName().endsWith(".so") && zipEntry.getName().indexOf("/") == -1) { modifyBundles.add( zipEntry.getName().substring(3, zipEntry.getName().lastIndexOf(".")).replace("_", ".")); } } for (ArtifactBundleInfo artifactBundleInfo : artifactBundleInfos) { if (artifactBundleInfo.getMainBundle()) { if (DiffType.MODIFY.equals(artifactBundleInfo.getDiffType()) || hasMainBundle) { PatchBundleInfo patchBundleInfo = new PatchBundleInfo(); patchBundleInfo.setNewBundle(DiffType.ADD.equals(artifactBundleInfo.getDiffType())); patchBundleInfo.setMainBundle(true); patchBundleInfo.setVersion(artifactBundleInfo.getVersion()); patchBundleInfo.setName(mainBundleName); patchBundleInfo.setApplicationName(artifactBundleInfo.getApplicationName()); patchBundleInfo.setArtifactId(artifactBundleInfo.getArtifactId()); patchBundleInfo.setPkgName(artifactBundleInfo.getPkgName()); patchBundleInfo.setDependency(artifactBundleInfo.getDependency()); // patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion()); patchInfo.getBundles().add(patchBundleInfo); continue; } } else if (DiffType.MODIFY.equals(artifactBundleInfo.getDiffType()) || DiffType.ADD.equals(artifactBundleInfo.getDiffType())) { PatchBundleInfo patchBundleInfo = new PatchBundleInfo(); patchBundleInfo.setNewBundle(DiffType.ADD.equals(artifactBundleInfo.getDiffType())); patchBundleInfo.setMainBundle(false); patchBundleInfo.setVersion(artifactBundleInfo.getVersion()); patchBundleInfo.setName(artifactBundleInfo.getName()); patchBundleInfo.setApplicationName(artifactBundleInfo.getApplicationName()); patchBundleInfo.setArtifactId(artifactBundleInfo.getArtifactId()); patchBundleInfo.setPkgName(artifactBundleInfo.getPkgName()); patchBundleInfo.setDependency(artifactBundleInfo.getDependency()); // patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion()); patchInfo.getBundles().add(patchBundleInfo); } else if (modifyBundles.contains(artifactBundleInfo.getPkgName())) { PatchBundleInfo patchBundleInfo = new PatchBundleInfo(); patchBundleInfo.setNewBundle(false); patchBundleInfo.setMainBundle(false); patchBundleInfo.setVersion(artifactBundleInfo.getVersion()); patchBundleInfo.setName(artifactBundleInfo.getName()); patchBundleInfo.setApplicationName(artifactBundleInfo.getApplicationName()); patchBundleInfo.setArtifactId(artifactBundleInfo.getArtifactId()); patchBundleInfo.setPkgName(artifactBundleInfo.getPkgName()); patchBundleInfo.setDependency(artifactBundleInfo.getDependency()); // patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion()); patchInfo.getBundles().add(patchBundleInfo); } } try { zipFile.close(); } catch (IOException e) { e.printStackTrace(); } return patchInfo; }
From source file:com.headswilllol.basiclauncher.Launcher.java
public void actionPerformed(ActionEvent e) { // button was pressed if (e.getActionCommand().equals("play")) { // play button was pressed // clear dem buttons this.remove(play); this.remove(force); this.remove(noUpdate); this.remove(quit); File dir = new File(appData(), FOLDER_NAME + File.separator + "resources"); if (!downloadDir.isEmpty()) // -d flag was used dir = new File(downloadDir, FOLDER_NAME + File.separator + "resources"); dir.mkdir();//from w ww . j a v a 2 s. c o m try { progress = "Downloading JSON file list..."; paintImmediately(0, 0, width, height); Downloader jsonDl = new Downloader(new URL(JSON_LOCATION), dir.getPath() + File.separator + "resources.json", "JSON file list", true); Thread jsonT = new Thread(jsonDl); // download in a separate thread so the GUI will continue to update jsonT.start(); while (jsonT.isAlive()) { } // no need for a progress bar; it's tiny JSONArray files = (JSONArray) ((JSONObject) new JSONParser().parse(new InputStreamReader( new File(dir.getPath(), "resources.json").toURI().toURL().openStream()))).get("resources"); List<String> paths = new ArrayList<String>(); for (Object obj : files) { // iterate the entries in the JSON file JSONObject jFile = (JSONObject) obj; String launch = ((String) jFile.get("launch")); // if true, resource will be used as main binary if (launch != null && launch.equals("true")) main = new File(dir, ((String) jFile.get("localPath")).replace("/", File.separator)); paths.add(((String) jFile.get("localPath")).replace("/", File.separator)); File file = new File(dir, ((String) jFile.get("localPath")).replace("/", File.separator)); boolean reacquire = false; if (!file.exists() || // files doesn't exist (allowReacquire && // allow files to be reacquired (update || // update forced // mismatch between local and remote file !jFile.get("md5").equals(md5(file.getPath()))))) { reacquire = true; if (update) System.out.println( "Update forced, so file " + jFile.get("localPath") + " must be updated"); else if (!file.exists()) System.out.println("Cannot find local copy of file " + jFile.get("localPath")); else System.out.println("MD5 checksum for file " + jFile.get("localPath") + " does not match expected value"); System.out.println("Attempting to reacquire..."); file.delete(); file.getParentFile().mkdirs(); file.createNewFile(); progress = "Downloading " + jFile.get("id"); // update the GUI paintImmediately(0, 0, width, height); Downloader dl = new Downloader(new URL((String) jFile.get("location")), dir + File.separator + ((String) jFile.get("localPath")).replace("/", File.separator), (String) jFile.get("id"), !jFile.containsKey("doNotSpoofUserAgent") || !Boolean.parseBoolean((String) jFile.get("doNotSpoofUserAgent"))); Thread th = new Thread(dl); th.start(); eSize = getFileSize(new URL((String) jFile.get("location"))) / 8; // expected file size speed = 0; // stores the current download speed lastSize = 0; // stores the size of the downloaded file the last time the GUI was updated while (th.isAlive()) { // wait but don't hang the main thread aSize = file.length() / 8; if (lastTime != -1) { // wait so the GUI isn't constantly updating if (System.currentTimeMillis() - lastTime >= SPEED_UPDATE_INTERVAL) { speed = (aSize - lastSize) / ((System.currentTimeMillis() - lastTime) / 1000) * 8; // calculate new speed lastTime = System.currentTimeMillis(); lastSize = aSize; // update the downloaded file's size } } else { speed = 0; // reset the download speed lastTime = System.currentTimeMillis(); // and the last time } paintImmediately(0, 0, width, height); } eSize = -1; aSize = -1; } if (jFile.containsKey("extract")) { // file should be unzipped HashMap<String, JSONObject> elements = new HashMap<String, JSONObject>(); for (Object ex : (JSONArray) jFile.get("extract")) { elements.put((String) ((JSONObject) ex).get("path"), (JSONObject) ex); paths.add(((String) ((JSONObject) ex).get("localPath")).replace("/", File.separator)); File f = new File(dir, ((String) ((JSONObject) ex).get("localPath")).replace("/", File.separator)); if (!f.exists() || // file doesn't exist // file isn't directory and has checksum (!f.isDirectory() && ((JSONObject) ex).get("md5") != null && // mismatch between local and remote file !md5(f.getPath()).equals((((JSONObject) ex).get("md5"))))) reacquire = true; if (((JSONObject) ex).get("id").equals("natives")) // specific to LWJGL launching natives = new File(dir, ((String) ((JSONObject) ex).get("localPath")).replace("/", File.separator)); } if (reacquire) { try { ZipFile zip = new ZipFile(new File(dir, ((String) jFile.get("localPath")).replace("/", File.separator))); @SuppressWarnings("rawtypes") Enumeration en = zip.entries(); List<String> dirs = new ArrayList<String>(); while (en.hasMoreElements()) { // iterate entries in ZIP file ZipEntry entry = (ZipEntry) en.nextElement(); boolean extract = false; // whether the entry should be extracted String parentDir = ""; if (elements.containsKey(entry.getName())) // entry is in list of files to extract extract = true; else for (String d : dirs) if (entry.getName().contains(d)) { extract = true; parentDir = d; } if (extract) { progress = "Extracting " + (elements.containsKey(entry.getName()) ? elements.get(entry.getName()).get("id") : entry.getName() .substring(entry.getName().indexOf(parentDir), entry.getName().length()) .replace("/", File.separator)); // update the GUI paintImmediately(0, 0, width, height); if (entry.isDirectory()) { if (parentDir.equals("")) dirs.add((String) elements.get(entry.getName()).get("localPath")); } else { File path = new File(dir, (parentDir.equals("")) ? ((String) elements.get(entry.getName()).get("localPath")) .replace("/", File.separator) : entry.getName() .substring(entry.getName().indexOf(parentDir), entry.getName().length()) .replace("/", File.separator)); // path to extract to if (path.exists()) path.delete(); unzip(zip, entry, path); // *zziiiip* } } } } catch (Exception ex) { ex.printStackTrace(); createExceptionLog(ex); progress = "Failed to extract files from " + jFile.get("id"); fail = "Errors occurred; see log file for details"; launcher.paintImmediately(0, 0, width, height); } } } } checkFile(dir, dir, paths); } catch (Exception ex) { // can't open resource list ex.printStackTrace(); createExceptionLog(ex); progress = "Failed to read JSON file list"; fail = "Errors occurred; see log file for details"; launcher.paintImmediately(0, 0, width, height); } launch(); } else if (e.getActionCommand().equals("force")) { force.setActionCommand("noForce"); force.setText("Will Force!"); update = true; // reset do not reacquire button noUpdate.setActionCommand("noReacquire"); noUpdate.setText("Do Not Reacquire"); allowReacquire = true; } else if (e.getActionCommand().equals("noForce")) { force.setActionCommand("force"); force.setText("Force Update"); update = false; } else if (e.getActionCommand().equals("noReacquire")) { noUpdate.setActionCommand("yesReacquire"); noUpdate.setText("Will Not Reacquire!"); allowReacquire = false; // reset force update button force.setActionCommand("force"); force.setText("Force Update"); update = false; } else if (e.getActionCommand().equals("yesReacquire")) { noUpdate.setActionCommand("noReacquire"); noUpdate.setText("Do Not Reacquire"); allowReacquire = true; } else if (e.getActionCommand().equals("quit")) { pullThePlug(); } else if (e.getActionCommand().equals("kill")) gameProcess.destroyForcibly(); }
From source file:org.b3log.symphony.processor.CaptchaProcessor.java
/** * Loads captcha.//w w w .jav a2s . co m */ private synchronized void loadCaptchas() { LOGGER.trace("Loading captchas...."); try { captchas = new Image[CAPTCHA_COUNT]; ZipFile zipFile; if (RuntimeEnv.LOCAL == Latkes.getRuntimeEnv()) { final InputStream inputStream = SymphonyServletListener.class.getClassLoader() .getResourceAsStream("captcha_static.zip"); final File file = File.createTempFile("b3log_captcha_static", null); final OutputStream outputStream = new FileOutputStream(file); IOUtils.copy(inputStream, outputStream); zipFile = new ZipFile(file); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); } else { final URL captchaURL = SymphonyServletListener.class.getClassLoader() .getResource("captcha_static.zip"); zipFile = new ZipFile(captchaURL.getFile()); } final Enumeration<? extends ZipEntry> entries = zipFile.entries(); int i = 0; while (entries.hasMoreElements()) { final ZipEntry entry = entries.nextElement(); final BufferedInputStream bufferedInputStream = new BufferedInputStream( zipFile.getInputStream(entry)); final byte[] captchaCharData = new byte[bufferedInputStream.available()]; bufferedInputStream.read(captchaCharData); bufferedInputStream.close(); final Image image = IMAGE_SERVICE.makeImage(captchaCharData); image.setName(entry.getName().substring(0, entry.getName().lastIndexOf('.'))); captchas[i] = image; i++; } zipFile.close(); } catch (final Exception e) { LOGGER.error("Can not load captchs!"); throw new IllegalStateException(e); } LOGGER.trace("Loaded captch images"); }
From source file:com.simpligility.maven.plugins.android.phase09package.ApkMojo.java
private void updateWithMetaInf(ZipOutputStream zos, File jarFile, Set<String> entries, boolean metaInfOnly) throws IOException { ZipFile zin = new ZipFile(jarFile); for (Enumeration<? extends ZipEntry> en = zin.entries(); en.hasMoreElements();) { ZipEntry ze = en.nextElement(); if (ze.isDirectory()) { continue; }/*from w w w .j a va 2s .com*/ String zn = ze.getName(); if (metaInfOnly) { if (!zn.startsWith("META-INF/")) { continue; } if (!this.apkMetaInf.isIncluded(zn)) { continue; } } boolean resourceTransformed = false; if (transformers != null) { for (ResourceTransformer transformer : transformers) { if (transformer.canTransformResource(zn)) { getLog().info("Transforming " + zn + " using " + transformer.getClass().getName()); InputStream is = zin.getInputStream(ze); transformer.processResource(zn, is, null); is.close(); resourceTransformed = true; break; } } } if (!resourceTransformed) { // Avoid duplicates that aren't accounted for by the resource transformers if (metaInfOnly && this.extractDuplicates && !entries.add(zn)) { continue; } InputStream is = zin.getInputStream(ze); final ZipEntry ne; if (ze.getMethod() == ZipEntry.STORED) { ne = new ZipEntry(ze); } else { ne = new ZipEntry(zn); } zos.putNextEntry(ne); copyStreamWithoutClosing(is, zos); is.close(); zos.closeEntry(); } } zin.close(); }
From source file:org.hammurapi.TaskBase.java
protected File processArchive() { if (archive == null) { return null; }//from ww w.ja v a2s. co m String tmpDirProperty = System.getProperty("java.io.tmpdir"); File tmpDir = tmpDirProperty == null ? new File(".") : new File(tmpDirProperty); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); String prefix = "har_" + sdf.format(new Date()); File workDir = unpackDir == null ? new File(tmpDir, prefix) : unpackDir; for (int i = 0; unpackDir == null && workDir.exists(); i++) { workDir = new File(tmpDir, prefix + "_" + Integer.toString(i, Character.MAX_RADIX)); } if (workDir.exists() || workDir.mkdir()) { try { ZipFile zipFile = new ZipFile(archive); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); if (!entry.getName().endsWith("/")) { File outFile = new File(workDir, entry.getName().replace('/', File.separatorChar)); if (!outFile.getParentFile().exists() && !outFile.getParentFile().mkdirs()) { throw new BuildException("Directory does not exist and cannot be created: " + outFile.getParentFile().getAbsolutePath()); } log("Archive entry " + entry.getName() + " unpacked to " + outFile.getAbsolutePath(), Project.MSG_DEBUG); byte[] buf = new byte[4096]; int l; InputStream in = zipFile.getInputStream(entry); FileOutputStream fos = new FileOutputStream(outFile); while ((l = in.read(buf)) != -1) { fos.write(buf, 0, l); } in.close(); fos.close(); } } zipFile.close(); File configFile = new File(workDir, "config.xml"); if (configFile.exists() && configFile.isFile()) { Document configDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(configFile); processConfig(workDir, configDoc.getDocumentElement()); } else { throw new BuildException("Archive configuration file does not exist or is not a file"); } } catch (ZipException e) { throw new BuildException(e.toString(), e); } catch (IOException e) { throw new BuildException(e.toString(), e); } catch (SAXException e) { throw new BuildException(e.toString(), e); } catch (ParserConfigurationException e) { throw new BuildException(e.toString(), e); } catch (FactoryConfigurationError e) { throw new BuildException(e.toString(), e); } } else { throw new BuildException("Could not create directory " + workDir.getAbsolutePath()); } return unpackDir == null ? workDir : null; }
From source file:org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.java
/** {@inheritDoc} */ public void copyResources(SiteRenderingContext siteRenderingContext, File outputDirectory) throws IOException { if (siteRenderingContext.getSkin() != null) { ZipFile file = getZipFile(siteRenderingContext.getSkin().getFile()); try {//from w w w . ja v a 2 s . co m for (Enumeration<? extends ZipEntry> e = file.entries(); e.hasMoreElements();) { ZipEntry entry = e.nextElement(); if (!entry.getName().startsWith("META-INF/")) { File destFile = new File(outputDirectory, entry.getName()); if (!entry.isDirectory()) { if (destFile.exists()) { // don't override existing content: avoids extra rewrite with same content or extra site // resource continue; } destFile.getParentFile().mkdirs(); copyFileFromZip(file, entry, destFile); } else { destFile.mkdirs(); } } } } finally { closeZipFile(file); } } if (siteRenderingContext.isUsingDefaultTemplate()) { InputStream resourceList = getClass().getClassLoader() .getResourceAsStream(RESOURCE_DIR + "/resources.txt"); if (resourceList != null) { Reader r = null; LineNumberReader reader = null; try { r = ReaderFactory.newReader(resourceList, ReaderFactory.UTF_8); reader = new LineNumberReader(r); String line; while ((line = reader.readLine()) != null) { if (line.startsWith("#") || line.trim().length() == 0) { continue; } InputStream is = getClass().getClassLoader().getResourceAsStream(RESOURCE_DIR + "/" + line); if (is == null) { throw new IOException("The resource " + line + " doesn't exist."); } File outputFile = new File(outputDirectory, line); if (outputFile.exists()) { // don't override existing content: avoids extra rewrite with same content or extra site // resource continue; } if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } OutputStream os = null; try { // for the images os = new FileOutputStream(outputFile); IOUtil.copy(is, os); } finally { IOUtil.close(os); } IOUtil.close(is); } } finally { IOUtil.close(reader); IOUtil.close(r); } } } // Copy extra site resources for (File siteDirectory : siteRenderingContext.getSiteDirectories()) { File resourcesDirectory = new File(siteDirectory, "resources"); if (resourcesDirectory != null && resourcesDirectory.exists()) { copyDirectory(resourcesDirectory, outputDirectory); } } // Check for the existence of /css/site.css File siteCssFile = new File(outputDirectory, "/css/site.css"); if (!siteCssFile.exists()) { // Create the subdirectory css if it doesn't exist, DOXIA-151 File cssDirectory = new File(outputDirectory, "/css/"); boolean created = cssDirectory.mkdirs(); if (created && getLogger().isDebugEnabled()) { getLogger().debug( "The directory '" + cssDirectory.getAbsolutePath() + "' did not exist. It was created."); } // If the file is not there - create an empty file, DOXIA-86 if (getLogger().isDebugEnabled()) { getLogger().debug( "The file '" + siteCssFile.getAbsolutePath() + "' does not exist. Creating an empty file."); } Writer writer = null; try { writer = WriterFactory.newWriter(siteCssFile, siteRenderingContext.getOutputEncoding()); //DOXIA-290...the file should not be 0 bytes. writer.write("/* You can override this file with your own styles */"); } finally { IOUtil.close(writer); } } }
From source file:com.photon.maven.plugins.android.phase09package.ApkMojo.java
private File removeDuplicatesFromJar(File in, List<String> duplicates) { File target = new File(project.getBasedir(), "target"); File tmp = new File(target, "unpacked-embedded-jars"); tmp.mkdirs();/* w ww .j a va2 s.c om*/ File out = new File(tmp, in.getName()); if (out.exists()) { return out; } try { out.createNewFile(); } catch (IOException e) { e.printStackTrace(); } // Create a new Jar file FileOutputStream fos = null; ZipOutputStream jos = null; try { fos = new FileOutputStream(out); jos = new ZipOutputStream(fos); } catch (FileNotFoundException e1) { getLog().error( "Cannot remove duplicates : the output file " + out.getAbsolutePath() + " does not found"); return null; } ZipFile inZip = null; try { inZip = new ZipFile(in); Enumeration<? extends ZipEntry> entries = inZip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); // If the entry is not a duplicate, copy. if (!duplicates.contains(entry.getName())) { // copy the entry header to jos jos.putNextEntry(entry); InputStream currIn = inZip.getInputStream(entry); copyStreamWithoutClosing(currIn, jos); currIn.close(); jos.closeEntry(); } } } catch (IOException e) { getLog().error("Cannot removing duplicates : " + e.getMessage()); return null; } try { if (inZip != null) { inZip.close(); } jos.close(); fos.close(); jos = null; fos = null; } catch (IOException e) { // ignore it. } getLog().info(in.getName() + " rewritten without duplicates : " + out.getAbsolutePath()); return out; }
From source file:com.simpligility.maven.plugins.android.phase09package.ApkMojo.java
private File removeDuplicatesFromJar(File in, List<String> duplicates, Set<String> duplicatesAdded, ZipOutputStream duplicateZos, int num) { String target = targetDirectory.getAbsolutePath(); File tmp = new File(target, "unpacked-embedded-jars"); tmp.mkdirs();//from ww w. j a v a 2s . c o m String jarName = String.format("%s-%d.%s", Files.getNameWithoutExtension(in.getName()), num, Files.getFileExtension(in.getName())); File out = new File(tmp, jarName); if (out.exists()) { return out; } else { try { out.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } // Create a new Jar file final FileOutputStream fos; final ZipOutputStream jos; try { fos = new FileOutputStream(out); jos = new ZipOutputStream(fos); } catch (FileNotFoundException e1) { getLog().error( "Cannot remove duplicates : the output file " + out.getAbsolutePath() + " does not found"); return null; } final ZipFile inZip; try { inZip = new ZipFile(in); Enumeration<? extends ZipEntry> entries = inZip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); // If the entry is not a duplicate, copy. if (!duplicates.contains(entry.getName())) { // copy the entry header to jos jos.putNextEntry(entry); InputStream currIn = inZip.getInputStream(entry); copyStreamWithoutClosing(currIn, jos); currIn.close(); jos.closeEntry(); } //if it is duplicate, check the resource transformers else { boolean resourceTransformed = false; if (transformers != null) { for (ResourceTransformer transformer : transformers) { if (transformer.canTransformResource(entry.getName())) { getLog().info("Transforming " + entry.getName() + " using " + transformer.getClass().getName()); InputStream currIn = inZip.getInputStream(entry); transformer.processResource(entry.getName(), currIn, null); currIn.close(); resourceTransformed = true; break; } } } //if not handled by transformer, add (once) to duplicates jar if (!resourceTransformed) { if (!duplicatesAdded.contains(entry.getName())) { duplicatesAdded.add(entry.getName()); duplicateZos.putNextEntry(entry); InputStream currIn = inZip.getInputStream(entry); copyStreamWithoutClosing(currIn, duplicateZos); currIn.close(); duplicateZos.closeEntry(); } } } } } catch (IOException e) { getLog().error("Cannot removing duplicates : " + e.getMessage()); return null; } try { inZip.close(); jos.close(); fos.close(); } catch (IOException e) { // ignore it. } getLog().info(in.getName() + " rewritten without duplicates : " + out.getAbsolutePath()); return out; }