@Test public void unzip() throws URISyntaxException, IOException { Path destPath = Paths.get("target/unzip"); try { Path zipFile = Paths.get(Thread.currentThread().getContextClassLoader().getResource("test-repository.zip").toURI()); if (Files.exists(destPath)) { org.apache.commons.io.FileUtils.deleteQuietly(destPath.toFile()); } FileUtils.unzip(zipFile, destPath); assertTrue(Files.exists(destPath.resolve("org/apache/maven/A/1.0/A-1.0.pom"))); assertTrue(Files.isRegularFile(destPath.resolve("org/apache/maven/A/1.0/A-1.0.pom"))); assertTrue(Files.exists(destPath.resolve("org/apache/maven/A/1.0/A-1.0.war"))); assertTrue(Files.isRegularFile(destPath.resolve("org/apache/maven/A/1.0/A-1.0.war"))); assertTrue(Files.exists(destPath.resolve("org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar"))); assertTrue(Files.isRegularFile(destPath.resolve("org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar"))); assertTrue(Files.exists(destPath.resolve("KEYS"))); assertTrue(Files.isRegularFile(destPath.resolve("KEYS"))); assertTrue(Files.isDirectory(destPath.resolve("invalid"))); assertTrue(Files.isDirectory(destPath.resolve("javax"))); assertTrue(Files.isDirectory(destPath.resolve("org"))); } finally { org.apache.commons.io.FileUtils.deleteQuietly(destPath.toFile()); } }
public static void unzip(Path zipFile, Path destinationPath) throws IOException { try (ZipFile file = new ZipFile(zipFile.toFile())) { file.stream().forEach(e -> { try { if (e.isDirectory()) { Files.createDirectories(destinationPath.resolve(e.getName())); } else { unzipFileEntry(file, e, destinationPath); } } catch (IOException ex) { log.error("Error occured during unzip of zipFile={}, entry={}. Message: {}", zipFile, e.getName(), ex.getMessage()); } }); } }
FileUtils { public static void unzip(Path zipFile, Path destinationPath) throws IOException { try (ZipFile file = new ZipFile(zipFile.toFile())) { file.stream().forEach(e -> { try { if (e.isDirectory()) { Files.createDirectories(destinationPath.resolve(e.getName())); } else { unzipFileEntry(file, e, destinationPath); } } catch (IOException ex) { log.error("Error occured during unzip of zipFile={}, entry={}. Message: {}", zipFile, e.getName(), ex.getMessage()); } }); } } }
FileUtils { public static void unzip(Path zipFile, Path destinationPath) throws IOException { try (ZipFile file = new ZipFile(zipFile.toFile())) { file.stream().forEach(e -> { try { if (e.isDirectory()) { Files.createDirectories(destinationPath.resolve(e.getName())); } else { unzipFileEntry(file, e, destinationPath); } } catch (IOException ex) { log.error("Error occured during unzip of zipFile={}, entry={}. Message: {}", zipFile, e.getName(), ex.getMessage()); } }); } }  }
FileUtils { public static void unzip(Path zipFile, Path destinationPath) throws IOException { try (ZipFile file = new ZipFile(zipFile.toFile())) { file.stream().forEach(e -> { try { if (e.isDirectory()) { Files.createDirectories(destinationPath.resolve(e.getName())); } else { unzipFileEntry(file, e, destinationPath); } } catch (IOException ex) { log.error("Error occured during unzip of zipFile={}, entry={}. Message: {}", zipFile, e.getName(), ex.getMessage()); } }); } }  static void deleteQuietly(Path dir); static IOStatus deleteDirectoryWithStatus(Path dir); static void deleteDirectory(Path dir); static String readFileToString(Path file, Charset encoding); static void writeStringToFile(Path file, Charset encoding, String value); static String getBasedir(); Path resolveNonAbsolute(Path parent, String child); static void unzipFileEntry(ZipFile file, ZipEntry entry, Path destinationPath); static void unzip(Path zipFile, Path destinationPath); }
FileUtils { public static void unzip(Path zipFile, Path destinationPath) throws IOException { try (ZipFile file = new ZipFile(zipFile.toFile())) { file.stream().forEach(e -> { try { if (e.isDirectory()) { Files.createDirectories(destinationPath.resolve(e.getName())); } else { unzipFileEntry(file, e, destinationPath); } } catch (IOException ex) { log.error("Error occured during unzip of zipFile={}, entry={}. Message: {}", zipFile, e.getName(), ex.getMessage()); } }); } }  static void deleteQuietly(Path dir); static IOStatus deleteDirectoryWithStatus(Path dir); static void deleteDirectory(Path dir); static String readFileToString(Path file, Charset encoding); static void writeStringToFile(Path file, Charset encoding, String value); static String getBasedir(); Path resolveNonAbsolute(Path parent, String child); static void unzipFileEntry(ZipFile file, ZipEntry entry, Path destinationPath); static void unzip(Path zipFile, Path destinationPath);  }