Manifest

What the java.util.jar classes add to the superclasses in java.util.zip is the ability to read the attributes of each JAR entry as well as the manifest for the entire JAR archive. Recall that a JAR archive should have exactly one manifest file. That manifest file has entries that apply to the entire file as well as entries for some (though perhaps not all) of the files stored in the archive. Although physically the manifest file belongs to the entire archive, logically parts of it belong to different entries in the archive. The java.util.jar.Manifest class represents this manifest file.

public class Manifest extends Object implements Cloneable

It has methods to get the entries and attributes of a manifest, to write the manifest onto an output stream, or to read entries from an input stream, as well as an assortment of utility methods. The Manifest class has three constructors:

public Manifest( )
public Manifest(InputStream in) throws IOException
public Manifest(Manifest manifest)

The first constructor creates an empty manifest (one with no entries), the second reads the manifest from the given stream, and the third copies the manifest from the Manifest object passed as an argument. However, all three are mostly for the internal use of Java. Instead, client programmers use the getManifest( ) method of JarFile to retrieve the Manifest object for the manifest file in a particular archive. For example:

JarFile jf = new JarFile("classes.jar");
Manifest m = jf.getManifest( );

The Manifest class has three methods that return a map of the entries in the manifest. getEnTRies( ) returns a Map in which the keys are the entry names and the values are the Attributes objects for the entry:

public Map getEntries( )

Java 5 genericizes this method to specify that the keys are strings and the values are attributes:

public Map getEntries( )

The getMainAttributes( ) method returns an Attributes object representing the attributes in the manifest file that apply to the file as a whole rather than to any individual entry in the file, such as Manifest-Version:

public Attributes getMainAttributes( )

The getAttributes( ) method returns an Attributes object containing the name/value pairs of the named entry. The Name attribute is not included in this list:

public Attributes getAttributes(String entryName)

The clear( ) method (which client programmers have little reason to call) removes all entries and attributes from the manifest so that it can be reused:

public void clear( )

The Manifest class also contains methods to read a Manifest object from an input stream and write one onto an output stream. These methods are mostly for Java's private use:

public void write(OutputStream out) throws IOException
public void read(InputStream in) throws IOException

The write( ) method is particularly useless, since there's no good way to create a Manifest object and add attributes to it from within Java. I suppose you could write a manifest file on a byte array output stream, create a byte array input stream from the output stream's byte array, and read it back in, but that's really a kludge. Much more commonly, you'll simply work with Manifest objects returned by getManifest( ).

Basic I/O

Introducing I/O

Output Streams

Input Streams

Data Sources

File Streams

Network Streams

Filter Streams

Filter Streams

Print Streams

Data Streams

Streams in Memory

Compressing Streams

JAR Archives

Cryptographic Streams

Object Serialization

New I/O

Buffers

Channels

Nonblocking I/O

The File System

Working with Files

File Dialogs and Choosers

Text

Character Sets and Unicode

Readers and Writers

Formatted I/O with java.text

Devices

The Java Communications API

USB

The J2ME Generic Connection Framework

Bluetooth

Character Sets



Java I/O
Java I/O
ISBN: 0596527500
EAN: 2147483647
Year: 2004
Pages: 244

Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net