Compress { @Nonnull public static Path zip(final Path fileOrFolderToCompress) throws IOException { Path parent = fileOrFolderToCompress.getParent(); if (parent == null) { throw new IllegalArgumentException("Not a file: " + fileOrFolderToCompress); } Path destFile = parent.resolve(fileOrFolderToCompress.getFileName() + ".zip"); zip(fileOrFolderToCompress, destFile); return destFile; } private  Compress(); @Nonnull static Path zip(final Path fileOrFolderToCompress); @Nonnull static void zip(final Path fileOrFolderToCompress,
          final Path destFile); @Nonnull static void zip(final Path fileOrFolderToCompress,
          final Path destFile, final Predicate<Path> filter); static void copyFileAtomic(final Path source, final Path destinationFile); @Nonnull static List<Path> unzip(final Path zipFile); @Nonnull static List<Path> unzip(final Path zipFile, final Path destinationDirectory); @Nonnull static List<Path> unzip(final Path zipFile, final Path destinationDirectory,
          final Predicate<Path> filter); @Nonnull static List<Path> unzip2(final Path zipFile, final Path destinationDirectory); @Nonnull @SuppressFBWarnings("PATH_TRAVERSAL_IN") static List<Path> unzip2(final Path zipFile, final Path destDir,
          final Predicate<Path> filter);  }
@Test public void testZip() throws IOException { File tmpFolder = Files.createTempDir(); File file = File.createTempFile(".bla", ".tmp", tmpFolder); String testStr = "skjfghskjdhgfjgishfgksjhgjkhdskghsfdkjhg"; File subFolder = new File(file.getParent(), "subFolder"); if (!subFolder.mkdir()) { throw new IOException("Cannot create folder " + subFolder); } File subTestFile = new File(subFolder, "subTestFile.txt"); Files.asCharSink(file, StandardCharsets.UTF_8).write(testStr); Files.asCharSink(subTestFile, StandardCharsets.UTF_8).write(testStr); Path zip = Compress.zip(tmpFolder.toPath()); Assert.assertThat(zip.getFileName().toString(), Matchers.endsWith(".zip")); Assert.assertTrue(java.nio.file.Files.exists(zip)); File tmpFir = Files.createTempDir(); List<Path> unzip = Compress.unzip(zip, tmpFir.toPath()); Assert.assertEquals(2, unzip.size()); Assert.assertEquals(testStr, Files.asCharSource(unzip.get(0).toFile(), StandardCharsets.UTF_8).read()); Assert.assertEquals(testStr, Files.asCharSource(unzip.get(1).toFile(), StandardCharsets.UTF_8).read()); }