23.07.2013 Views

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Java</strong> I/O<br />

The getAttributes() method returns the attributes for this entry as documented in the<br />

manifest file of the archive. In brief, an Attributes object is a map of the name/value pairs<br />

for the entry. This will be discussed further in the next section. The getCertificates()<br />

method returns an array of java.security. cert.Certificate objects formed from any<br />

signature files for this entry stored in the archive. These can be used to allow some classes<br />

more access to the system than they would normally get. I won't go into this possibility here;<br />

the details are available in <strong>Java</strong> Security.<br />

9.5.6 Attributes<br />

The java.util.jar.Attributes class is mostly just a concrete implementation of the<br />

java.util.Map interface from the Collections API.<br />

public class Attributes implements Map, Cloneable // <strong>Java</strong> 2<br />

An Attributes object is a container for an entry in a manifest file. Recall that the entry is<br />

composed of name/value pairs; the keys of the map are the names, while the values of the<br />

entries are the values of the map. The Attributes class is accessed almost entirely through<br />

the methods of the Map interface and has three public constructors:<br />

public Attributes() // <strong>Java</strong> 2<br />

public Attributes(int size) // <strong>Java</strong> 2<br />

public Attributes(Attributes a) // <strong>Java</strong> 2<br />

However, these are primarily for <strong>Java</strong>'s internal use. Most of the time, you'll simply retrieve<br />

Attributes objects from the getAttributes() method of JarEntry or the<br />

getAttributes() and getMainAttributes() method of Manifest.<br />

The Attributes class implements all the usual Map methods:<br />

public Object get(Object name) // <strong>Java</strong> 2<br />

public Object put(Object name, Object value) // <strong>Java</strong> 2<br />

public Object remove(Object name) // <strong>Java</strong> 2<br />

public boolean containsValue(Object value) // <strong>Java</strong> 2<br />

public boolean containsKey(Object name) // <strong>Java</strong> 2<br />

public void putAll(Map attr) // <strong>Java</strong> 2<br />

public void clear() // <strong>Java</strong> 2<br />

public int size() // <strong>Java</strong> 2<br />

public boolean isEmpty() // <strong>Java</strong> 2<br />

public Set keySet() // <strong>Java</strong> 2<br />

public Collection values() // <strong>Java</strong> 2<br />

public Set entrySet() // <strong>Java</strong> 2<br />

public boolean equals(Object o) // <strong>Java</strong> 2<br />

public int hashCode() // <strong>Java</strong> 2<br />

The key objects for this map should all be Attributes.Name objects. Attributes.Name is a<br />

rare public inner class called Name inside the Attributes class. However, it's simplest to just<br />

think of it as another class in java.util.jar with a somewhat funny name. This strangely<br />

named class has a single constructor:<br />

public Attributes.Name(String name) // <strong>Java</strong> 2<br />

182

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!