Attributes

The java.util.jar.Attributes class is mostly just a concrete implementation of the java.util.Map interface from the Collections API.

public class Attributes implements Map, Cloneable

An Attributes object is a container for an entry in a manifest file. Recall that the entry is composed of name/value pairs; the keys of the map are the names and the values of the entries are the values of the map. The Attributes class is accessed almost entirely through the methods of the Map interface and has three public constructors:

public Attributes( )
public Attributes(int size)
public Attributes(Attributes a)

However, these constructors are primarily for Java's internal use. Most of the time, you'll simply retrieve Attributes objects from the getAttributes( ) method of JarEntry or the getAttributes( ) and getMainAttributes( ) methods of Manifest.

The keys for this map should all be Attributes.Name objects. Attributes.Name is a public inner class called Name inside the Attributes class. However, it's simplest to just think of it as another class in java.util.jar with a somewhat funny name. This class has a single constructor:

public Attributes.Name(String name)

The Attributes.Name class represents the name half of the name/value pairs in a manifest file. Attribute names are restricted to the upper- and lowercase letters AZ, the digits 09, the underscore, and the hyphen. The Attributes.Name( ) constructor checks to make sure that the name is legal and throws an IllegalArgumentException if it isn't.

Attributes.Name overrides the equals( ), hashCode( ), and toString( ) methods but has no other methods. It exists only to be a key in the Attributes map.

The Attributes.Name class defines some mnemonic constants that identify particular attribute names found in some kinds of JAR files. These are all Attributes.Name objects:

The last one takes an Attributes.Name object as an argument. Example 11-1 is a revised version of the FancyZipLister from Example 10-9. This program works with JAR files and prints the attributes of each entry as well as the information seen previously.