private static void unzipEntry(ZipEntry entry, ZipInputStream zipStream, Path targetDirNormalized) throws IOException { File to = targetDirNormalized.resolve(entry.getName()).toFile(); verifyInsideTargetDirectory(entry, to.toPath(), targetDirNormalized); if (entry.isDirectory()) { throwExceptionIfDirectoryIsNotCreatable(to); } else { File parent = to.getParentFile(); throwExceptionIfDirectoryIsNotCreatable(parent); copy(zipStream, to); } }
File parent = target.getParentFile(); throwExceptionIfDirectoryIsNotCreatable(parent); copy(zipFile, entry, target);
private static void unzipEntry(ZipEntry entry, ZipInputStream zipStream, Path targetDirNormalized) throws IOException { File to = targetDirNormalized.resolve(entry.getName()).toFile(); verifyInsideTargetDirectory(entry, to.toPath(), targetDirNormalized); if (entry.isDirectory()) { throwExceptionIfDirectoryIsNotCreatable(to); } else { File parent = to.getParentFile(); throwExceptionIfDirectoryIsNotCreatable(parent); copy(zipStream, to); } }
public static File unzip(InputStream stream, File toDir, ZipEntryFilter filter) throws IOException { if (!toDir.exists()) { FileUtils.forceMkdir(toDir); } ZipInputStream zipStream = new ZipInputStream(stream); try { ZipEntry entry; while ((entry = zipStream.getNextEntry()) != null) { if (filter.accept(entry)) { File to = new File(toDir, entry.getName()); if (entry.isDirectory()) { throwExceptionIfDirectoryIsNotCreatable(to); } else { File parent = to.getParentFile(); throwExceptionIfDirectoryIsNotCreatable(parent); copy(zipStream, to); } } } return toDir; } finally { zipStream.close(); } }
public static File unzip(File zip, File toDir, ZipEntryFilter filter) throws IOException { if (!toDir.exists()) { FileUtils.forceMkdir(toDir); } ZipFile zipFile = new ZipFile(zip); try { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (filter.accept(entry)) { File to = new File(toDir, entry.getName()); if (entry.isDirectory()) { throwExceptionIfDirectoryIsNotCreatable(to); } else { File parent = to.getParentFile(); throwExceptionIfDirectoryIsNotCreatable(parent); copy(zipFile, entry, to); } } } return toDir; } finally { zipFile.close(); } }
File parent = target.getParentFile(); throwExceptionIfDirectoryIsNotCreatable(parent); copy(zipFile, entry, target);