Top Description Inners Fields Constructors Methods
java.util.zip

public Class ZipFile

extends Object
implements ZipConstants, Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable, java.util.zip.ZipConstants
Known Direct Subclasses
java.util.jar.JarFile
Imports
java.io.Closeable, .InputStream, .IOException, .EOFException, .File, .RandomAccessFile, .UncheckedIOException, java.lang.ref.Cleaner.Cleanable, java.nio.charset.Charset, java.nio.file.InvalidPathException, .Files, java.nio.file.attribute.BasicFileAttributes, java.util.ArrayDeque, .ArrayList, .Arrays, .Collections, .Deque, .Enumeration, .HashMap, .Iterator, .List, .Locale, .Objects, .NoSuchElementException, .Set, .Spliterator, .Spliterators, .TreeSet, .WeakHashMap, java.util.function.Consumer, .IntFunction, java.util.jar.JarEntry, .JarFile, java.util.stream.Stream, .StreamSupport, jdk.internal.access.JavaUtilZipFileAccess, .JavaUtilJarAccess, .SharedSecrets, jdk.internal.util.OperatingSystem, jdk.internal.perf.PerfCounter, jdk.internal.ref.CleanerFactory, jdk.internal.vm.annotation.Stable, sun.nio.cs.UTF_8, sun.nio.fs.DefaultFileSystemProvider, sun.security.action.GetPropertyAction, sun.security.util.SignatureFileVerifier

This class is used to read entries from a ZIP file.

Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.

API Note

To release resources used by this ZipFile, the close() method should be called explicitly or by try-with-resources. Subclasses are responsible for the cleanup of resources acquired by the subclass. Subclasses that override finalize() in order to perform cleanup should be modified to use alternative cleanup mechanisms such as java.lang.ref.Cleaner and remove the overriding finalize method.

Author
David Connelly
Since
1.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private class
private static class
private static class
private class
private class
private class

Field Summary

Modifier and TypeField and Description
private volatile boolean
private static final int
private static final boolean
DISABLE_ZIP64_EXTRA_VALIDATION

Flag to specify whether the Extra ZIP64 validation should be disabled.

private final String
private final String
private String
private int
public static final int
OPEN_DELETE

Mode flag to open a ZIP file and mark it for deletion.

public static final int
OPEN_READ

Mode flag to open a ZIP file for reading.

private final ZipFile.CleanableResource
private static final int

Constructor Summary

AccessConstructor and Description
public
ZipFile(String
the name of the ZIP file
name
)

Opens a ZIP file for reading.

public
ZipFile(File
the ZIP file to be opened for reading
file
,
int
the mode in which the file is to be opened
mode
)

Opens a new ZipFile to read from the specified File object in the specified mode.

public
ZipFile(File
the ZIP file to be opened for reading
file
)

Opens a ZIP file for reading given the specified File object.

public
ZipFile(File
the ZIP file to be opened for reading
file
,
int
the mode in which the file is to be opened
mode
,
Charset
the charset to be used to decode the ZIP entry name and comment that are not encoded by using UTF-8 encoding (indicated by entry's general purpose flag).
charset
)

Opens a new ZipFile to read from the specified File object in the specified mode.

public
ZipFile(String
the name of the ZIP file
name
,
Charset
the charset to be used to decode the ZIP entry name and comment that are not encoded by using UTF-8 encoding (indicated by entry's general purpose flag).
charset
)

Opens a ZIP file for reading.

public
ZipFile(File
the ZIP file to be opened for reading
file
,
Charset
The charset to be used to decode the ZIP entry name and comment (ignored if the language encoding bit of the ZIP entry's general purpose bit flag is set).
charset
)

Opens a ZIP file for reading given the specified File object.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes the ZIP file.

private void
private void
public Enumeration<? extends ZipEntry>

Returns:

an enumeration of the ZIP file entries
entries
()

Returns an enumeration of the ZIP file entries.

private Stream<String>
public String

Returns:

the comment string for the ZIP file, or null if none
getComment
()

Returns the ZIP file comment.

pack-priv static boolean
getDisableZip64ExtraFieldValidation()

Returns the value of the System property which indicates whether the Extra ZIP64 validation should be disabled.

public ZipEntry

Returns:

the ZIP file entry, or null if not found
getEntry
(String
the name of the entry
name
)

Returns the ZIP file entry for the specified name, or null if not found.

private String
getEntryName(int pos)

public InputStream

Returns:

the input stream for reading the contents of the specified ZIP file entry or null if the ZIP file entry does not exist within the ZIP file.
getInputStream
(ZipEntry
the ZIP file entry
entry
)

Returns an input stream for reading the contents of the specified ZIP file entry.

private List<String>
getManifestAndSignatureRelatedFiles()

Returns the names of the META-INF/MANIFEST.MF entry - if exists - and any signature-related files under META-INF.

private String
getManifestName(boolean onlyIfSignatureRelatedFiles)

Returns the name of the META-INF/MANIFEST.MF entry, ignoring case.

private int
getManifestNum()

Returns the number of the META-INF/MANIFEST.MF entries, case insensitive.

private int[]
getMetaInfVersions()

Returns the versions for which there exists a non-directory entry that begin with "META-INF/versions/" (case ignored).

public String

Returns:

the path name of the ZIP file
getName
()

Returns the path name of the ZIP file.

private ZipEntry
getZipEntry(String name, int pos)

private Enumeration<JarEntry>
private Stream<JarEntry>
public int

Returns:

the number of entries in the ZIP file
size
()

Returns the number of entries in the ZIP file.

public Stream<? extends ZipEntry>

Returns:

an ordered Stream of entries in this ZIP file
stream
()

Returns an ordered Stream over the ZIP file entries.

public String

Returns:

a string identifying this ZipFile, for debugging
toString
()

Overrides java.lang.Object.toString.

Returns a string identifying this ZipFile, for debugging.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait