Zipper implements AutoCloseable { public void addToZip(byte[] bytes, String destFilename) throws IOException { zip.putNextEntry(new ZipEntry(destFilename)); zip.write(bytes); zip.closeEntry(); } Zipper(OutputStream destStream); void addToZip(byte[] bytes, String destFilename); void addToZip(Path path, String destFilename); void addDirectoryToZip(final Path sourceDirectory,
                                  final PathPredicate directoryPredicate,
                                  final FilePredicate filePredicate,
                                  final String destinationDirectoryName); void close(); static final PathPredicate ALL_DIRECTORIES; static final FilePredicate ALL_FILES; }
@Test public void should_zip_some_bytes() throws Exception { byte[] foo = "foobar".getBytes(StandardCharsets.UTF_8); zipper.addToZip(foo, "foo.txt"); Path dest = unzip(out); assertThat(dest.resolve("foo.txt").toFile()).exists(); assertThat(dest.resolve("foo.txt").toFile()).usingCharset(StandardCharsets.UTF_8).hasContent("foobar"); }