ZipFiles { static ByteSource asByteSource(ZipFile file, ZipEntry entry) { return new ZipEntryByteSource(file, entry); } private  ZipFiles(); static void zipDirectory(File sourceDirectory, File zipFile); static void zipDirectory(File sourceDirectory, OutputStream outputStream);  }
@Test public void testAsByteSource() throws Exception { File zipDir = new File(tmpDir, "zip"); assertTrue(zipDir.mkdirs()); createFileWithContents(zipDir, "myTextFile.txt", "Simple Text"); ZipFiles.zipDirectory(tmpDir, zipFile); try (ZipFile zip = new ZipFile(zipFile)) { ZipEntry entry = zip.getEntry("zip/myTextFile.txt"); ByteSource byteSource = ZipFiles.asByteSource(zip, entry); if (entry.getSize() != -1) { assertEquals(entry.getSize(), byteSource.size()); } assertArrayEquals("Simple Text".getBytes(StandardCharsets.UTF_8), byteSource.read()); } }