ZFile implements Closeable { @NonNull public Set<StoredEntry> entries() { Map<String, StoredEntry> entries = Maps.newHashMap(); for (FileUseMapEntry<StoredEntry> mapEntry : mEntries.values()) { StoredEntry entry = mapEntry.getStore(); assert entry != null; entries.put(entry.getCentralDirectoryHeader().getName(), entry); } for (StoredEntry uncompressed : mUncompressedEntries) { entries.put(uncompressed.getCentralDirectoryHeader().getName(), uncompressed); } return Sets.newHashSet(entries.values()); } ZFile(@NonNull File file);  ZFile(@NonNull File file, @NonNull ZFileOptions options); @NonNull Set<StoredEntry> entries(); @Nullable StoredEntry get(@NonNull String path); @NonNull InputStream directOpen(final long start, final long end); void update(); @Override void close(); @NonNull byte[] getCentralDirectoryBytes(); @NonNull byte[] getEocdBytes(); void openReadOnly(); void add(@NonNull String name, @NonNull InputStream stream); void add(@NonNull String name, @NonNull InputStream stream, boolean mayCompress); void mergeFrom(@NonNull ZFile src, @NonNull Predicate<String> ignoreFilter); void touch(); void finishAllBackgroundTasks(); boolean realign(); void addZFileExtension(@NonNull ZFileExtension extension); void removeZFileExtension(@NonNull ZFileExtension extension); void directWrite(long offset, @NonNull byte[] data, int start, int count); void directWrite(long offset, @NonNull byte[] data); int directRead(long offset, @NonNull byte[] data, int start, int count); int directRead(long offset, @NonNull byte[] data); void directFullyRead(long offset, @NonNull byte[] data); void addAllRecursively(@NonNull File file); void addAllRecursively(@NonNull File file,
            @NonNull Function<? super File, Boolean> mayCompress); long getCentralDirectoryOffset(); long getCentralDirectorySize(); long getEocdOffset(); long getEocdSize(); void setExtraDirectoryOffset(long offset); long getExtraDirectoryOffset(); boolean areTimestampsIgnored(); void sortZipContents(); @NonNull File getFile(); static final char SEPARATOR; }
@Test public void readOnlyZipSupport() throws Exception { File testZip = ZipTestUtils.cloneRsrc("empty-zip.zip", mTemporaryFolder); assertTrue(testZip.setWritable(false)); try (ZFile zf = new ZFile(testZip)) { assertEquals(1, zf.entries().size()); } }
@Test public void java7JarSupported() throws Exception { File jar = ZipTestUtils.cloneRsrc("j7.jar", mTemporaryFolder); try (ZFile j = new ZFile(jar)) { assertEquals(8, j.entries().size()); } }
@Test public void java8JarSupported() throws Exception { File jar = ZipTestUtils.cloneRsrc("j8.jar", mTemporaryFolder); try (ZFile j = new ZFile(jar)) { assertEquals(8, j.entries().size()); } }
@Test public void utf8NamesSupportedOnReading() throws Exception { File zip = ZipTestUtils.cloneRsrc("zip-with-utf8-filename.zip", mTemporaryFolder); try (ZFile f = new ZFile(zip)) { assertEquals(1, f.entries().size()); StoredEntry entry = f.entries().iterator().next(); String filetMignonKorean = "\uc548\uc2eC \uc694\ub9ac"; String isGoodJapanese = "\u3068\u3066\u3082\u826f\u3044"; assertEquals( filetMignonKorean + " " + isGoodJapanese, entry.getCentralDirectoryHeader().getName()); assertArrayEquals( "Stuff about food is good.\n".getBytes(Charsets.US_ASCII), entry.read()); } }