src/java.base/share/classes/java/util/jar/Attributes.java
author jboes
Fri, 20 Sep 2019 11:07:52 +0100
changeset 58242 94bb65cb37d3
parent 54337 5a9d780eb9dd
permissions -rw-r--r--
8230648: Replace @exception tag with @throws in java.base Summary: Minor coding style update of javadoc tag in any file in java.base Reviewed-by: prappo, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54337
diff changeset
     2
 * Copyright (c) 1997, 2019, 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.DataOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
48936
13a3013ae0cb 8198539: Cleanup of unused imports in java/util/jar/Attributes.java (java.base) and JdpController.java (jdk.management.agent)
clanger
parents: 47444
diff changeset
    30
import java.util.Collection;
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
    31
import java.util.HashMap;
27718
5e08d0fb67c9 8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents: 25859
diff changeset
    32
import java.util.LinkedHashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Map;
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
    34
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Set;
48936
13a3013ae0cb 8198539: Cleanup of unused imports in java/util/jar/Attributes.java (java.base) and JdpController.java (jdk.management.agent)
clanger
parents: 47444
diff changeset
    36
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
    37
import jdk.internal.misc.VM;
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
    38
import jdk.internal.vm.annotation.Stable;
3861
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 2
diff changeset
    39
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
53095
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
    41
import static java.nio.charset.StandardCharsets.UTF_8;
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
    42
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The Attributes class maps Manifest attribute names to associated string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * values. Valid attribute names are case-insensitive, are restricted to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed 70
49111
1b33025ae610 6372077: JarFile.getManifest() should handle manifest attribute name 70 bytes
rriggs
parents: 48936
diff changeset
    47
 * characters in length. There must be a colon and a SPACE after the name;
1b33025ae610 6372077: JarFile.getManifest() should handle manifest attribute name 70 bytes
rriggs
parents: 48936
diff changeset
    48
 * the combined length will not exceed 72 characters.
1b33025ae610 6372077: JarFile.getManifest() should handle manifest attribute name 70 bytes
rriggs
parents: 48936
diff changeset
    49
 * Attribute values can contain any characters and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * will be UTF8-encoded when written to the output stream.  See the
45663
4a0cbf8f2474 8182023: some java.util.jar docs contain links to technotes
psandoz
parents: 36411
diff changeset
    51
 * <a href="{@docRoot}/../specs/jar/jar.html">JAR File Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * for more information about valid attribute names and values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
27718
5e08d0fb67c9 8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents: 25859
diff changeset
    54
 * <p>This map and its views have a predictable iteration order, namely the
5e08d0fb67c9 8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents: 25859
diff changeset
    55
 * order that keys were inserted into the map, as with {@link LinkedHashMap}.
