List of usage examples for java.util.zip ZipFile entries
public Enumeration<? extends ZipEntry> entries()
From source file:edu.umd.cs.buildServer.ProjectSubmission.java
public Set<String> getFilesInSubmission() throws IOException { HashSet<String> result = new HashSet<String>(); ZipFile z = null; try {//from w w w. j a va 2s .c om z = new ZipFile(getZipFile()); Enumeration<? extends ZipEntry> e = z.entries(); while (e.hasMoreElements()) { ZipEntry entry = e.nextElement(); result.add(entry.getName()); } } finally { IO.closeSilently(z); } return result; }
From source file:de.dfki.km.perspecting.obie.corpus.TextCorpus.java
/** * @return list of files in corpus/*w ww . j ava 2 s. c o m*/ * @throws IOException * @throws ZipException */ @SuppressWarnings("unchecked") protected HashMap<URI, InputStream> getEntries() throws Exception { HashMap<URI, InputStream> entries = new HashMap<URI, InputStream>(); if (corpusFileMediaType == MediaType.ZIP) { ZipFile zippedCorpusDir = new ZipFile(corpus); Enumeration<? extends ZipEntry> zipEntries = zippedCorpusDir.entries(); while (zipEntries.hasMoreElements()) { ZipEntry zipEntry = zipEntries.nextElement(); if (!zipEntry.isDirectory()) { String uriValue = corpus.toURI().toString() + "/"; String entryName = zipEntry.getName(); uriValue += URLEncoder.encode(entryName, "utf-8"); entries.put(new URI(uriValue), zippedCorpusDir.getInputStream(zipEntry)); } } } else if (corpusFileMediaType == MediaType.DIRECTORY) { for (File f : corpus.listFiles()) { entries.put(f.toURI(), new FileInputStream(f)); } } return entries; }
From source file:org.eclipse.mylyn.internal.context.core.InteractionContextExternalizer.java
private ZipEntry findFileInZip(ZipFile zipFile, String identifier) throws UnsupportedEncodingException { String encoded = URLEncoder.encode(identifier, InteractionContextManager.CONTEXT_FILENAME_ENCODING); for (Enumeration<?> e = zipFile.entries(); e.hasMoreElements();) { ZipEntry entry = (ZipEntry) e.nextElement(); if (entry.getName().equals(encoded)) { return entry; }/*w ww . jav a 2s.c o m*/ } return null; }
From source file:de.jcup.egradle.core.util.FileSupport.java
/** * Unzips the given zip file to the given destination directory extracting * only those entries the pass through the given filter. * * @param zipFile//w ww . ja v a2s . c o m * the zip file to unzip * @param dstDir * the destination directory * @throws IOException * in case of problem */ public void unzip(ZipFile zipFile, File dstDir) throws IOException { Enumeration<? extends ZipEntry> entries = zipFile.entries(); try { while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.isDirectory()) { continue; } String entryName = entry.getName(); File file = new File(dstDir, changeSeparator(entryName, '/', File.separatorChar)); file.getParentFile().mkdirs(); InputStream src = null; OutputStream dst = null; try { src = zipFile.getInputStream(entry); dst = new FileOutputStream(file); transferData(src, dst); } finally { if (dst != null) { try { dst.close(); } catch (IOException e) { } } if (src != null) { src.close(); } } } } finally { try { zipFile.close(); } catch (IOException e) { } } }
From source file:com.skcraft.launcher.launch.JavaRuntimeFetcher.java
private void extract(File zip, File destination) { if (!zip.exists()) { throw new UnsupportedOperationException("Attempted to extract non-existent file: " + zip); }// www . ja va 2 s . com if (destination.mkdirs()) { log.log(Level.INFO, "Creating dir: {0}", destination); } ZipFile zipFile = null; try { zipFile = new ZipFile(zip); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (!entry.isDirectory()) { InputStream inputStream = zipFile.getInputStream(entry); File file = new File(destination, entry.getName()); copyFile(inputStream, file, SharedLocale.tr("runtimeFetcher.extract", file.getName()), -1); } } } catch (IOException e) { e.printStackTrace(); } finally { Closer.close(zipFile); } }
From source file:io.fabric8.forge.camel.commands.CamelNewComponentsCommand.java
private String findComponentFQCN(String component, String selectedVersion) { String result = null;// w w w .j av a 2 s . com InputStream stream = null; try { File tmp = File.createTempFile("camel-dep", "jar"); URL url = new URL(String.format("https://repo1.maven.org/maven2/org/apache/camel/%s/%s/%s-%s.jar", component, selectedVersion, component, selectedVersion)); FileUtils.copyURLToFile(url, tmp); ZipFile zipFile = new ZipFile(tmp); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().startsWith("META-INF/services/org/apache/camel/component/") && !entry.isDirectory()) { stream = zipFile.getInputStream(entry); Properties prop = new Properties(); prop.load(stream); result = prop.getProperty("class"); break; } } } catch (Exception e) { throw new RuntimeException("Unable to inspect added component", e); } finally { if (stream != null) { try { stream.close(); } catch (Exception e) { } } } return result; }
From source file:CrossRef.java
/** For each Zip file, for each entry, xref it */ public void processOneZip(String fileName) throws IOException { List entries = new ArrayList(); ZipFile zipFile = null; try {//from ww w .j a v a2s . co m zipFile = new ZipFile(new File(fileName)); } catch (ZipException zz) { throw new FileNotFoundException(zz.toString() + fileName); } Enumeration all = zipFile.entries(); // Put the entries into the List for sorting... while (all.hasMoreElements()) { ZipEntry zipEntry = (ZipEntry) all.nextElement(); entries.add(zipEntry); } // Sort the entries (by class name) // Collections.sort(entries); // Process all the entries in this zip. Iterator it = entries.iterator(); while (it.hasNext()) { ZipEntry zipEntry = (ZipEntry) it.next(); String zipName = zipEntry.getName(); // Ignore package/directory, other odd-ball stuff. if (zipEntry.isDirectory()) { continue; } // Ignore META-INF stuff if (zipName.startsWith("META-INF/")) { continue; } // Ignore images, HTML, whatever else we find. if (!zipName.endsWith(".class")) { continue; } // If doing CLASSPATH, Ignore com.* which are "internal API". // if (doingStandardClasses && !zipName.startsWith("java")){ // continue; // } // Convert the zip file entry name, like // java/lang/Math.class // to a class name like // java.lang.Math String className = zipName.replace('/', '.').substring(0, zipName.length() - 6); // 6 for ".class" // Now get the Class object for it. Class c = null; try { c = Class.forName(className); } catch (ClassNotFoundException ex) { System.err.println("Error: " + ex); } // Hand it off to the subclass... doClass(c); } }
From source file:au.org.ala.delta.util.Utils.java
/** * Unzips the supplied zip file/*from ww w. j a va2 s . c o m*/ * * @param zip * The zip file to extract * @param destinationDir * the directory to extract the zip to * @throws IOException * if an error occurred while extracting the zip file. */ public static void extractZipFile(File zip, File destinationDir) throws IOException { if (!zip.exists()) { throw new IllegalArgumentException("zip file does not exist"); } if (!zip.isFile()) { throw new IllegalArgumentException("supplied zip file is not a file"); } if (!destinationDir.exists()) { throw new IllegalArgumentException("destination does not exist"); } if (!destinationDir.isDirectory()) { throw new IllegalArgumentException("destination is not a directory"); } ZipFile zipFile = new ZipFile(zip); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String entryName = entry.getName(); File fileForEntry = new File(destinationDir, entryName); if (entry.isDirectory() && !fileForEntry.exists()) { fileForEntry.mkdirs(); } else { InputStream is = new BufferedInputStream(zipFile.getInputStream(entry)); FileUtils.copyInputStreamToFile(is, fileForEntry); } } }
From source file:com.aurel.track.lucene.util.openOffice.OOIndexer.java
private List unzip(String zip, String destination) { List destLs = new ArrayList(); Enumeration entries;/*w w w. jav a 2 s .c om*/ ZipFile zipFile; File dest = new File(destination); dest.mkdir(); if (dest.isDirectory()) { try { zipFile = new ZipFile(zip); entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); if (entry.isDirectory()) { (new File(dest.getAbsolutePath() + File.separator + entry.getName())).mkdirs(); continue; } if (entry.getName().lastIndexOf("/") > 0) { File f = new File(dest.getAbsolutePath() + File.separator + entry.getName().substring(0, entry.getName().lastIndexOf("/"))); f.mkdirs(); } copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream( new FileOutputStream(dest.getAbsolutePath() + File.separator + entry.getName()))); destLs.add(dest.getAbsolutePath() + File.separator + TMP_UNZIP_DIR + File.separator + entry.getName()); } zipFile.close(); } catch (IOException e) { deleteDir(new File(destination)); LOGGER.error(e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } } else { LOGGER.info("There is already a file by that name"); } return destLs; }