@Override public Predicate<ZipEntry> filter(ZipEntry entry) { return zipEntry -> !zipEntry.isDirectory() && zipEntry.getName().contains(PROCESSES); }
public static void unzip(File zipfile, File directory) throws IOException { ZipFile zfile = new ZipFile(zipfile); Enumeration<? extends ZipEntry> entries = zfile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File file = new File(directory, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { file.getParentFile().mkdirs(); InputStream in = zfile.getInputStream(entry); try { copy(in, file); } finally { in.close(); } } } }
List<String> classNames = new ArrayList<String>(); ZipInputStream zip = new ZipInputStream(new FileInputStream("/path/to/jar/file.jar")); for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) { if (!entry.isDirectory() && entry.getName().endsWith(".class")) { // This ZipEntry represents a class. Now, what class does it represent? String className = entry.getName().replace('/', '.'); // including ".class" classNames.add(className.substring(0, className.length() - ".class".length())); } }
zip = new ZipFile(zipFile); for (ZipEntry entry : asIterable(zip.entries())) { if (entry.isDirectory()) { new File(toDir, entry.getName()).mkdirs(); in = zip.getInputStream(entry); File outFile = new File(toDir, entry.getName()); outFile.getParentFile().mkdirs(); out = new BufferedOutputStream(new FileOutputStream(outFile));
private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException { if (entry.isDirectory()) { createDir(new File(outputDir, entry.getName())); return; } 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(); } }
final ZipEntry entry, final String name) throws IOException { File file = new File(destDir, name); files.add(file); if (entry.isDirectory()) { return createOrExistsDir(file); } else { try { in = new BufferedInputStream(zip.getInputStream(entry)); out = new BufferedOutputStream(new FileOutputStream(file)); byte buffer[] = new byte[BUFFER_LEN]; int len;
public static void unzipFiles(ZipFile zipFile, String targetDirectory, String[] zipEntries, Map<String, String> zipEntryToFilenameMap) throws IOException { File dir = new File(targetDirectory); if (!dir.exists() && !dir.mkdirs()) { throw new IOException("Failed to create target directory: " + targetDirectory); } if (zipEntryToFilenameMap == null) { zipEntryToFilenameMap = new HashMap<>(); } for (String requestedEntry : zipEntries) { ZipEntry ze = zipFile.getEntry(requestedEntry); if (ze != null) { String name = ze.getName(); if (zipEntryToFilenameMap.containsKey(name)) { name = zipEntryToFilenameMap.get(name); } File destFile = new File(dir, name); if (!isInside(destFile, dir)) { Timber.e("Refusing to decompress invalid path: %s", destFile.getCanonicalPath()); throw new IOException("File is outside extraction target directory."); } if (!ze.isDirectory()) { Timber.i("uncompress %s", name); try (InputStream zis = zipFile.getInputStream(ze)) { writeToFile(zis, destFile.getAbsolutePath()); } } } } }
public void process(InputStream in, ZipEntry zipEntry) throws IOException { String entryName = zipEntry.getName(); if (visitedNames.contains(entryName)) { return; } visitedNames.add(entryName); File file = new File(destination, entryName); if (zipEntry.isDirectory()) { FileUtils.forceMkdir(file); return; } else { FileUtils.forceMkdir(file.getParentFile()); file.createNewFile(); } ZipEntryTransformer transformer = (ZipEntryTransformer) entryByPath.remove(entryName); if (transformer == null) { // no transformer FileUtils.copy(in, file); } else { // still transform entry transformIntoFile(transformer, in, zipEntry, file); } }
public static void decompress(InputStream input, File destDir) throws IOException { ZipInputStream zin = new ZipInputStream(input); ZipEntry entry = null; byte[] buffer = new byte[1024]; while ((entry = zin.getNextEntry()) != null) { File f = getZipOutputFile(destDir, entry); if (entry.isDirectory()) { f.mkdirs(); continue; } BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f)); int n = -1; while ((n = zin.read(buffer)) != -1) { out.write(buffer, 0, n); } out.flush(); out.close(); } }
byte[] data = Files.readAllBytes(new File(remainingArgs[0]).toPath()); try(com.googlecode.d2j.util.zip.ZipFile zipFile = new com.googlecode.d2j.util.zip.ZipFile(data)) { for (com.googlecode.d2j.util.zip.ZipEntry e : zipFile.entries()) { zos.putNextEntry(nEntry); if (!nEntry.isDirectory()) { try (InputStream is = zipFile.getInputStream(e)) { while (true) {
private void scanForNextEntry() { while (nextEntry == null) { if (!zipEntryEnumerator.hasMoreElements()) { return; } ZipEntry zipEntry = zipEntryEnumerator.nextElement(); if (!zipEntry.isDirectory()) { addLastModifiedTime(zipEntry.getTime()); nextEntry = new ZipFileCodeBaseEntry(ZipFileCodeBase.this, zipEntry); break; } } } };
jarEntry = jarStream.getNextEntry(); String entryName = jarEntry.getName(); if (!jarEntry.isDirectory() && entryName.endsWith(".class")) { jarEntry = jarStream.getNextEntry();
return bs; case ZIP: { ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(bs)); ZipEntry ze = zis.getNextEntry(); // Get the *FIRST* entry if( ze != null && !ze.isDirectory() ) { is = zis; break;
JarFile jarFile = new JarFile(pathToJar); Enumeration<JarEntry> e = jarFile.entries(); URL[] urls = { new URL("jar:file:" + pathToJar+"!/") }; URLClassLoader cl = URLClassLoader.newInstance(urls); while (e.hasMoreElements()) { JarEntry je = e.nextElement(); if(je.isDirectory() || !je.getName().endsWith(".class")){ continue; } // -6 because of .class String className = je.getName().substring(0,je.getName().length()-6); className = className.replace('/', '.'); Class c = cl.loadClass(className); }
private InputStream getDataFromZip(InputStream is, String name) throws IOException { final ZipInputStream zis = new ZipInputStream(is); ZipEntry ze = zis.getNextEntry(); while (ze != null) { final String fileName = ze.getName(); if (ze.isDirectory()) { } else if (fileName.equals(name)) { return zis; } ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); return null; }
private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException { if (entry.isDirectory()) { createDir(new File(outputDir, entry.getName())); return; } 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(); } }
while (true) { ZipEntry e = in.getNextEntry(); if (e == null) { break; if (!e.isDirectory()) { String name = e.getName(); long size = e.getSize();
private boolean accept(final ZipEntry entry) { if (entry.isDirectory()) { return false; } if (entryNameFilter == null) { return true; } for (final String filter : entryNameFilter) { if (entry.getName().startsWith(filter)) { return true; } } return false; }
java.util.jar.JarFile jar = new java.util.jar.JarFile(jarFile); java.util.Enumeration enumEntries = jar.entries(); while (enumEntries.hasMoreElements()) { java.util.jar.JarEntry file = (java.util.jar.JarEntry) enumEntries.nextElement(); java.io.File f = new java.io.File(destDir + java.io.File.separator + file.getName()); if (file.isDirectory()) { // if its a directory, create it f.mkdir(); continue; } java.io.InputStream is = jar.getInputStream(file); // get the input stream java.io.FileOutputStream fos = new java.io.FileOutputStream(f); while (is.available() > 0) { // write contents of 'is' to 'fos' fos.write(is.read()); } fos.close(); is.close(); }
import org.apache.commons.io.IOUtils; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public boolean unzip(InputStream inputStream, File outputFolder) throws IOException { ZipInputStream zis = new ZipInputStream(inputStream); ZipEntry entry; boolean isEmpty = true; while ((entry = zis.getNextEntry()) != null) { isEmpty = false; File newFile = new File(outputFolder, entry.getName()); if (newFile.getParentFile().mkdirs() && !entry.isDirectory()) { FileOutputStream fos = new FileOutputStream(newFile); IOUtils.copy(zis, fos); IOUtils.closeQuietly(fos); } } IOUtils.closeQuietly(zis); return !isEmpty; }