5e08d0fb67c9 8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents: 25859
diff changeset
    56
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author  David Connelly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @see     Manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @since   1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public class Attributes implements Map<Object,Object>, Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * The attribute name-value mappings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected Map<Object,Object> map;
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 default size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public Attributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        this(11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Constructs a new, empty Attributes object with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * initial size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param size the initial number of attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public Attributes(int size) {
27718
5e08d0fb67c9 8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents: 25859
diff changeset
    81
        map = new LinkedHashMap<>(size);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Constructs a new Attributes object with the same attribute name-value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * mappings as in the specified Attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param attr the specified Attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public Attributes(Attributes attr) {
27718
5e08d0fb67c9 8062194: java.util.jar.Attributes should use insertion-ordered iteration
martin
parents: 25859
diff changeset
    91
        map = new LinkedHashMap<>(attr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Returns the value of the specified attribute name, or null if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * attribute name was not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param name the attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @return the value of the specified attribute name, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *         not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public Object get(Object name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return map.get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Returns the value of the specified attribute name, specified as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * a string, or null if the attribute was not found. The attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * name is case-insensitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * This method is defined as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *      return (String)get(new Attributes.Name((String)name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param name the attribute name as a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @return the String value of the specified attribute name, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *         not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @throws IllegalArgumentException if the attribute name is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public String getValue(String name) {
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   123
        return (String)get(Name.of(name));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Returns the value of the specified Attributes.Name, or null if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * attribute was not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * This method is defined as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *     return (String)get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @param name the Attributes.Name object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @return the String value of the specified Attribute.Name, or null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *         not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public String getValue(Name name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return (String)get(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Associates the specified value with the specified attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * (key) in this Map. If the Map previously contained a mapping for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * the attribute name, the old value is replaced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param name the attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param value the attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @return the previous value of the attribute, or null if none
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54337
diff changeset
   151
     * @throws    ClassCastException if the name is not a Attributes.Name
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *            or the value is not a String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public Object put(Object name, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return map.put((Attributes.Name)name, (String)value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Associates the specified value with the specified attribute name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * specified as a String. The attributes name is case-insensitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * If the Map previously contained a mapping for the attribute name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * the old value is replaced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * This method is defined as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *      return (String)put(new Attributes.Name(name), value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @param name the attribute name as a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @param value the attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @return the previous value of the attribute, or null if none
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54337
diff changeset
   172
     * @throws    IllegalArgumentException if the attribute name is invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public String putValue(String name, String value) {
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   175
        return (String)put(Name.of(name), value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Removes the attribute with the specified name (key) from this Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Returns the previous attribute value, or null if none.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param name attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @return the previous value of the attribute, or null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public Object remove(Object name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return map.remove(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Returns true if this Map maps one or more attribute names (keys)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param value the attribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @return true if this Map maps one or more attribute names to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *         the specified value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public boolean containsValue(Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return map.containsValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Returns true if this Map contains the specified attribute name (key).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param name the attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @return true if this Map contains the specified attribute name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public boolean containsKey(Object name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return map.containsKey(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Copies all of the attribute name-value mappings from the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Attributes to this Map. Duplicate mappings will be replaced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param attr the Attributes to be stored in this map
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54337
diff changeset
   216
     * @throws    ClassCastException if attr is not an Attributes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public void putAll(Map<?,?> attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        // ## javac bug?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if (!Attributes.class.isInstance(attr))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            throw new ClassCastException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        for (Map.Entry<?,?> me : (attr).entrySet())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            put(me.getKey(), me.getValue());
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
     * Removes all attributes from this Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        map.clear();
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 the number of attributes in this Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return map.size();
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 true if this Map contains no attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return map.isEmpty();
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 Set view of the attribute names (keys) contained in this Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public Set<Object> keySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return map.keySet();
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 values contained in this Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public Collection<Object> values() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return map.values();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Returns a Collection view of the attribute name-value mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * contained in this Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public Set<Map.Entry<Object,Object>> entrySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        return map.entrySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
53630
53c72d9d962b 8217393: Clarify Attributes.equals()
lancea
parents: 53095
diff changeset
   270
     * Compares the specified object to the underlying
53c72d9d962b 8217393: Clarify Attributes.equals()
lancea
parents: 53095
diff changeset
   271
     * {@linkplain Attributes#map map} for equality.
53c72d9d962b 8217393: Clarify Attributes.equals()
lancea
parents: 53095
diff changeset
   272
     * Returns true if the given object is also a Map
53c72d9d962b 8217393: Clarify Attributes.equals()
lancea
parents: 53095
diff changeset
   273
     * and the two maps represent the same mappings.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @param o the Object to be compared
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @return true if the specified Object is equal to this Map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        return map.equals(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Returns the hash code value for this Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return map.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Returns a copy of the Attributes, implemented as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *     public Object clone() { return new Attributes(this); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Since the attribute names and values are themselves immutable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * the Attributes returned can be safely modified without affecting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * the original.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return new Attributes(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Writes the current attributes to the specified data output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * XXX Need to handle UTF8 values and break up lines longer than 72 bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
53095
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   306
    void write(DataOutputStream out) throws IOException {
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   307
        StringBuilder buffer = new StringBuilder(72);
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   308
        for (Entry<Object, Object> e : entrySet()) {
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   309
            buffer.setLength(0);
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   310
            buffer.append(e.getKey().toString());
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   311
            buffer.append(": ");
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   312
            buffer.append(e.getValue());
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   313
            Manifest.println72(out, buffer.toString());
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   314
        }
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   315
        Manifest.println(out); // empty line after individual section
2
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
     */
53095
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   325
    void writeMain(DataOutputStream out) throws IOException {
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   326
        StringBuilder buffer = new StringBuilder(72);
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   327
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        // write out the *-Version header first, if it exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        String vername = Name.MANIFEST_VERSION.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        String version = getValue(vername);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        if (version == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            vername = Name.SIGNATURE_VERSION.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            version = getValue(vername);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        if (version != null) {
53095
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   337
            buffer.append(vername);
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   338
            buffer.append(": ");
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   339
            buffer.append(version);
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   340
            out.write(buffer.toString().getBytes(UTF_8));
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   341
            Manifest.println(out);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        // write out all attributes except for the version
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        // we wrote out earlier
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   346
        for (Entry<Object, Object> e : entrySet()) {
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   347
            String name = ((Name) e.getKey()).toString();
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 19409
diff changeset
   348
            if ((version != null) && !(name.equalsIgnoreCase(vername))) {
53095
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   349
                buffer.setLength(0);
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   350
                buffer.append(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                buffer.append(": ");
53095
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   352
                buffer.append(e.getValue());
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   353
                Manifest.println72(out, buffer.toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
53095
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   356
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   357
        Manifest.println(out); // empty line after main attributes section
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * Reads attributes from the specified input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
51879
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   363
    void read(Manifest.FastInputStream is, byte[] lbuf) throws IOException {
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   364
        read(is, lbuf, null, 0);
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   365
    }
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   366
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   367
    int read(Manifest.FastInputStream is, byte[] lbuf, String filename, int lineNumber) throws IOException {
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   368
        String name = null, value;
2
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;
50413
1234ff7199c7 8200530: '\r' is not supported as "newline" in java.util.jar.Manifest
sherman
parents: 49850
diff changeset
   374
            byte c = lbuf[--len];
51879
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   375
            lineNumber++;
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   376
50413
1234ff7199c7 8200530: '\r' is not supported as "newline" in java.util.jar.Manifest
sherman
parents: 49850
diff changeset
   377
            if (c != '\n' && c != '\r') {
51879
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   378
                throw new IOException("line too long ("
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   379
                            + Manifest.getErrorPosition(filename, lineNumber) + ")");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if (len > 0 && lbuf[len-1] == '\r') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                --len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            if (len == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            if (lbuf[0] == ' ') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                // continuation of previous line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                if (name == null) {
51879
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   391
                    throw new IOException("misplaced continuation line ("
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   392
                                + Manifest.getErrorPosition(filename, lineNumber) + ")");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                lineContinued = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                byte[] buf = new byte[lastline.length + len - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                System.arraycopy(lastline, 0, buf, 0, lastline.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                System.arraycopy(lbuf, 1, buf, lastline.length, len - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                if (is.peek() == ' ') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    lastline = buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                }
53095
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   402
                value = new String(buf, 0, buf.length, UTF_8);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                lastline = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                while (lbuf[i++] != ':') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    if (i >= len) {
51879
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   407
                        throw new IOException("invalid header field ("
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   408
                                    + Manifest.getErrorPosition(filename, lineNumber) + ")");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                if (lbuf[i++] != ' ') {
51879
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   412
                    throw new IOException("invalid header field ("
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   413
                                + Manifest.getErrorPosition(filename, lineNumber) + ")");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                }
53095
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   415
                name = new String(lbuf, 0, i - 2, UTF_8);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                if (is.peek() == ' ') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    lastline = new byte[len - i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    System.arraycopy(lbuf, i, lastline, 0, len - i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                }
53095
33a51275fee0 8066619: Fix deprecation warnings in java.util.jar
rriggs
parents: 52061
diff changeset
   421
                value = new String(lbuf, i, len - i, UTF_8);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                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
   425
                    PlatformLogger.getLogger("java.util.jar").warning(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                     "Duplicate name in Manifest: " + name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                     + ".\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                     + "Ensure that the manifest does not "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                     + "have duplicate entries, and\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                                     + "that blank lines separate "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                                     + "individual sections in both your\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                     + "manifest and in the META-INF/MANIFEST.MF "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                                     + "entry in the jar file.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            } catch (IllegalArgumentException e) {
51879
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   436
                throw new IOException("invalid header field name: " + name
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   437
                            + " (" + Manifest.getErrorPosition(filename, lineNumber) + ")");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
51879
6ffa38b8da65 8207768: Improve exception messages during manifest parsing of jar archives
mbaesken
parents: 50413
diff changeset
   440
        return lineNumber;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * The Attributes.Name class represents an attribute name stored in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * this Map. Valid attribute names are case-insensitive, are restricted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * to the ASCII characters in the set [0-9a-zA-Z_-], and cannot exceed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * 70 characters in length. Attribute values can contain any characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * and will be UTF8-encoded when written to the output stream.  See the
45663
4a0cbf8f2474 8182023: some java.util.jar docs contain links to technotes
psandoz
parents: 36411
diff changeset
   449
     * <a href="{@docRoot}/../specs/jar/jar.html">JAR File Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * for more information about valid attribute names and values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public static class Name {
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   453
        private final String name;
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   454
        private final int hashCode;
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   455
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   456
        /**
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   457
         * Avoid allocation for common Names
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   458
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   459
        private static @Stable Map<String, Name> KNOWN_NAMES;
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   460
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   461
        static final Name of(String name) {
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   462
            Name n = KNOWN_NAMES.get(name);
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   463
            if (n != null) {
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   464
                return n;
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   465
            }
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   466
            return new Name(name);
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   467
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
         * Constructs a new attribute name using the given string name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
         * @param name the attribute string name
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54337
diff changeset
   473
         * @throws    IllegalArgumentException if the attribute name was
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
         *            invalid
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 54337
diff changeset
   475
         * @throws    NullPointerException if the attribute name was null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        public Name(String name) {
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   478
            this.hashCode = hash(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            this.name = name.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   482
        // Checks the string is valid
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   483
        private final int hash(String name) {
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   484
            Objects.requireNonNull(name, "name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            int len = name.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            if (len > 70 || len == 0) {
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   487
                throw new IllegalArgumentException(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            }
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   489
            // Calculate hash code case insensitively
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   490
            int h = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            for (int i = 0; i < len; i++) {
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   492
                char c = name.charAt(i);
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   493
                if (c >= 'a' && c <= 'z') {
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   494
                    // hashcode must be identical for upper and lower case
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   495
                    h = h * 31 + (c - 0x20);
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   496
                } else if ((c >= 'A' && c <= 'Z' ||
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   497
                        c >= '0' && c <= '9' ||
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   498
                        c == '_' || c == '-')) {
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   499
                    h = h * 31 + c;
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   500
                } else {
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   501
                    throw new IllegalArgumentException(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            }
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   504
            return h;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
         * Compares this attribute name to another for equality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
         * @param o the object to compare
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
         * @return true if this attribute name is equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
         *         specified attribute object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        public boolean equals(Object o) {
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   514
            if (this == o) {
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   515
                return true;
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   516
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            if (o instanceof Name) {
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   518
                Name other = (Name)o;
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   519
                return other.name.equalsIgnoreCase(name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
         * Computes the hash value for this attribute name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            return hashCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
         * Returns the attribute name as a String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   540
         * {@code Name} object for {@code Manifest-Version}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
         * manifest attribute. This attribute indicates the version number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
         * of the manifest standard to which a JAR file's manifest conforms.
52061
070186461dbb 8211880: Broken links in java.util.jar
sherman
parents: 51879
diff changeset
   543
         * @see <a href="{@docRoot}/../specs/jar/jar.html#jar-manifest">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
         *      Manifest and Signature Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   546
        public static final Name MANIFEST_VERSION;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   549
         * {@code Name} object for {@code Signature-Version}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
         * manifest attribute used when signing JAR files.
52061
070186461dbb 8211880: Broken links in java.util.jar
sherman
parents: 51879
diff changeset
   551
         * @see <a href="{@docRoot}/../specs/jar/jar.html#jar-manifest">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
         *      Manifest and Signature Specification</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   554
        public static final Name SIGNATURE_VERSION;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   557
         * {@code Name} object for {@code Content-Type}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
         * manifest attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   560
        public static final Name CONTENT_TYPE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   563
         * {@code Name} object for {@code Class-Path}
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   564
         * manifest attribute.
52061
070186461dbb 8211880: Broken links in java.util.jar
sherman
parents: 51879
diff changeset
   565
         * @see <a href="{@docRoot}/../specs/jar/jar.html#class-path-attribute">
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   566
         *      JAR file specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   568
        public static final Name CLASS_PATH;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   571
         * {@code Name} object for {@code Main-Class} manifest
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
         * attribute used for launching applications packaged in JAR files.
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   573
         * The {@code Main-Class} attribute is used in conjunction
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   574
         * with the {@code -jar} command-line option of the
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   575
         * {@code java} application launcher.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   577
        public static final Name MAIN_CLASS;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   580
         * {@code Name} object for {@code Sealed} manifest attribute
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
         * used for sealing.
47444
b6da56767057 8183901: Fix broken links to "Package Sealing" in the JAR spec
bchristi
parents: 47216
diff changeset
   582
         * @see <a href="{@docRoot}/../specs/jar/jar.html#package-sealing">
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   583
         *      Package Sealing</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   585
        public static final Name SEALED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   587
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   588
         * {@code Name} object for {@code Extension-List} manifest attribute
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   589
         * used for the extension mechanism that is no longer supported.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   591
        public static final Name EXTENSION_LIST;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   594
         * {@code Name} object for {@code Extension-Name} manifest attribute.
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   595
         * used for the extension mechanism that is no longer supported.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   597
        public static final Name EXTENSION_NAME;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   600
         * {@code Name} object for {@code Extension-Installation} manifest attribute.
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   601
         *
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   602
         * @deprecated Extension mechanism is no longer supported.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
         */
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   604
        @Deprecated
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   605
        public static final Name EXTENSION_INSTALLATION;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   608
         * {@code Name} object for {@code Implementation-Title}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
         * manifest attribute used for package versioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   611
        public static final Name IMPLEMENTATION_TITLE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   614
         * {@code Name} object for {@code Implementation-Version}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
         * manifest attribute used for package versioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   617
        public static final Name IMPLEMENTATION_VERSION;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   620
         * {@code Name} object for {@code Implementation-Vendor}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
         * manifest attribute used for package versioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   623
        public static final Name IMPLEMENTATION_VENDOR;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   626
         * {@code Name} object for {@code Implementation-Vendor-Id}
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   627
         * manifest attribute.
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   628
         *
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   629
         * @deprecated Extension mechanism is no longer supported.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
         */
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   631
        @Deprecated
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   632
        public static final Name IMPLEMENTATION_VENDOR_ID;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   634
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   635
         * {@code Name} object for {@code Implementation-URL}
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   636
         * manifest attribute.
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   637
         *
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   638
         * @deprecated Extension mechanism is no longer supported.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
         */
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
   640
        @Deprecated
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   641
        public static final Name IMPLEMENTATION_URL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   644
         * {@code Name} object for {@code Specification-Title}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
         * manifest attribute used for package versioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   647
        public static final Name SPECIFICATION_TITLE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   650
         * {@code Name} object for {@code Specification-Version}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
         * manifest attribute used for package versioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   653
        public static final Name SPECIFICATION_VERSION;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        /**
32037
ab4526f4ac10 8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents: 27804
diff changeset
   656
         * {@code Name} object for {@code Specification-Vendor}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
         * manifest attribute used for package versioning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   659
        public static final Name SPECIFICATION_VENDOR;
36129
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 32037
diff changeset
   660
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 32037
diff changeset
   661
        /**
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 32037
diff changeset
   662
         * {@code Name} object for {@code Multi-Release}
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 32037
diff changeset
   663
         * manifest attribute that indicates this is a multi-release JAR file.
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 32037
diff changeset
   664
         *
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 32037
diff changeset
   665
         * @since   9
332b49163fc9 8132734: JDK 9 runtime changes to support multi-release jar files
sdrach
parents: 32037
diff changeset
   666
         */
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   667
        public static final Name MULTI_RELEASE;
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   668
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   669
        private static void addName(Map<String, Name> names, Name name) {
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   670
            names.put(name.name, name);
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   671
        }
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   672
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   673
        static {
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   674
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   675
            VM.initializeFromArchive(Attributes.Name.class);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   676
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   677
            if (KNOWN_NAMES == null) {
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   678
                MANIFEST_VERSION = new Name("Manifest-Version");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   679
                SIGNATURE_VERSION = new Name("Signature-Version");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   680
                CONTENT_TYPE = new Name("Content-Type");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   681
                CLASS_PATH = new Name("Class-Path");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   682
                MAIN_CLASS = new Name("Main-Class");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   683
                SEALED = new Name("Sealed");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   684
                EXTENSION_LIST = new Name("Extension-List");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   685
                EXTENSION_NAME = new Name("Extension-Name");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   686
                EXTENSION_INSTALLATION = new Name("Extension-Installation");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   687
                IMPLEMENTATION_TITLE = new Name("Implementation-Title");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   688
                IMPLEMENTATION_VERSION = new Name("Implementation-Version");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   689
                IMPLEMENTATION_VENDOR = new Name("Implementation-Vendor");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   690
                IMPLEMENTATION_VENDOR_ID = new Name("Implementation-Vendor-Id");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   691
                IMPLEMENTATION_URL = new Name("Implementation-URL");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   692
                SPECIFICATION_TITLE = new Name("Specification-Title");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   693
                SPECIFICATION_VERSION = new Name("Specification-Version");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   694
                SPECIFICATION_VENDOR = new Name("Specification-Vendor");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   695
                MULTI_RELEASE = new Name("Multi-Release");
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   696
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   697
                var names = new HashMap<String, Name>(64);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   698
                addName(names, MANIFEST_VERSION);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   699
                addName(names, SIGNATURE_VERSION);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   700
                addName(names, CONTENT_TYPE);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   701
                addName(names, CLASS_PATH);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   702
                addName(names, MAIN_CLASS);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   703
                addName(names, SEALED);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   704
                addName(names, EXTENSION_LIST);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   705
                addName(names, EXTENSION_NAME);
54337
5a9d780eb9dd 8221687: Deprecated j.u.jar.Attributes.Name attributes accidentally set to null
redestad
parents: 54275
diff changeset
   706
                addName(names, EXTENSION_INSTALLATION);
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   707
                addName(names, IMPLEMENTATION_TITLE);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   708
                addName(names, IMPLEMENTATION_VERSION);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   709
                addName(names, IMPLEMENTATION_VENDOR);
54337
5a9d780eb9dd 8221687: Deprecated j.u.jar.Attributes.Name attributes accidentally set to null
redestad
parents: 54275
diff changeset
   710
                addName(names, IMPLEMENTATION_VENDOR_ID);
5a9d780eb9dd 8221687: Deprecated j.u.jar.Attributes.Name attributes accidentally set to null
redestad
parents: 54275
diff changeset
   711
                addName(names, IMPLEMENTATION_URL);
54275
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   712
                addName(names, SPECIFICATION_TITLE);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   713
                addName(names, SPECIFICATION_VERSION);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   714
                addName(names, SPECIFICATION_VENDOR);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   715
                addName(names, MULTI_RELEASE);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   716
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   717
                // Common attributes used in MANIFEST.MF et.al; adding these has a
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   718
                // small footprint cost, but is likely to be quickly paid for by
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   719
                // reducing allocation when reading and parsing typical manifests
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   720
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   721
                // JDK internal attributes
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   722
                addName(names, new Name("Add-Exports"));
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   723
                addName(names, new Name("Add-Opens"));
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   724
                // LauncherHelper attributes
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   725
                addName(names, new Name("Launcher-Agent-Class"));
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   726
                addName(names, new Name("JavaFX-Application-Class"));
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   727
                // jarsigner attributes
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   728
                addName(names, new Name("Name"));
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   729
                addName(names, new Name("Created-By"));
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   730
                addName(names, new Name("SHA1-Digest"));
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   731
                addName(names, new Name("SHA-256-Digest"));
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   732
                KNOWN_NAMES = Map.copyOf(names);
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   733
            } else {
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   734
                // Even if KNOWN_NAMES was read from archive, we still need
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   735
                // to initialize the public constants
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   736
                MANIFEST_VERSION = KNOWN_NAMES.get("Manifest-Version");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   737
                SIGNATURE_VERSION = KNOWN_NAMES.get("Signature-Version");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   738
                CONTENT_TYPE = KNOWN_NAMES.get("Content-Type");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   739
                CLASS_PATH = KNOWN_NAMES.get("Class-Path");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   740
                MAIN_CLASS = KNOWN_NAMES.get("Main-Class");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   741
                SEALED = KNOWN_NAMES.get("Sealed");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   742
                EXTENSION_LIST = KNOWN_NAMES.get("Extension-List");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   743
                EXTENSION_NAME = KNOWN_NAMES.get("Extension-Name");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   744
                EXTENSION_INSTALLATION = KNOWN_NAMES.get("Extension-Installation");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   745
                IMPLEMENTATION_TITLE = KNOWN_NAMES.get("Implementation-Title");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   746
                IMPLEMENTATION_VERSION = KNOWN_NAMES.get("Implementation-Version");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   747
                IMPLEMENTATION_VENDOR = KNOWN_NAMES.get("Implementation-Vendor");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   748
                IMPLEMENTATION_VENDOR_ID = KNOWN_NAMES.get("Implementation-Vendor-Id");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   749
                IMPLEMENTATION_URL = KNOWN_NAMES.get("Implementation-URL");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   750
                SPECIFICATION_TITLE = KNOWN_NAMES.get("Specification-Title");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   751
                SPECIFICATION_VERSION = KNOWN_NAMES.get("Specification-Version");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   752
                SPECIFICATION_VENDOR = KNOWN_NAMES.get("Specification-Vendor");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   753
                MULTI_RELEASE = KNOWN_NAMES.get("Multi-Release");
5ee30b6991a7 8214712: Archive Attributes$Name.KNOWN_NAMES
redestad
parents: 53630
diff changeset
   754
            }
49850
e286fa159ff1 6805750: Improve handling of Attributes.Name
redestad
parents: 49111
diff changeset
   755
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
}