Method from java.util.jar.Attributes Detail: |
public void clear() {
map.clear();
}
Removes all attributes from this Map. |
public Object clone() {
return new Attributes(this);
}
Returns a copy of the Attributes, implemented as follows:
public Object clone() { return new Attributes(this); }
Since the attribute names and values are themselves immutable,
the Attributes returned can be safely modified without affecting
the original. |
public boolean containsKey(Object name) {
return map.containsKey(name);
}
Returns true if this Map contains the specified attribute name (key). |
public boolean containsValue(Object value) {
return map.containsValue(value);
}
Returns true if this Map maps one or more attribute names (keys)
to the specified value. |
public Set<Object, Object> entrySet() {
return map.entrySet();
}
Returns a Collection view of the attribute name-value mappings
contained in this Map. |
public boolean equals(Object o) {
return map.equals(o);
}
Compares the specified Attributes object with this Map for equality.
Returns true if the given object is also an instance of Attributes
and the two Attributes objects represent the same mappings. |
public Object get(Object name) {
return map.get(name);
}
Returns the value of the specified attribute name, or null if the
attribute name was not found. |
public String getValue(String name) {
return (String)get(new Attributes.Name(name));
}
return (String)get(new Attributes.Name((String)name));
|
public String getValue(Name name) {
return (String)get(name);
}
return (String)get(name);
|
public int hashCode() {
return map.hashCode();
}
Returns the hash code value for this Map. |
public boolean isEmpty() {
return map.isEmpty();
}
Returns true if this Map contains no attributes. |
public Set<Object> keySet() {
return map.keySet();
}
Returns a Set view of the attribute names (keys) contained in this Map. |
public Object put(Object name,
Object value) {
return map.put((Attributes.Name)name, (String)value);
}
Associates the specified value with the specified attribute name
(key) in this Map. If the Map previously contained a mapping for
the attribute name, the old value is replaced. |
public void putAll(Map<?, ?> attr) {
// ## javac bug?
if (!Attributes.class.isInstance(attr))
throw new ClassCastException();
for (Map.Entry< ?,? > me : (attr).entrySet())
put(me.getKey(), me.getValue());
}
Copies all of the attribute name-value mappings from the specified
Attributes to this Map. Duplicate mappings will be replaced. |
public String putValue(String name,
String value) {
return (String)put(new Name(name), value);
}
return (String)put(new Attributes.Name(name), value);
|
void read(FastInputStream is,
byte[] lbuf) throws IOException {
String name = null, value = null;
byte[] lastline = null;
int len;
while ((len = is.readLine(lbuf)) != -1) {
boolean lineContinued = false;
if (lbuf[--len] != '\n') {
throw new IOException("line too long");
}
if (len > 0 && lbuf[len-1] == '\r') {
--len;
}
if (len == 0) {
break;
}
int i = 0;
if (lbuf[0] == ' ') {
// continuation of previous line
if (name == null) {
throw new IOException("misplaced continuation line");
}
lineContinued = true;
byte[] buf = new byte[lastline.length + len - 1];
System.arraycopy(lastline, 0, buf, 0, lastline.length);
System.arraycopy(lbuf, 1, buf, lastline.length, len - 1);
if (is.peek() == ' ') {
lastline = buf;
continue;
}
value = new String(buf, 0, buf.length, "UTF8");
lastline = null;
} else {
while (lbuf[i++] != ':') {
if (i >= len) {
throw new IOException("invalid header field");
}
}
if (lbuf[i++] != ' ') {
throw new IOException("invalid header field");
}
name = new String(lbuf, 0, 0, i - 2);
if (is.peek() == ' ') {
lastline = new byte[len - i];
System.arraycopy(lbuf, i, lastline, 0, len - i);
continue;
}
value = new String(lbuf, i, len - i, "UTF8");
}
try {
if ((putValue(name, value) != null) && (!lineContinued)) {
PlatformLogger.getLogger("java.util.jar").warning(
"Duplicate name in Manifest: " + name
+ ".\n"
+ "Ensure that the manifest does not "
+ "have duplicate entries, and\n"
+ "that blank lines separate "
+ "individual sections in both your\n"
+ "manifest and in the META-INF/MANIFEST.MF "
+ "entry in the jar file.");
}
} catch (IllegalArgumentException e) {
throw new IOException("invalid header field name: " + name);
}
}
}
|
public Object remove(Object name) {
return map.remove(name);
}
Removes the attribute with the specified name (key) from this Map.
Returns the previous attribute value, or null if none. |
public int size() {
return map.size();
}
Returns the number of attributes in this Map. |
public Collection<Object> values() {
return map.values();
}
Returns a Collection view of the attribute values contained in this Map. |
void write(DataOutputStream os) throws IOException {
Iterator it = entrySet().iterator();
while (it.hasNext()) {
Map.Entry e = (Map.Entry)it.next();
StringBuffer buffer = new StringBuffer(
((Name)e.getKey()).toString());
buffer.append(": ");
String value = (String)e.getValue();
if (value != null) {
byte[] vb = value.getBytes("UTF8");
value = new String(vb, 0, 0, vb.length);
}
buffer.append(value);
buffer.append("\r\n");
Manifest.make72Safe(buffer);
os.writeBytes(buffer.toString());
}
os.writeBytes("\r\n");
}
|
void writeMain(DataOutputStream out) throws IOException {
// write out the *-Version header first, if it exists
String vername = Name.MANIFEST_VERSION.toString();
String version = getValue(vername);
if (version == null) {
vername = Name.SIGNATURE_VERSION.toString();
version = getValue(vername);
}
if (version != null) {
out.writeBytes(vername+": "+version+"\r\n");
}
// write out all attributes except for the version
// we wrote out earlier
Iterator it = entrySet().iterator();
while (it.hasNext()) {
Map.Entry e = (Map.Entry)it.next();
String name = ((Name)e.getKey()).toString();
if ((version != null) && ! (name.equalsIgnoreCase(vername))) {
StringBuffer buffer = new StringBuffer(name);
buffer.append(": ");
String value = (String)e.getValue();
if (value != null) {
byte[] vb = value.getBytes("UTF8");
value = new String(vb, 0, 0, vb.length);
}
buffer.append(value);
buffer.append("\r\n");
Manifest.make72Safe(buffer);
out.writeBytes(buffer.toString());
}
}
out.writeBytes("\r\n");
}
|