src/java.base/share/classes/java/util/jar/Attributes.java

Print this page
rev 13827 : 8151384: Examine sun.misc.ASCIICaseInsensitiveComparator
Reviewed-by:


  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 




  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 
  40 /**
  41  * The Attributes class maps Manifest attribute names to associated string
  42  * values. Valid attribute names are case-insensitive, are restricted to
  43  * the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed 70
  44  * characters in length. Attribute values can contain any characters and
  45  * will be UTF8-encoded when written to the output stream.  See the
  46  * <a href="../../../../technotes/guides/jar/jar.html">JAR File Specification</a>
  47  * for more information about valid attribute names and values.
  48  *
  49  * <p>This map and its views have a predictable iteration order, namely the
  50  * order that keys were inserted into the map, as with {@link LinkedHashMap}.
  51  *
  52  * @author  David Connelly
  53  * @see     Manifest
  54  * @since   1.2
  55  */
  56 public class Attributes implements Map<Object,Object>, Cloneable {
  57     /**
  58      * The attribute name-value mappings.


 483         private static boolean isValid(char c) {
 484             return isAlpha(c) || isDigit(c) || c == '_' || c == '-';
 485         }
 486 
 487         private static boolean isAlpha(char c) {
 488             return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
 489         }
 490 
 491         private static boolean isDigit(char c) {
 492             return c >= '0' && c <= '9';
 493         }
 494 
 495         /**
 496          * Compares this attribute name to another for equality.
 497          * @param o the object to compare
 498          * @return true if this attribute name is equal to the
 499          *         specified attribute object
 500          */
 501         public boolean equals(Object o) {
 502             if (o instanceof Name) {
 503                 Comparator<String> c = String.CASE_INSENSITIVE_ORDER;
 504                 return c.compare(name, ((Name)o).name) == 0;
 505             } else {
 506                 return false;
 507             }
 508         }
 509 
 510         /**
 511          * Computes the hash value for this attribute name.
 512          */
 513         public int hashCode() {
 514             if (hashCode == -1) {
 515                 hashCode = name.toLowerCase().hashCode();
 516             }
 517             return hashCode;
 518         }
 519 
 520         /**
 521          * Returns the attribute name as a String.
 522          */
 523         public String toString() {
 524             return name;
 525         }
 526 
 527         /**
 528          * {@code Name} object for {@code Manifest-Version}
 529          * manifest attribute. This attribute indicates the version number
 530          * of the manifest standard to which a JAR file's manifest conforms.
 531          * @see <a href="../../../../technotes/guides/jar/jar.html#JAR_Manifest">
 532          *      Manifest and Signature Specification</a>
 533          */
 534         public static final Name MANIFEST_VERSION = new Name("Manifest-Version");
 535