ZipFiles { @SuppressWarnings("unchecked") static FluentIterable<ZipEntry> entries(final ZipFile file) { checkNotNull(file); return new FluentIterable<ZipEntry>() { @Override public Iterator<ZipEntry> iterator() { return (Iterator<ZipEntry>) Iterators.forEnumeration(file.entries()); } }; } private  ZipFiles(); static void zipDirectory(File sourceDirectory, File zipFile); static void zipDirectory(File sourceDirectory, OutputStream outputStream);  }
@Test public void testEntries() throws Exception { File zipDir = new File(tmpDir, "zip"); File subDir1 = new File(zipDir, "subDir1"); File subDir2 = new File(subDir1, "subdir2"); assertTrue(subDir2.mkdirs()); createFileWithContents(subDir2, "myTextFile.txt", "Simple Text"); ZipFiles.zipDirectory(tmpDir, zipFile); try (ZipFile zip = new ZipFile(zipFile)) { Enumeration<? extends ZipEntry> entries = zip.entries(); for (ZipEntry entry : ZipFiles.entries(zip)) { assertTrue(entries.hasMoreElements()); assertEquals(entry.getName(), entries.nextElement().getName()); } assertFalse(entries.hasMoreElements()); } }