25.9.2. Archive Files java.util.jar
The java.util.jar package provides classes for reading and writing the JAR (Java ARchive) file format,
which is based on the standard ZIP file format with an optional manifest file. JAR files can be used to
distribute the classes and resources of a Package as a single unit. The manifest stores information about the
JAR file contents and provides the specification information for the Package contained thereinas we
discussed on page 477.
Archive files define a format for storing multiple files within a single file, and allow for the compression of
those original file contents. A full description of archive files, particularly the JAR format, is beyond the
scope of this book. For illustration we briefly describe each of the classes within the java.util.jar
package:
- Attributes maps Manifest attribute names to associated string values.
Attributes.Namerepresents an attribute's name. The main function of this class is to define static
Attributes.Name objects for each attribute that a manifest may have. For example, the object
corresponding to the "Manifest-Version" attribute of a manifest is stored in the static field
Attributes.Name.MANIFEST_VERSION.
•
- JarEntry represents a JAR file entry.
- JarFile represents an actual JAR file and allows that JAR file to be read or written.
JarInputStream reads a JAR file. Methods exist that read each entry of the JAR file into a new
JarEntry object.
•
JarOutputStream writes a JAR file. Methods exist that take a JarEntry object that is written
to the JAR file.
•
- Manifest maintains manifest entry names and their associated attributes.
A JarFile represents an actual JAR file and allows its contents to be read or written with the appropriate
streams. A JAR file consists of a manifest and a number of JAR entries that can be read or written
individually. The manifest contains all the attributes of the JAR file and all the attributes of the entries in the
JAR file. The manifest is decoded with the Manifest and Attributes classes. Each JarEntry
contains the per-entry attributes extracted from the manifest.
Most users never need to use the classes within java.util.jar. JAR files can be created via tools
supplied as part of your development environment and are read automatically by the class loader within the
virtual machine when needed.
25.9.3. ZIP Files java.util.zip
The java.util.zip package provides classes for reading and writing standard ZIP and GZIP file
formats. We mention it only for completeness, as it predates the newer JAR file format and forms its basis.
- ZipFile represents a ZIP or GZIP format file.
- ZipEntry represents an entry in a ZIP or GZIP format file.
- ZipInputStream reads ZIP file format.
- ZipOutputStream writes ZIP file format.
- GZIPInputStream reads GZIP file format.
- GZIPOutputStream writes GZIP file format.
- Deflater provides general support for using ZLIB compression.
- DeflaterOutputStream writes using ZLIB compression
- Inflater provides general support for using ZLIB decompression.
- InflaterInputStream reads ZLIB compressed data.
- CheckedInputStream reads a stream, creating a checksum of the data.
- CheckedOutputStream writes a stream, creating a checksum of the data.