jdk/src/share/classes/java/util/jar/Attributes.java
author psandoz
Fri, 20 Dec 2013 13:38:13 +0100
changeset 22078 bdec5d53e98c
parent 19409 d7c7b9d56631
permissions -rw-r--r--
8030851: Update code in java.util to use newer language features Reviewed-by: dfuchs, briangoetz, chegar, alanb, mduigou
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19047
08210fe86260 8021408: Fix misc doclint issues in java.util and java.io
darcy
parents: 15682
diff changeset
     2
 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.util.jar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.DataInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.DataOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.AbstractSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Iterator;
3861
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 2
diff changeset
    37
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Comparator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.misc.ASCIICaseInsensitiveComparator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The Attributes class maps Manifest attribute names to associated string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * values. Valid attribute names are case-insensitive, are restricted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed 70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * characters in length. Attribute values can contain any characters and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * will be UTF8-encoded when written to the output stream.  See the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <a href="../../../../technotes/guides/jar/jar.html">JAR File Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * for more information about valid attribute names and values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author  David Connelly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @see     Manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @since   1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public class Attributes implements Map<Object,Object>, Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * The attribute name-value mappings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    protected Map<Object,Object> map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Constructs a new, empty Attributes object with default size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public Attributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        this(11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Constructs a new, empty Attributes object with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * initial size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param size the initial number of attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public Attributes(int size) {
11841
38a39c748880 7143230: fix warnings in java.util.jar, sun.tools.jar, zipfs demo, etc.
smarks
parents: 11016
diff changeset
    74
        map = new HashMap<>(size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Constructs a new Attributes object with the same attribute name-value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * mappings as in the specified Attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param attr the specified Attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public Attributes(Attributes attr) {
11841
38a39c748880 7143230: fix warnings in java.util.jar, sun.tools.jar, zipfs demo, etc.
smarks
parents: 11016
diff changeset
    84
        map = new HashMap<>(attr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Returns the value of the specified attribute name, or null if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * attribute name was not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param name the attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @return the value of the specified attribute name, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *         not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public Object get(Object name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return map.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Returns the value of the specified attribute name, specified as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * a string, or null if the attribute was not found. The attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * name is case-insensitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * This method is defined as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *      return (String)get(new Attributes.Name((String)name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param name the attribute name as a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @return the String value of the specified attribute name, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *         not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @throws IllegalArgumentException if the attribute name is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public String getValue(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return (String)get(new Attributes.Name(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Returns the value of the specified Attributes.Name, or null if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * attribute was not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * This method is defined as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *     return (String)get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param name the Attributes.Name object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @return the String value of the specified Attribute.Name, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *         not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public String getValue(Name name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        return (String)get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Associates the specified value with the specified attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * (key) in this Map. If the Map previously contained a mapping for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * the attribute name, the old value is replaced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param name the attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param value the attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @return the previous value of the attribute, or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @exception ClassCastException if the name is not a Attributes.Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *            or the value is not a String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public Object put(Object name, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return map.put((Attributes.Name)name, (String)value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Associates the specified value with the specified attribute name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * specified as a String. The attributes name is case-insensitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * If the Map previously contained a mapping for the attribute name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * the old value is replaced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * This method is defined as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *      return (String)put(new Attributes.Name(name), value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param name the attribute name as a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param value the attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return the previous value of the attribute, or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @exception IllegalArgumentException if the attribute name is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public String putValue(String name, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return (String)put(new Name(name), value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Removes the attribute with the specified name (key) from this Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Returns the previous attribute value, or null if none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param name attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @return the previous value of the attribute, or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public Object remove(Object name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        return map.remove(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Returns true if this Map maps one or more attribute names (keys)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param value the attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @return true if this Map maps one or more attribute names to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *         the specified value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public boolean containsValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        return map.containsValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Returns true if this Map contains the specified attribute name (key).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param name the attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @return true if this Map contains the specified attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public boolean containsKey(Object name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return map.containsKey(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Copies all of the attribute name-value mappings from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Attributes to this Map. Duplicate mappings will be replaced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @param attr the Attributes to be stored in this map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @exception ClassCastException if attr is not an Attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public void putAll(Map<?,?> attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // ## javac bug?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        if (!Attributes.class.isInstance(attr))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            throw new ClassCastException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        for (Map.Entry<?,?> me : (attr).entrySet())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            put(me.getKey(), me.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Removes all attributes from this Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        map.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Returns the number of attributes in this Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return map.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Returns true if this Map contains no attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return map.isEmpty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Returns a Set view of the attribute names (keys) contained in this Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public Set<Object> keySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return map.keySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Returns a Collection view of the attribute values contained in this Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public Collection<Object> values() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return map.values();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Returns a Collection view of the attribute name-value mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * contained in this Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public Set<Map.Entry<Object,Object>> entrySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return map.entrySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Compares the specified Attributes object with this Map for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Returns true if the given object is also an instance of Attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * and the two Attributes objects represent the same mappings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param o the Object to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @return true if the specified Object is equal to this Map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return map.equals(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Returns the hash code value for this Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        return map.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Returns a copy of the Attributes, implemented as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *     public Object clone() { return new Attributes(this); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * Since the attribute names and values are themselves immutable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * the Attributes returned can be safely modified without affecting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * the original.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        return new Attributes(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Writes the current attributes to the specified data output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * XXX Need to handle UTF8 values and break up lines longer than 72 bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     void write(DataOutputStream os) throws IOException {
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   299
         for (Entry<Object, Object> e : entrySet()) {
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   300
             StringBuffer buffer = new StringBuffer(
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   301
                                         ((Name) e.getKey()).toString());
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   302
             buffer.append(": ");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   304
             String value = (String) e.getValue();
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   305
             if (value != null) {
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   306
                 byte[] vb = value.getBytes("UTF8");
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   307
                 value = new String(vb, 0, 0, vb.length);
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   308
             }
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   309
             buffer.append(value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   311
             buffer.append("\r\n");
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   312
             Manifest.make72Safe(buffer);
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   313
             os.writeBytes(buffer.toString());
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   314
         }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        os.writeBytes("\r\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Writes the current attributes to the specified data output stream,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * make sure to write out the MANIFEST_VERSION or SIGNATURE_VERSION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * attributes first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * XXX Need to handle UTF8 values and break up lines longer than 72 bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    void writeMain(DataOutputStream out) throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        // write out the *-Version header first, if it exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        String vername = Name.MANIFEST_VERSION.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        String version = getValue(vername);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (version == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            vername = Name.SIGNATURE_VERSION.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            version = getValue(vername);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if (version != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            out.writeBytes(vername+": "+version+"\r\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        // write out all attributes except for the version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        // we wrote out earlier
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   341
        for (Entry<Object, Object> e : entrySet()) {
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   342
            String name = ((Name) e.getKey()).toString();
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   343
            if ((version != null) && !(name.equalsIgnoreCase(vername))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                StringBuffer buffer = new StringBuffer(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                buffer.append(": ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   348
                String value = (String) e.getValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    byte[] vb = value.getBytes("UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    value = new String(vb, 0, 0, vb.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                buffer.append(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                buffer.append("\r\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                Manifest.make72Safe(buffer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                out.writeBytes(buffer.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        out.writeBytes("\r\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * Reads attributes from the specified input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * XXX Need to handle UTF8 values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    void read(Manifest.FastInputStream is, byte[] lbuf) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        String name = null, value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        byte[] lastline = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        int len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        while ((len = is.readLine(lbuf)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            boolean lineContinued = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if (lbuf[--len] != '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                throw new IOException("line too long");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            if (len > 0 && lbuf[len-1] == '\r') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                --len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            if (len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            if (lbuf[0] == ' ') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                // continuation of previous line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    throw new IOException("misplaced continuation line");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                lineContinued = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                byte[] buf = new byte[lastline.length + len - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                System.arraycopy(lastline, 0, buf, 0, lastline.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                System.arraycopy(lbuf, 1, buf, lastline.length, len - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                if (is.peek() == ' ') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    lastline = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                value = new String(buf, 0, buf.length, "UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                lastline = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                while (lbuf[i++] != ':') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    if (i >= len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                        throw new IOException("invalid header field");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                if (lbuf[i++] != ' ') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    throw new IOException("invalid header field");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                name = new String(lbuf, 0, 0, i - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                if (is.peek() == ' ') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    lastline = new byte[len - i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                    System.arraycopy(lbuf, i, lastline, 0, len - i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                value = new String(lbuf, i, len - i, "UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                if ((putValue(name, value) != null) && (!lineContinued)) {
3861
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 2
diff changeset
   418
                    PlatformLogger.getLogger("java.util.jar").warning(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                                     "Duplicate name in Manifest: " + name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                                     + ".\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                                     + "Ensure that the manifest does not "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                                     + "have duplicate entries, and\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                                     + "that blank lines separate "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                     + "individual sections in both your\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                     + "manifest and in the META-INF/MANIFEST.MF "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                     + "entry in the jar file.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                throw new IOException("invalid header field name: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * The Attributes.Name class represents an attribute name stored in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * this Map. Valid attribute names are case-insensitive, are restricted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * to the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * 70 characters in length. Attribute values can contain any characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * and will be UTF8-encoded when written to the output stream.  See the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * <a href="../../../../technotes/guides/jar/jar.html">JAR File Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * for more information about valid attribute names and values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public static class Name {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        private int hashCode = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
         * Constructs a new attribute name using the given string name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
         * @param name the attribute string name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
         * @exception IllegalArgumentException if the attribute name was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
         *            invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
         * @exception NullPointerException if the attribute name was null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        public Name(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                throw new NullPointerException("name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            if (!isValid(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                throw new IllegalArgumentException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            this.name = name.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        private static boolean isValid(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            int len = name.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            if (len > 70 || len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                if (!isValid(name.charAt(i))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        private static boolean isValid(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            return isAlpha(c) || isDigit(c) || c == '_' || c == '-';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        private static boolean isAlpha(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        private static boolean isDigit(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            return c >= '0' && c <= '9';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
         * Compares this attribute name to another for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
         * @param o the object to compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
         * @return true if this attribute name is equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
         *         specified attribute object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            if (o instanceof Name) {
11841
38a39c748880 7143230: fix warnings in java.util.jar, sun.tools.jar, zipfs demo, etc.
smarks
parents: 11016
diff changeset
   498
                Comparator<String> c = ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                return c.compare(name, ((Name)o).name) == 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
         * Computes the hash value for this attribute name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            if (hashCode == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                hashCode = ASCIICaseInsensitiveComparator.lowerCaseHashCode(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            return hashCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
         * Returns the attribute name as a String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         * <code>Name</code> object for <code>Manifest-Version</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
         * manifest attribute. This attribute indicates the version number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
         * of the manifest standard to which a JAR file's manifest conforms.
19047
08210fe86260 8021408: Fix misc doclint issues in java.util and java.io
darcy
parents: 15682
diff changeset
   526
         * @see <a href="../../../../technotes/guides/jar/jar.html#JAR_Manifest">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
         *      Manifest and Signature Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        public static final Name MANIFEST_VERSION = new Name("Manifest-Version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
         * <code>Name</code> object for <code>Signature-Version</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
         * manifest attribute used when signing JAR files.
19047
08210fe86260 8021408: Fix misc doclint issues in java.util and java.io
darcy
parents: 15682
diff changeset
   534
         * @see <a href="../../../../technotes/guides/jar/jar.html#JAR_Manifest">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
         *      Manifest and Signature Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        public static final Name SIGNATURE_VERSION = new Name("Signature-Version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
         * <code>Name</code> object for <code>Content-Type</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
         * manifest attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        public static final Name CONTENT_TYPE = new Name("Content-Type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
         * <code>Name</code> object for <code>Class-Path</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
         * manifest attribute. Bundled extensions can use this attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
         * to find other JAR files containing needed classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
         * @see <a href="../../../../technotes/guides/extensions/spec.html#bundled">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
         *      Extensions Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        public static final Name CLASS_PATH = new Name("Class-Path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
         * <code>Name</code> object for <code>Main-Class</code> manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
         * attribute used for launching applications packaged in JAR files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
         * The <code>Main-Class</code> attribute is used in conjunction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
         * with the <code>-jar</code> command-line option of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
         * <tt>java</tt> application launcher.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        public static final Name MAIN_CLASS = new Name("Main-Class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
         * <code>Name</code> object for <code>Sealed</code> manifest attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
         * used for sealing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
         * @see <a href="../../../../technotes/guides/extensions/spec.html#sealing">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
         *      Extension Sealing</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        public static final Name SEALED = new Name("Sealed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
       /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
         * <code>Name</code> object for <code>Extension-List</code> manifest attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
         * used for declaring dependencies on installed extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
         * @see <a href="../../../../technotes/guides/extensions/spec.html#dependency">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
         *      Installed extension dependency</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        public static final Name EXTENSION_LIST = new Name("Extension-List");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
         * <code>Name</code> object for <code>Extension-Name</code> manifest attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
         * used for declaring dependencies on installed extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
         * @see <a href="../../../../technotes/guides/extensions/spec.html#dependency">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
         *      Installed extension dependency</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        public static final Name EXTENSION_NAME = new Name("Extension-Name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
         * <code>Name</code> object for <code>Extension-Name</code> manifest attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
         * used for declaring dependencies on installed extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
         * @see <a href="../../../../technotes/guides/extensions/spec.html#dependency">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
         *      Installed extension dependency</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        public static final Name EXTENSION_INSTALLATION = new Name("Extension-Installation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
         * <code>Name</code> object for <code>Implementation-Title</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
         * manifest attribute used for package versioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
         * @see <a href="../../../../technotes/guides/versioning/spec/versioning2.html#wp90779">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
         *      Java Product Versioning Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        public static final Name IMPLEMENTATION_TITLE = new Name("Implementation-Title");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
         * <code>Name</code> object for <code>Implementation-Version</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
         * manifest attribute used for package versioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
         * @see <a href="../../../../technotes/guides/versioning/spec/versioning2.html#wp90779">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
         *      Java Product Versioning Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        public static final Name IMPLEMENTATION_VERSION = new Name("Implementation-Version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
         * <code>Name</code> object for <code>Implementation-Vendor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
         * manifest attribute used for package versioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
         * @see <a href="../../../../technotes/guides/versioning/spec/versioning2.html#wp90779">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
         *      Java Product Versioning Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        public static final Name IMPLEMENTATION_VENDOR = new Name("Implementation-Vendor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
         * <code>Name</code> object for <code>Implementation-Vendor-Id</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
         * manifest attribute used for package versioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
         * @see <a href="../../../../technotes/guides/versioning/spec/versioning2.html#wp90779">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
         *      Java Product Versioning Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        public static final Name IMPLEMENTATION_VENDOR_ID = new Name("Implementation-Vendor-Id");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
       /**
11016
e2665f4ac6d2 7110111: Minor Java SE javadoc & Constructor clean up
lancea
parents: 5506
diff changeset
   628
         * <code>Name</code> object for <code>Implementation-URL</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
         * manifest attribute used for package versioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
         * @see <a href="../../../../technotes/guides/versioning/spec/versioning2.html#wp90779">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
         *      Java Product Versioning Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        public static final Name IMPLEMENTATION_URL = new Name("Implementation-URL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
         * <code>Name</code> object for <code>Specification-Title</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
         * manifest attribute used for package versioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
         * @see <a href="../../../../technotes/guides/versioning/spec/versioning2.html#wp90779">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
         *      Java Product Versioning Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        public static final Name SPECIFICATION_TITLE = new Name("Specification-Title");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
         * <code>Name</code> object for <code>Specification-Version</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
         * manifest attribute used for package versioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
         * @see <a href="../../../../technotes/guides/versioning/spec/versioning2.html#wp90779">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
         *      Java Product Versioning Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        public static final Name SPECIFICATION_VERSION = new Name("Specification-Version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
         * <code>Name</code> object for <code>Specification-Vendor</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
         * manifest attribute used for package versioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
         * @see <a href="../../../../technotes/guides/versioning/spec/versioning2.html#wp90779">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
         *      Java Product Versioning Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        public static final Name SPECIFICATION_VENDOR = new Name("Specification-Vendor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
}