IncrementalRelativeFileSets { @NonNull public static ImmutableMap<RelativeFile, FileStatus> fromZip(@NonNull File zip) throws IOException { return fromZip(zip, FileStatus.NEW); } private  IncrementalRelativeFileSets(); @NonNull static ImmutableMap<RelativeFile, FileStatus> fromDirectory(@NonNull File directory); @NonNull static ImmutableMap<RelativeFile, FileStatus> fromZip(@NonNull File zip); @NonNull static ImmutableMap<RelativeFile, FileStatus> fromZip(@NonNull File zip,
            FileStatus status); @NonNull static ImmutableMap<RelativeFile, FileStatus> fromZip(@NonNull File zip,
            @NonNull FileCacheByPath cache); @NonNull static ImmutableMap<RelativeFile, FileStatus> union(
            @NonNull Iterable<ImmutableMap<RelativeFile, FileStatus>> sets); static int getBaseDirectoryCount(@NonNull ImmutableMap<RelativeFile, FileStatus> set); @NonNull static ImmutableMap<RelativeFile, FileStatus> fromZipsAndDirectories(
            @NonNull Iterable<File> files); @NonNull static ImmutableMap<RelativeFile, FileStatus> makeFromBaseFiles(
            @NonNull Collection<File> baseFiles,
            @NonNull Map<File, FileStatus> updates,
            @NonNull FileCacheByPath cache);  }
@Test public void readEmptyZip() throws Exception { File zipFile = new File(mTemporaryFolder.getRoot(), "foo"); Closer closer = Closer.create(); try { ZFile zf = closer.register(new ZFile(zipFile)); zf.close(); } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } ImmutableMap<RelativeFile, FileStatus> set = IncrementalRelativeFileSets.fromZip(zipFile); assertEquals(0, set.size()); }
@Test public void readZip() throws Exception { File zipFile = new File(mTemporaryFolder.getRoot(), "foo"); RelativeFile expectedB = new RelativeFile(zipFile, new File(zipFile, "a" + File.separator + "b")); RelativeFile expectedC = new RelativeFile(zipFile, new File(zipFile, "a" + File.separator + "c")); RelativeFile expectedD = new RelativeFile(zipFile, new File(zipFile, "d")); Closer closer = Closer.create(); try { ZFile zf = closer.register(new ZFile(zipFile)); zf.add("a/", new ByteArrayInputStream(new byte[0])); zf.add("a/b", new ByteArrayInputStream(new byte[0])); zf.add("a/c", new ByteArrayInputStream(new byte[0])); zf.add("d", new ByteArrayInputStream(new byte[0])); zf.close(); } catch (Throwable t) { throw closer.rethrow(t); } finally { closer.close(); } ImmutableMap<RelativeFile, FileStatus> set = IncrementalRelativeFileSets.fromZip(zipFile); assertEquals(3, set.size()); assertTrue(set.containsKey(expectedB)); assertTrue(set.containsKey(expectedC)); assertTrue(set.containsKey(expectedD)); assertEquals(FileStatus.NEW, set.get(expectedB)); assertEquals(FileStatus.NEW, set.get(expectedC)); assertEquals(FileStatus.NEW, set.get(expectedD)); }