17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.util.jar;
27
28 import java.io.DataInputStream;
29 import java.io.DataOutputStream;
30 import java.io.IOException;
31 import java.util.LinkedHashMap;
32 import java.util.Map;
33 import java.util.Set;
34 import java.util.Collection;
35 import java.util.AbstractSet;
36 import java.util.Iterator;
37 import sun.util.logging.PlatformLogger;
38 import java.util.Comparator;
39 import sun.misc.ASCIICaseInsensitiveComparator;
40
41 /**
42 * The Attributes class maps Manifest attribute names to associated string
43 * values. Valid attribute names are case-insensitive, are restricted to
44 * the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed 70
45 * characters in length. Attribute values can contain any characters and
46 * will be UTF8-encoded when written to the output stream. See the
47 * <a href="../../../../technotes/guides/jar/jar.html">JAR File Specification</a>
48 * for more information about valid attribute names and values.
49 *
50 * <p>This map and its views have a predictable iteration order, namely the
51 * order that keys were inserted into the map, as with {@link LinkedHashMap}.
52 *
53 * @author David Connelly
54 * @see Manifest
55 * @since 1.2
56 */
57 public class Attributes implements Map<Object,Object>, Cloneable {
58 /**
59 * The attribute name-value mappings.
484 private static boolean isValid(char c) {
485 return isAlpha(c) || isDigit(c) || c == '_' || c == '-';
486 }
487
488 private static boolean isAlpha(char c) {
489 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
490 }
491
492 private static boolean isDigit(char c) {
493 return c >= '0' && c <= '9';
494 }
495
496 /**
497 * Compares this attribute name to another for equality.
498 * @param o the object to compare
499 * @return true if this attribute name is equal to the
500 * specified attribute object
501 */
502 public boolean equals(Object o) {
503 if (o instanceof Name) {
504 Comparator<String> c = ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER;
505 return c.compare(name, ((Name)o).name) == 0;
506 } else {
507 return false;
508 }
509 }
510
511 /**
512 * Computes the hash value for this attribute name.
513 */
514 public int hashCode() {
515 if (hashCode == -1) {
516 hashCode = ASCIICaseInsensitiveComparator.lowerCaseHashCode(name);
517 }
518 return hashCode;
519 }
520
521 /**
522 * Returns the attribute name as a String.
523 */
524 public String toString() {
525 return name;
526 }
527
528 /**
529 * {@code Name} object for {@code Manifest-Version}
530 * manifest attribute. This attribute indicates the version number
531 * of the manifest standard to which a JAR file's manifest conforms.
532 * @see <a href="../../../../technotes/guides/jar/jar.html#JAR_Manifest">
533 * Manifest and Signature Specification</a>
534 */
535 public static final Name MANIFEST_VERSION = new Name("Manifest-Version");
536
|
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.util.jar;
27
28 import java.io.DataInputStream;
29 import java.io.DataOutputStream;
30 import java.io.IOException;
31 import java.util.LinkedHashMap;
32 import java.util.Map;
33 import java.util.Set;
34 import java.util.Collection;
35 import java.util.AbstractSet;
36 import java.util.Iterator;
37 import java.util.Locale;
38 import sun.util.logging.PlatformLogger;
39 import java.util.Comparator;
40
41 /**
42 * The Attributes class maps Manifest attribute names to associated string
43 * values. Valid attribute names are case-insensitive, are restricted to
44 * the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed 70
45 * characters in length. Attribute values can contain any characters and
46 * will be UTF8-encoded when written to the output stream. See the
47 * <a href="../../../../technotes/guides/jar/jar.html">JAR File Specification</a>
48 * for more information about valid attribute names and values.
49 *
50 * <p>This map and its views have a predictable iteration order, namely the
51 * order that keys were inserted into the map, as with {@link LinkedHashMap}.
52 *
53 * @author David Connelly
54 * @see Manifest
55 * @since 1.2
56 */
57 public class Attributes implements Map<Object,Object>, Cloneable {
58 /**
59 * The attribute name-value mappings.
484 private static boolean isValid(char c) {
485 return isAlpha(c) || isDigit(c) || c == '_' || c == '-';
486 }
487
488 private static boolean isAlpha(char c) {
489 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
490 }
491
492 private static boolean isDigit(char c) {
493 return c >= '0' && c <= '9';
494 }
495
496 /**
497 * Compares this attribute name to another for equality.
498 * @param o the object to compare
499 * @return true if this attribute name is equal to the
500 * specified attribute object
501 */
502 public boolean equals(Object o) {
503 if (o instanceof Name) {
504 Comparator<String> c = String.CASE_INSENSITIVE_ORDER;
505 return c.compare(name, ((Name)o).name) == 0;
506 } else {
507 return false;
508 }
509 }
510
511 /**
512 * Computes the hash value for this attribute name.
513 */
514 public int hashCode() {
515 if (hashCode == -1) {
516 hashCode = name.toLowerCase(Locale.ROOT).hashCode();
517 }
518 return hashCode;
519 }
520
521 /**
522 * Returns the attribute name as a String.
523 */
524 public String toString() {
525 return name;
526 }
527
528 /**
529 * {@code Name} object for {@code Manifest-Version}
530 * manifest attribute. This attribute indicates the version number
531 * of the manifest standard to which a JAR file's manifest conforms.
532 * @see <a href="../../../../technotes/guides/jar/jar.html#JAR_Manifest">
533 * Manifest and Signature Specification</a>
534 */
535 public static final Name MANIFEST_VERSION = new Name("Manifest-Version");
536
|