src/java.base/share/classes/java/util/Properties.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58242 94bb65cb37d3
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
55221
27d3b8e5c58b 8224240: Properties.load fails to throw IAE on malformed unicode in certain circumstances
redestad
parents: 55009
diff changeset
     2
 * Copyright (c) 1995, 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: 3705
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: 3705
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: 3705
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3705
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3705
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.PrintWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.Reader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.Writer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.OutputStreamWriter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.BufferedWriter;
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
    37
import java.io.ObjectInputStream;
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
    38
import java.io.ObjectOutputStream;
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
    39
import java.io.StreamCorruptedException;
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
    40
import java.io.UnsupportedEncodingException;
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
    41
import java.nio.charset.Charset;
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
    42
import java.nio.charset.IllegalCharsetNameException;
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
    43
import java.nio.charset.UnsupportedCharsetException;
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
    44
import java.util.concurrent.ConcurrentHashMap;
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
    45
import java.util.function.BiConsumer;
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
    46
import java.util.function.BiFunction;
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
    47
import java.util.function.Function;
14029
c684694164c2 8000354: (props) Properties.storeToXML/loadFromXML need to allow for alternative implementations
alanb
parents: 12448
diff changeset
    48
52427
3c6aa484536c 8211122: Reduce the number of internal classes made accessible to jdk.unsupported
mchung
parents: 50677
diff changeset
    49
import jdk.internal.access.SharedSecrets;
50677
bcbfd2707e58 8199435: Unsafe publication of java.util.Properties.map
redestad
parents: 48252
diff changeset
    50
import jdk.internal.misc.Unsafe;
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
    51
import jdk.internal.util.ArraysSupport;
24371
a9c7b18bf425 8042889: (props) Properties.loadFromXML/storeToXML should consistently use the UKit parser
alanb
parents: 24196
diff changeset
    52
import jdk.internal.util.xml.PropertiesDefaultHandler;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
/**
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
    55
 * The {@code Properties} class represents a persistent set of
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
    56
 * properties. The {@code Properties} can be saved to a stream
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * or loaded from a stream. Each key and its corresponding value in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * the property list is a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * A property list can contain another property list as its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * "defaults"; this second property list is searched if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * the property key is not found in the original property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
    64
 * Because {@code Properties} inherits from {@code Hashtable}, the
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
    65
 * {@code put} and {@code putAll} methods can be applied to a
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
    66
 * {@code Properties} object.  Their use is strongly discouraged as they
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * allow the caller to insert entries whose keys or values are not
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
    68
 * {@code Strings}.  The {@code setProperty} method should be used
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
    69
 * instead.  If the {@code store} or {@code save} method is called
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
    70
 * on a "compromised" {@code Properties} object that contains a
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
    71
 * non-{@code String} key or value, the call will fail. Similarly,
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
    72
 * the call to the {@code propertyNames} or {@code list} method
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
    73
 * will fail if it is called on a "compromised" {@code Properties}
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
    74
 * object that contains a non-{@code String} key.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <p>
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
    77
 * The iterators returned by the {@code iterator} method of this class's
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
    78
 * "collection views" (that is, {@code entrySet()}, {@code keySet()}, and
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
    79
 * {@code values()}) may not fail-fast (unlike the Hashtable implementation).
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
    80
 * These iterators are guaranteed to traverse elements as they existed upon
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
    81
 * construction exactly once, and may (but are not guaranteed to) reflect any
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
    82
 * modifications subsequent to construction.
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
    83
 * <p>
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
    84
 * The {@link #load(java.io.Reader) load(Reader)} {@code /}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * {@link #store(java.io.Writer, java.lang.String) store(Writer, String)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * methods load and store properties from and to a character based stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * in a simple line-oriented format specified below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
    89
 * The {@link #load(java.io.InputStream) load(InputStream)} {@code /}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * {@link #store(java.io.OutputStream, java.lang.String) store(OutputStream, String)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * methods work the same way as the load(Reader)/store(Writer, String) pair, except
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * the input/output stream is encoded in ISO 8859-1 character encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * Characters that cannot be directly represented in this encoding can be written using
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
    94
 * Unicode escapes as defined in section 3.3 of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
    95
 * <cite>The Java&trade; Language Specification</cite>;
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
    96
 * only a single 'u' character is allowed in an escape
30789
9eca83469588 8074431: Remove native2ascii tool
mchung
parents: 29593
diff changeset
    97
 * sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * <p> The {@link #loadFromXML(InputStream)} and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * #storeToXML(OutputStream, String, String)} methods load and store properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * in a simple XML format.  By default the UTF-8 character encoding is used,
14187
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
   102
 * however a specific encoding may be specified if required. Implementations
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
   103
 * are required to support UTF-8 and UTF-16 and may support other encodings.
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
   104
 * An XML properties document has the following DOCTYPE declaration:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * &lt;!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * Note that the system URI (http://java.sun.com/dtd/properties.dtd) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <i>not</i> accessed when exporting or importing properties; it merely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * serves as a string to uniquely identify the DTD, which is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *    &lt;!-- DTD for properties --&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *    &lt;!ELEMENT properties ( comment?, entry* ) &gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *    &lt;!ATTLIST properties version CDATA #FIXED "1.0"&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *    &lt;!ELEMENT comment (#PCDATA) &gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *    &lt;!ELEMENT entry (#PCDATA) &gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *    &lt;!ATTLIST entry key CDATA #REQUIRED&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *
3705
6d494ca143b8 6875861: javadoc build warning on java.util.Properites from unconventional @see ordering
darcy
parents: 2
diff changeset
   128
 * <p>This class is thread-safe: multiple threads can share a single
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
   129
 * {@code Properties} object without the need for external synchronization.
3705
6d494ca143b8 6875861: javadoc build warning on java.util.Properites from unconventional @see ordering
darcy
parents: 2
diff changeset
   130
 *
47476
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   131
 * @apiNote
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   132
 * The {@code Properties} class does not inherit the concept of a load factor
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   133
 * from its superclass, {@code Hashtable}.
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   134
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * @author  Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * @author  Michael McCloskey
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * @author  Xueming Shen
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24371
diff changeset
   138
 * @since   1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
class Properties extends Hashtable<Object,Object> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * use serialVersionUID from JDK 1.1.X for interoperability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 55221
diff changeset
   145
    @java.io.Serial
50677
bcbfd2707e58 8199435: Unsafe publication of java.util.Properties.map
redestad
parents: 48252
diff changeset
   146
    private static final long serialVersionUID = 4112578634029874840L;
bcbfd2707e58 8199435: Unsafe publication of java.util.Properties.map
redestad
parents: 48252
diff changeset
   147
bcbfd2707e58 8199435: Unsafe publication of java.util.Properties.map
redestad
parents: 48252
diff changeset
   148
    private static final Unsafe UNSAFE = Unsafe.getUnsafe();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * A property list that contains default values for any keys not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * found in this property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
50677
bcbfd2707e58 8199435: Unsafe publication of java.util.Properties.map
redestad
parents: 48252
diff changeset
   156
    protected volatile Properties defaults;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
   159
     * Properties does not store values in its inherited Hashtable, but instead
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
   160
     * in an internal ConcurrentHashMap.  Synchronization is omitted from
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
   161
     * simple read operations.  Writes and bulk operations remain synchronized,
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
   162
     * as in Hashtable.
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
   163
     */
50677
bcbfd2707e58 8199435: Unsafe publication of java.util.Properties.map
redestad
parents: 48252
diff changeset
   164
    private transient volatile ConcurrentHashMap<Object, Object> map;
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
   165
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
   166
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Creates an empty property list with no default values.
47476
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   168
     *
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   169
     * @implNote The initial capacity of a {@code Properties} object created
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   170
     * with this constructor is unspecified.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public Properties() {
47476
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   173
        this(null, 8);
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   174
    }
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   175
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   176
    /**
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   177
     * Creates an empty property list with no default values, and with an
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   178
     * initial size accommodating the specified number of elements without the
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   179
     * need to dynamically resize.
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   180
     *
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   181
     * @param  initialCapacity the {@code Properties} will be sized to
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   182
     *         accommodate this many elements
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   183
     * @throws IllegalArgumentException if the initial capacity is less than
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   184
     *         zero.
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   185
     */
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   186
    public Properties(int initialCapacity) {
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   187
        this(null, initialCapacity);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Creates an empty property list with the specified defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
47476
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   193
     * @implNote The initial capacity of a {@code Properties} object created
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   194
     * with this constructor is unspecified.
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   195
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param   defaults   the defaults.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public Properties(Properties defaults) {
47476
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   199
        this(defaults, 8);
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   200
    }
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   201
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   202
    private Properties(Properties defaults, int initialCapacity) {
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
   203
        // use package-private constructor to
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
   204
        // initialize unused fields with dummy values
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
   205
        super((Void) null);
47476
1851856462b0 8189319: Add a java.util.Properties constructor that takes an initial capacity
bchristi
parents: 47423
diff changeset
   206
        map = new ConcurrentHashMap<>(initialCapacity);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        this.defaults = defaults;
50677
bcbfd2707e58 8199435: Unsafe publication of java.util.Properties.map
redestad
parents: 48252
diff changeset
   208
bcbfd2707e58 8199435: Unsafe publication of java.util.Properties.map
redestad
parents: 48252
diff changeset
   209
        // Ensure writes can't be reordered
bcbfd2707e58 8199435: Unsafe publication of java.util.Properties.map
redestad
parents: 48252
diff changeset
   210
        UNSAFE.storeFence();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
   214
     * Calls the {@code Hashtable} method {@code put}. Provided for
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
   215
     * parallelism with the {@code getProperty} method. Enforces use of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * strings for property keys and values. The value returned is the
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
   217
     * result of the {@code Hashtable} call to {@code put}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param key the key to be placed into this property list.
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
   220
     * @param value the value corresponding to {@code key}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @return     the previous value of the specified key in this property
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   222
     *             list, or {@code null} if it did not have one.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @see #getProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @since    1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public synchronized Object setProperty(String key, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        return put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Reads a property list (key and element pairs) from the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * character stream in a simple line-oriented format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Properties are processed in terms of lines. There are two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * kinds of line, <i>natural lines</i> and <i>logical lines</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * A natural line is defined as a line of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * characters that is terminated either by a set of line terminator
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   239
     * characters ({@code \n} or {@code \r} or {@code \r\n})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * or by the end of the stream. A natural line may be either a blank line,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * a comment line, or hold all or some of a key-element pair. A logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * line holds all the data of a key-element pair, which may be spread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * out across several adjacent natural lines by escaping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * the line terminator sequence with a backslash character
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   245
     * {@code \}.  Note that a comment line cannot be extended
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * in this manner; every natural line that is a comment must have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * its own comment indicator, as described below. Lines are read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * input until the end of the stream is reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * A natural line that contains only white space characters is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * considered blank and is ignored.  A comment line has an ASCII
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   253
     * {@code '#'} or {@code '!'} as its first non-white
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * space character; comment lines are also ignored and do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * encode key-element information.  In addition to line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * terminators, this format considers the characters space
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   257
     * ({@code ' '}, {@code '\u005Cu0020'}), tab
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   258
     * ({@code '\t'}, {@code '\u005Cu0009'}), and form feed
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   259
     * ({@code '\f'}, {@code '\u005Cu000C'}) to be white
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * If a logical line is spread across several natural lines, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * backslash escaping the line terminator sequence, the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * terminator sequence, and any white space at the start of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * following line have no affect on the key or element values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * The remainder of the discussion of key and element parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * (when loading) will assume all the characters constituting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * the key and element appear on a single natural line after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * line continuation characters have been removed.  Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * it is <i>not</i> sufficient to only examine the character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * preceding a line terminator sequence to decide if the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * terminator is escaped; there must be an odd number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * contiguous backslashes for the line terminator to be escaped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Since the input is processed from left to right, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * non-zero even number of 2<i>n</i> contiguous backslashes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * before a line terminator (or elsewhere) encodes <i>n</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * backslashes after escape processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * The key contains all of the characters in the line starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * with the first non-white space character and up to, but not
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   283
     * including, the first unescaped {@code '='},
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   284
     * {@code ':'}, or white space character other than a line
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * terminator. All of these key termination characters may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * included in the key by escaping them with a preceding backslash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * character; for example,<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   289
     * {@code \:\=}<p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   291
     * would be the two-character key {@code ":="}.  Line
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   292
     * terminator characters can be included using {@code \r} and
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   293
     * {@code \n} escape sequences.  Any white space after the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * key is skipped; if the first non-white space character after
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   295
     * the key is {@code '='} or {@code ':'}, then it is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * ignored and any white space characters after it are also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * skipped.  All remaining characters on the line become part of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * the associated element string; if there are no remaining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * characters, the element is the empty string
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   300
     * {@code ""}.  Once the raw character sequences
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * constituting the key and element are identified, escape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * processing is performed as described above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * As an example, each of the following three lines specifies the key
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   306
     * {@code "Truth"} and the associated element value
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   307
     * {@code "Beauty"}:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Truth = Beauty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *  Truth:Beauty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * Truth                    :Beauty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * As another example, the following three lines specify a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * property:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * fruits                           apple, banana, pear, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *                                  cantaloupe, watermelon, \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *                                  kiwi, mango
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * </pre>
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   320
     * The key is {@code "fruits"} and the associated element is:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * <pre>"apple, banana, pear, cantaloupe, watermelon, kiwi, mango"</pre>
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   322
     * Note that a space appears before each {@code \} so that a space
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   323
     * will appear after each comma in the final result; the {@code \},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * line terminator, and leading white space on the continuation line are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * merely discarded and are <i>not</i> replaced by one or more other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * As a third example, the line:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * <pre>cheeses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * </pre>
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   331
     * specifies that the key is {@code "cheeses"} and the associated
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 19864
diff changeset
   332
     * element is the empty string {@code ""}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * <p>
44844
b2b4d98404ba 8179364: update "<a name=" in java.base module to use id attribute
jjg
parents: 44035
diff changeset
   334
     * <a id="unicodeescapes"></a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Characters in keys and elements can be represented in escape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * sequences similar to those used for character and string literals
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
   337
     * (see sections 3.3 and 3.10.6 of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
   338
     * <cite>The Java&trade; Language Specification</cite>).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * The differences from the character escape sequences and Unicode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * escapes used for characters and strings are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * <li> Octal escapes are not recognized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   346
     * <li> The character sequence {@code \b} does <i>not</i>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * represent a backspace character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * <li> The method does not treat a backslash character,
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   350
     * {@code \}, before a non-valid escape character as an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * error; the backslash is silently dropped.  For example, in a
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   352
     * Java string the sequence {@code "\z"} would cause a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * compile time error.  In contrast, this method silently drops
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * the backslash.  Therefore, this method treats the two character
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   355
     * sequence {@code "\b"} as equivalent to the single
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   356
     * character {@code 'b'}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * <li> Escapes are not necessary for single and double quotes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * however, by the rule above, single and double quote characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * preceded by a backslash still yield single and double quote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * characters, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
19864
41c6dfb2022e 7186311: (props) "Unicode" is misspelled as "Uniocde" in JavaDoc and error message
sherman
parents: 18568
diff changeset
   363
     * <li> Only a single 'u' character is allowed in a Unicode escape
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * The specified stream remains open after this method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @param   reader   the input character stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @throws  IOException  if an error occurred when reading from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *          input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @throws  IllegalArgumentException if a malformed Unicode escape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *          appears in the input.
29593
935cd82c2868 8075362: j.u.Properties.load() methods have misaligned @throws clauses
bpb
parents: 29486
diff changeset
   375
     * @throws  NullPointerException if {@code reader} is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public synchronized void load(Reader reader) throws IOException {
29486
3a37e8f12b94 8073214: javadoc of Properties methods should specify NullPointerExceptions
bpb
parents: 25859
diff changeset
   379
        Objects.requireNonNull(reader, "reader parameter is null");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        load0(new LineReader(reader));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * Reads a property list (key and element pairs) from the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * byte stream. The input stream is in a simple line-oriented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * format as specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * {@link #load(java.io.Reader) load(Reader)} and is assumed to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * the ISO 8859-1 character encoding; that is each byte is one Latin1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * character. Characters not in Latin1, and certain special characters,
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
   390
     * are represented in keys and elements using Unicode escapes as defined in
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
   391
     * section 3.3 of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7816
diff changeset
   392
     * <cite>The Java&trade; Language Specification</cite>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * The specified stream remains open after this method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @param      inStream   the input stream.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   397
     * @throws     IOException  if an error occurred when reading from the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *             input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @throws     IllegalArgumentException if the input stream contains a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     *             malformed Unicode escape sequence.
29593
935cd82c2868 8075362: j.u.Properties.load() methods have misaligned @throws clauses
bpb
parents: 29486
diff changeset
   401
     * @throws     NullPointerException if {@code inStream} is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public synchronized void load(InputStream inStream) throws IOException {
29486
3a37e8f12b94 8073214: javadoc of Properties methods should specify NullPointerExceptions
bpb
parents: 25859
diff changeset
   405
        Objects.requireNonNull(inStream, "inStream parameter is null");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        load0(new LineReader(inStream));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   409
    private void load0(LineReader lr) throws IOException {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   410
        StringBuilder outBuffer = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        int limit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        int keyLen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        int valueStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        boolean hasSep;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        boolean precedingBackslash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        while ((limit = lr.readLine()) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            keyLen = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            valueStart = limit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            hasSep = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            //System.out.println("line=<" + new String(lineBuf, 0, limit) + ">");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            precedingBackslash = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            while (keyLen < limit) {
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   425
                char c = lr.lineBuf[keyLen];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                //need check if escaped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                if ((c == '=' ||  c == ':') && !precedingBackslash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    valueStart = keyLen + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                    hasSep = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                } else if ((c == ' ' || c == '\t' ||  c == '\f') && !precedingBackslash) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    valueStart = keyLen + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                if (c == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                    precedingBackslash = !precedingBackslash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    precedingBackslash = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                keyLen++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            while (valueStart < limit) {
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   443
                char c = lr.lineBuf[valueStart];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                if (c != ' ' && c != '\t' &&  c != '\f') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    if (!hasSep && (c == '=' ||  c == ':')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                        hasSep = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                valueStart++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            }
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   453
            String key = loadConvert(lr.lineBuf, 0, keyLen, outBuffer);
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   454
            String value = loadConvert(lr.lineBuf, valueStart, limit - valueStart, outBuffer);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    /* Read in a "logical line" from an InputStream/Reader, skip all comment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * and blank lines and filter out those leading whitespace characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * (\u0020, \u0009 and \u000c) from the beginning of a "natural line".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * Method returns the char length of the "logical line" and stores
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * the line in "lineBuf".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     */
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   465
    private static class LineReader {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   466
        LineReader(InputStream inStream) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            this.inStream = inStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            inByteBuf = new byte[8192];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   471
        LineReader(Reader reader) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            this.reader = reader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            inCharBuf = new char[8192];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        char[] lineBuf = new char[1024];
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   477
        private byte[] inByteBuf;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   478
        private char[] inCharBuf;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   479
        private int inLimit = 0;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   480
        private int inOff = 0;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   481
        private InputStream inStream;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   482
        private Reader reader;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        int readLine() throws IOException {
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   485
            // use locals to optimize for interpreted performance
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            int len = 0;
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   487
            int off = inOff;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   488
            int limit = inLimit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            boolean skipWhiteSpace = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            boolean appendedLineBegin = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            boolean precedingBackslash = false;
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   493
            boolean fromStream = inStream != null;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   494
            byte[] byteBuf = inByteBuf;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   495
            char[] charBuf = inCharBuf;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   496
            char[] lineBuf = this.lineBuf;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   497
            char c;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            while (true) {
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   500
                if (off >= limit) {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   501
                    inLimit = limit = fromStream ? inStream.read(byteBuf)
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   502
                                                 : reader.read(charBuf);
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   503
                    if (limit <= 0) {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   504
                        if (len == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                        }
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   507
                        return precedingBackslash ? len - 1 : len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    }
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   509
                    off = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                }
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   511
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   512
                // (char)(byte & 0xFF) is equivalent to calling a ISO8859-1 decoder.
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   513
                c = (fromStream) ? (char)(byteBuf[off++] & 0xFF) : charBuf[off++];
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   514
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                if (skipWhiteSpace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    if (c == ' ' || c == '\t' || c == '\f') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                    if (!appendedLineBegin && (c == '\r' || c == '\n')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                    skipWhiteSpace = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    appendedLineBegin = false;
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   524
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                }
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   526
                if (len == 0) { // Still on a new logical line
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    if (c == '#' || c == '!') {
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   528
                        // Comment, quickly consume the rest of the line
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   529
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   530
                        // When checking for new line characters a range check,
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   531
                        // starting with the higher bound ('\r') means one less
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   532
                        // branch in the common case.
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   533
                        commentLoop: while (true) {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   534
                            if (fromStream) {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   535
                                byte b;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   536
                                while (off < limit) {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   537
                                    b = byteBuf[off++];
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   538
                                    if (b <= '\r' && (b == '\r' || b == '\n'))
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   539
                                        break commentLoop;
44035
f3871cc7914a 8176041: Optimize handling of comment lines in Properties$LineReader.readLine
redestad
parents: 38772
diff changeset
   540
                                }
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   541
                                if (off == limit) {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   542
                                    inLimit = limit = inStream.read(byteBuf);
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   543
                                    if (limit <= 0) { // EOF
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   544
                                        return -1;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   545
                                    }
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   546
                                    off = 0;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   547
                                }
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   548
                            } else {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   549
                                while (off < limit) {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   550
                                    c = charBuf[off++];
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   551
                                    if (c <= '\r' && (c == '\r' || c == '\n'))
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   552
                                        break commentLoop;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   553
                                }
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   554
                                if (off == limit) {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   555
                                    inLimit = limit = reader.read(charBuf);
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   556
                                    if (limit <= 0) { // EOF
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   557
                                        return -1;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   558
                                    }
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   559
                                    off = 0;
44035
f3871cc7914a 8176041: Optimize handling of comment lines in Properties$LineReader.readLine
redestad
parents: 38772
diff changeset
   560
                                }
f3871cc7914a 8176041: Optimize handling of comment lines in Properties$LineReader.readLine
redestad
parents: 38772
diff changeset
   561
                            }
f3871cc7914a 8176041: Optimize handling of comment lines in Properties$LineReader.readLine
redestad
parents: 38772
diff changeset
   562
                        }
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   563
                        skipWhiteSpace = true;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   564
                        continue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                if (c != '\n' && c != '\r') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                    lineBuf[len++] = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    if (len == lineBuf.length) {
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   571
                        lineBuf = new char[ArraysSupport.newLength(len, 1, len)];
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   572
                        System.arraycopy(this.lineBuf, 0, lineBuf, 0, len);
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   573
                        this.lineBuf = lineBuf;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    }
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   575
                    // flip the preceding backslash flag
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   576
                    precedingBackslash = (c == '\\') ? !precedingBackslash : false;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   577
                } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                    // reached EOL
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   579
                    if (len == 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                        skipWhiteSpace = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                    }
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   583
                    if (off >= limit) {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   584
                        inLimit = limit = fromStream ? inStream.read(byteBuf)
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   585
                                                     : reader.read(charBuf);
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   586
                        off = 0;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   587
                        if (limit <= 0) { // EOF
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   588
                            return precedingBackslash ? len - 1 : len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    if (precedingBackslash) {
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   592
                        // backslash at EOL is not part of the line
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                        len -= 1;
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   594
                        // skip leading whitespace characters in the following line
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                        skipWhiteSpace = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                        appendedLineBegin = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                        precedingBackslash = false;
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   598
                        // take care not to include any subsequent \n
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                        if (c == '\r') {
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   600
                            if (fromStream) {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   601
                                if (byteBuf[off] == '\n') {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   602
                                    off++;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   603
                                }
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   604
                            } else {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   605
                                if (charBuf[off] == '\n') {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   606
                                    off++;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   607
                                }
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   608
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                    } else {
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   611
                        inOff = off;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                        return len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * Converts encoded &#92;uxxxx to unicode chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * and changes special saved chars to their original forms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     */
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   623
    private String loadConvert(char[] in, int off, int len, StringBuilder out) {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   624
        char aChar;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   625
        int end = off + len;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   626
        int start = off;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   627
        while (off < end) {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   628
            aChar = in[off++];
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   629
            if (aChar == '\\') {
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   630
                break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            }
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   632
        }
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   633
        if (off == end) { // No backslash
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   634
            return new String(in, start, len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        }
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   636
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   637
        // backslash found at off - 1, reset the shared buffer, rewind offset
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   638
        out.setLength(0);
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   639
        off--;
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   640
        out.append(in, start, off - start);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        while (off < end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            aChar = in[off++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            if (aChar == '\\') {
55221
27d3b8e5c58b 8224240: Properties.load fails to throw IAE on malformed unicode in certain circumstances
redestad
parents: 55009
diff changeset
   645
                // No need to bounds check since LineReader::readLine excludes
27d3b8e5c58b 8224240: Properties.load fails to throw IAE on malformed unicode in certain circumstances
redestad
parents: 55009
diff changeset
   646
                // unescaped \s at the end of the line
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                aChar = in[off++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                if(aChar == 'u') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    // Read the xxxx
55221
27d3b8e5c58b 8224240: Properties.load fails to throw IAE on malformed unicode in certain circumstances
redestad
parents: 55009
diff changeset
   650
                    if (off > end - 4)
27d3b8e5c58b 8224240: Properties.load fails to throw IAE on malformed unicode in certain circumstances
redestad
parents: 55009
diff changeset
   651
                        throw new IllegalArgumentException(
27d3b8e5c58b 8224240: Properties.load fails to throw IAE on malformed unicode in certain circumstances
redestad
parents: 55009
diff changeset
   652
                                     "Malformed \\uxxxx encoding.");
27d3b8e5c58b 8224240: Properties.load fails to throw IAE on malformed unicode in certain circumstances
redestad
parents: 55009
diff changeset
   653
                    int value = 0;
27d3b8e5c58b 8224240: Properties.load fails to throw IAE on malformed unicode in certain circumstances
redestad
parents: 55009
diff changeset
   654
                    for (int i = 0; i < 4; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                        aChar = in[off++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                        switch (aChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                          case '0': case '1': case '2': case '3': case '4':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                          case '5': case '6': case '7': case '8': case '9':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                             value = (value << 4) + aChar - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                             break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                          case 'a': case 'b': case 'c':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                          case 'd': case 'e': case 'f':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                             value = (value << 4) + 10 + aChar - 'a';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                             break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                          case 'A': case 'B': case 'C':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                          case 'D': case 'E': case 'F':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                             value = (value << 4) + 10 + aChar - 'A';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                             break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                              throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                                           "Malformed \\uxxxx encoding.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                        }
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   673
                    }
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   674
                    out.append((char)value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    if (aChar == 't') aChar = '\t';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                    else if (aChar == 'r') aChar = '\r';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    else if (aChar == 'n') aChar = '\n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                    else if (aChar == 'f') aChar = '\f';
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   680
                    out.append(aChar);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            } else {
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   683
                out.append(aChar);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        }
55009
cdb107ca16e6 8224202: Speed up Properties.load
redestad
parents: 52427
diff changeset
   686
        return out.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * Converts unicodes to encoded &#92;uxxxx and escapes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * special characters with a preceding slash
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    private String saveConvert(String theString,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                               boolean escapeSpace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                               boolean escapeUnicode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        int len = theString.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        int bufLen = len * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        if (bufLen < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            bufLen = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 24865
diff changeset
   701
        StringBuilder outBuffer = new StringBuilder(bufLen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        for(int x=0; x<len; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            char aChar = theString.charAt(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            // Handle common case first, selecting largest block that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            // avoids the specials below
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            if ((aChar > 61) && (aChar < 127)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                if (aChar == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                    outBuffer.append('\\'); outBuffer.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                outBuffer.append(aChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            switch(aChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                case ' ':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    if (x == 0 || escapeSpace)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                        outBuffer.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                    outBuffer.append(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                case '\t':outBuffer.append('\\'); outBuffer.append('t');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                case '\n':outBuffer.append('\\'); outBuffer.append('n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                case '\r':outBuffer.append('\\'); outBuffer.append('r');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                case '\f':outBuffer.append('\\'); outBuffer.append('f');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                case '=': // Fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                case ':': // Fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                case '#': // Fall through
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                case '!':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                    outBuffer.append('\\'); outBuffer.append(aChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                    if (((aChar < 0x0020) || (aChar > 0x007e)) & escapeUnicode ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                        outBuffer.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                        outBuffer.append('u');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                        outBuffer.append(toHex((aChar >> 12) & 0xF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                        outBuffer.append(toHex((aChar >>  8) & 0xF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                        outBuffer.append(toHex((aChar >>  4) & 0xF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                        outBuffer.append(toHex( aChar        & 0xF));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                        outBuffer.append(aChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        return outBuffer.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    private static void writeComments(BufferedWriter bw, String comments)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        bw.write("#");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        int len = comments.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        int current = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        int last = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        char[] uu = new char[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        uu[0] = '\\';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        uu[1] = 'u';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        while (current < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            char c = comments.charAt(current);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            if (c > '\u00ff' || c == '\n' || c == '\r') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                if (last != current)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                    bw.write(comments.substring(last, current));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                if (c > '\u00ff') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                    uu[2] = toHex((c >> 12) & 0xf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                    uu[3] = toHex((c >>  8) & 0xf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                    uu[4] = toHex((c >>  4) & 0xf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                    uu[5] = toHex( c        & 0xf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                    bw.write(new String(uu));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                    bw.newLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                    if (c == '\r' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                        current != len - 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                        comments.charAt(current + 1) == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                        current++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                    if (current == len - 1 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                        (comments.charAt(current + 1) != '#' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                        comments.charAt(current + 1) != '!'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                        bw.write("#");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                last = current + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            current++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        if (last != current)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            bw.write(comments.substring(last, current));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        bw.newLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    /**
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   793
     * Calls the {@code store(OutputStream out, String comments)} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * and suppresses IOExceptions that were thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * @deprecated This method does not throw an IOException if an I/O error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * occurs while saving the property list.  The preferred way to save a
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   798
     * properties list is via the {@code store(OutputStream out,
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   799
     * String comments)} method or the
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   800
     * {@code storeToXML(OutputStream os, String comment)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @param   out      an output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * @param   comments   a description of the property list.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   804
     * @throws     ClassCastException  if this {@code Properties} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     *             contains any keys or values that are not
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   806
     *             {@code Strings}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    @Deprecated
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6521
diff changeset
   809
    public void save(OutputStream out, String comments)  {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            store(out, comments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * Writes this property list (key and element pairs) in this
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   818
     * {@code Properties} table to the output character stream in a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * format suitable for using the {@link #load(java.io.Reader) load(Reader)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * <p>
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   822
     * Properties from the defaults table of this {@code Properties}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * table (if any) are <i>not</i> written out by this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * <p>
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   825
     * If the comments argument is not null, then an ASCII {@code #}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * character, the comments string, and a line separator are first written
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   827
     * to the output stream. Thus, the {@code comments} can serve as an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * identifying comment. Any one of a line feed ('\n'), a carriage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * return ('\r'), or a carriage return followed immediately by a line feed
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   830
     * in comments is replaced by a line separator generated by the {@code Writer}
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   831
     * and if the next character in comments is not character {@code #} or
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   832
     * character {@code !} then an ASCII {@code #} is written out
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * after that line separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * Next, a comment line is always written, consisting of an ASCII
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   836
     * {@code #} character, the current date and time (as if produced
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   837
     * by the {@code toString} method of {@code Date} for the
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   838
     * current time), and a line separator as generated by the {@code Writer}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * <p>
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   840
     * Then every entry in this {@code Properties} table is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * written out, one per line. For each entry the key string is
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   842
     * written, then an ASCII {@code =}, then the associated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * element string. For the key, all space characters are
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   844
     * written with a preceding {@code \} character.  For the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * element, leading space characters, but not embedded or trailing
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   846
     * space characters, are written with a preceding {@code \}
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   847
     * character. The key and element characters {@code #},
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   848
     * {@code !}, {@code =}, and {@code :} are written
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * with a preceding backslash to ensure that they are properly loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * After the entries have been written, the output stream is flushed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * The output stream remains open after this method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * @param   writer      an output character stream writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * @param   comments   a description of the property list.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   856
     * @throws     IOException if writing this property list to the specified
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
   857
     *             output stream throws an {@code IOException}.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   858
     * @throws     ClassCastException  if this {@code Properties} object
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   859
     *             contains any keys or values that are not {@code Strings}.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   860
     * @throws     NullPointerException  if {@code writer} is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    public void store(Writer writer, String comments)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        store0((writer instanceof BufferedWriter)?(BufferedWriter)writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                                                 : new BufferedWriter(writer),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
               comments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
               false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * Writes this property list (key and element pairs) in this
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   874
     * {@code Properties} table to the output stream in a format suitable
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   875
     * for loading into a {@code Properties} table using the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * {@link #load(InputStream) load(InputStream)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * <p>
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   878
     * Properties from the defaults table of this {@code Properties}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * table (if any) are <i>not</i> written out by this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * This method outputs the comments, properties keys and values in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * the same format as specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * {@link #store(java.io.Writer, java.lang.String) store(Writer)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * with the following differences:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * <li>The stream is written using the ISO 8859-1 character encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * <li>Characters not in Latin-1 in the comments are written as
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   889
     * {@code \u005Cu}<i>xxxx</i> for their appropriate unicode
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * hexadecimal value <i>xxxx</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     *
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   892
     * <li>Characters less than {@code \u005Cu0020} and characters greater
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   893
     * than {@code \u005Cu007E} in property keys or values are written
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   894
     * as {@code \u005Cu}<i>xxxx</i> for the appropriate hexadecimal
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * value <i>xxxx</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * After the entries have been written, the output stream is flushed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * The output stream remains open after this method returns.
24196
61c9885d76e2 8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents: 21334
diff changeset
   900
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * @param   out      an output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * @param   comments   a description of the property list.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   903
     * @throws     IOException if writing this property list to the specified
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
   904
     *             output stream throws an {@code IOException}.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   905
     * @throws     ClassCastException  if this {@code Properties} object
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   906
     *             contains any keys or values that are not {@code Strings}.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   907
     * @throws     NullPointerException  if {@code out} is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    public void store(OutputStream out, String comments)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        store0(new BufferedWriter(new OutputStreamWriter(out, "8859_1")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
               comments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
               true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    private void store0(BufferedWriter bw, String comments, boolean escUnicode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        if (comments != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            writeComments(bw, comments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        bw.write("#" + new Date().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        bw.newLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        synchronized (this) {
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
   927
            for (Map.Entry<Object, Object> e : entrySet()) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
   928
                String key = (String)e.getKey();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
   929
                String val = (String)e.getValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                key = saveConvert(key, true, escUnicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                /* No need to escape embedded and trailing spaces for value, hence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                 * pass false to flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                val = saveConvert(val, false, escUnicode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                bw.write(key + "=" + val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                bw.newLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        bw.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * Loads all of the properties represented by the XML document on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * specified input stream into this properties table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * <p>The XML document must have the following DOCTYPE declaration:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * &lt;!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * Furthermore, the document must satisfy the properties DTD described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     *
14187
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
   953
     * <p> An implementation is required to read XML documents that use the
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
   954
     * "{@code UTF-8}" or "{@code UTF-16}" encoding. An implementation may
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
   955
     * support additional encodings.
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
   956
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * <p>The specified stream is closed after this method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * @param in the input stream from which to read the XML document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * @throws IOException if reading from the specified input stream
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
   961
     *         results in an {@code IOException}.
14187
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
   962
     * @throws java.io.UnsupportedEncodingException if the document's encoding
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
   963
     *         declaration can be read and it specifies an encoding that is not
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
   964
     *         supported
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * @throws InvalidPropertiesFormatException Data on input stream does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     *         constitute a valid XML document with the mandated document type.
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   967
     * @throws NullPointerException if {@code in} is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * @see    #storeToXML(OutputStream, String, String)
14187
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
   969
     * @see    <a href="http://www.w3.org/TR/REC-xml/#charencoding">Character
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
   970
     *         Encoding in Entities</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    public synchronized void loadFromXML(InputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        throws IOException, InvalidPropertiesFormatException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    {
24371
a9c7b18bf425 8042889: (props) Properties.loadFromXML/storeToXML should consistently use the UKit parser
alanb
parents: 24196
diff changeset
   976
        Objects.requireNonNull(in);
a9c7b18bf425 8042889: (props) Properties.loadFromXML/storeToXML should consistently use the UKit parser
alanb
parents: 24196
diff changeset
   977
        PropertiesDefaultHandler handler = new PropertiesDefaultHandler();
a9c7b18bf425 8042889: (props) Properties.loadFromXML/storeToXML should consistently use the UKit parser
alanb
parents: 24196
diff changeset
   978
        handler.load(this, in);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * Emits an XML document representing all of the properties contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * in this table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     *
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
   986
     * <p> An invocation of this method of the form {@code props.storeToXML(os,
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
   987
     * comment)} behaves in exactly the same way as the invocation
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
   988
     * {@code props.storeToXML(os, comment, "UTF-8");}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * @param os the output stream on which to emit the XML document.
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   991
     * @param comment a description of the property list, or {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     *        if no comment is desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * @throws IOException if writing to the specified output stream
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
   994
     *         results in an {@code IOException}.
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   995
     * @throws NullPointerException if {@code os} is null.
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   996
     * @throws ClassCastException  if this {@code Properties} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     *         contains any keys or values that are not
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
   998
     *         {@code Strings}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * @see    #loadFromXML(InputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     */
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6521
diff changeset
  1002
    public void storeToXML(OutputStream os, String comment)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        storeToXML(os, comment, "UTF-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * Emits an XML document representing all of the properties contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * in this table, using the specified encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * <p>The XML document will have the following DOCTYPE declaration:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * &lt;!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     *
14187
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
  1017
     * <p>If the specified comment is {@code null} then no comment
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * will be stored in the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     *
14187
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
  1020
     * <p> An implementation is required to support writing of XML documents
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
  1021
     * that use the "{@code UTF-8}" or "{@code UTF-16}" encoding. An
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
  1022
     * implementation may support additional encodings.
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
  1023
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * <p>The specified stream remains open after this method returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     *
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1026
     * <p>This method behaves the same as
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1027
     * {@linkplain #storeToXML(OutputStream os, String comment, Charset charset)}
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1028
     * except that it will {@linkplain java.nio.charset.Charset#forName look up the charset}
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1029
     * using the given encoding name.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1030
     *
6521
3b995fa42e90 6977887: (doc) Java 6 API missing info about encoding parameter in storeToXML method
mchung
parents: 5506
diff changeset
  1031
     * @param os        the output stream on which to emit the XML document.
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
  1032
     * @param comment   a description of the property list, or {@code null}
6521
3b995fa42e90 6977887: (doc) Java 6 API missing info about encoding parameter in storeToXML method
mchung
parents: 5506
diff changeset
  1033
     *                  if no comment is desired.
3b995fa42e90 6977887: (doc) Java 6 API missing info about encoding parameter in storeToXML method
mchung
parents: 5506
diff changeset
  1034
     * @param  encoding the name of a supported
3b995fa42e90 6977887: (doc) Java 6 API missing info about encoding parameter in storeToXML method
mchung
parents: 5506
diff changeset
  1035
     *                  <a href="../lang/package-summary.html#charenc">
3b995fa42e90 6977887: (doc) Java 6 API missing info about encoding parameter in storeToXML method
mchung
parents: 5506
diff changeset
  1036
     *                  character encoding</a>
3b995fa42e90 6977887: (doc) Java 6 API missing info about encoding parameter in storeToXML method
mchung
parents: 5506
diff changeset
  1037
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * @throws IOException if writing to the specified output stream
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
  1039
     *         results in an {@code IOException}.
14187
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
  1040
     * @throws java.io.UnsupportedEncodingException if the encoding is not
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
  1041
     *         supported by the implementation.
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
  1042
     * @throws NullPointerException if {@code os} is {@code null},
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
  1043
     *         or if {@code encoding} is {@code null}.
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
  1044
     * @throws ClassCastException  if this {@code Properties} object
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1045
     *         contains any keys or values that are not {@code Strings}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * @see    #loadFromXML(InputStream)
14187
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
  1047
     * @see    <a href="http://www.w3.org/TR/REC-xml/#charencoding">Character
9e193f8bab66 8000685: (props) Properties.storeToXML/loadFromXML should only require UTF-8 and UTF-16 to be supported
alanb
parents: 14029
diff changeset
  1048
     *         Encoding in Entities</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     */
6882
637546039be3 6977738: Deadlock between java.lang.ClassLoader and java.util.Properties
mchung
parents: 6521
diff changeset
  1051
    public void storeToXML(OutputStream os, String comment, String encoding)
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1052
        throws IOException {
24371
a9c7b18bf425 8042889: (props) Properties.loadFromXML/storeToXML should consistently use the UKit parser
alanb
parents: 24196
diff changeset
  1053
        Objects.requireNonNull(os);
a9c7b18bf425 8042889: (props) Properties.loadFromXML/storeToXML should consistently use the UKit parser
alanb
parents: 24196
diff changeset
  1054
        Objects.requireNonNull(encoding);
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1055
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1056
        try {
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1057
            Charset charset = Charset.forName(encoding);
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1058
            storeToXML(os, comment, charset);
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1059
        } catch (IllegalCharsetNameException | UnsupportedCharsetException e) {
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1060
            throw new UnsupportedEncodingException(encoding);
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1061
        }
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1062
    }
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1063
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1064
    /**
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1065
     * Emits an XML document representing all of the properties contained
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1066
     * in this table, using the specified encoding.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1067
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1068
     * <p>The XML document will have the following DOCTYPE declaration:
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1069
     * <pre>
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1070
     * &lt;!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"&gt;
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1071
     * </pre>
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1072
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1073
     * <p>If the specified comment is {@code null} then no comment
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1074
     * will be stored in the document.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1075
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1076
     * <p> An implementation is required to support writing of XML documents
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1077
     * that use the "{@code UTF-8}" or "{@code UTF-16}" encoding. An
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1078
     * implementation may support additional encodings.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1079
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1080
     * <p> Unmappable characters for the specified charset will be encoded as
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1081
     * numeric character references.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1082
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1083
     * <p>The specified stream remains open after this method returns.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1084
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1085
     * @param os        the output stream on which to emit the XML document.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1086
     * @param comment   a description of the property list, or {@code null}
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1087
     *                  if no comment is desired.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1088
     * @param charset   the charset
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1089
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1090
     * @throws IOException if writing to the specified output stream
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1091
     *         results in an {@code IOException}.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1092
     * @throws NullPointerException if {@code os} or {@code charset} is {@code null}.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1093
     * @throws ClassCastException  if this {@code Properties} object
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1094
     *         contains any keys or values that are not {@code Strings}.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1095
     * @see    #loadFromXML(InputStream)
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1096
     * @see    <a href="http://www.w3.org/TR/REC-xml/#charencoding">Character
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1097
     *         Encoding in Entities</a>
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1098
     * @since 10
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1099
     */
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1100
    public void storeToXML(OutputStream os, String comment, Charset charset)
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1101
        throws IOException {
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1102
        Objects.requireNonNull(os, "OutputStream");
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1103
        Objects.requireNonNull(charset, "Charset");
24371
a9c7b18bf425 8042889: (props) Properties.loadFromXML/storeToXML should consistently use the UKit parser
alanb
parents: 24196
diff changeset
  1104
        PropertiesDefaultHandler handler = new PropertiesDefaultHandler();
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47476
diff changeset
  1105
        handler.store(this, os, comment, charset);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * Searches for the property with the specified key in this property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * If the key is not found in this property list, the default property list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * and its defaults, recursively, are then checked. The method returns
11676
7e75ec031b97 7132338: Use @code friendly idiom for '\' in javadoc
darcy
parents: 10587
diff changeset
  1112
     * {@code null} if the property is not found.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * @param   key   the property key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * @return  the value in this property list with the specified key value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * @see     #setProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * @see     #defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    public String getProperty(String key) {
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1120
        Object oval = map.get(key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        String sval = (oval instanceof String) ? (String)oval : null;
50677
bcbfd2707e58 8199435: Unsafe publication of java.util.Properties.map
redestad
parents: 48252
diff changeset
  1122
        Properties defaults;
bcbfd2707e58 8199435: Unsafe publication of java.util.Properties.map
redestad
parents: 48252
diff changeset
  1123
        return ((sval == null) && ((defaults = this.defaults) != null)) ? defaults.getProperty(key) : sval;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * Searches for the property with the specified key in this property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * If the key is not found in this property list, the default property list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * and its defaults, recursively, are then checked. The method returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * default value argument if the property is not found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * @param   key            the hashtable key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * @param   defaultValue   a default value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * @return  the value in this property list with the specified key value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * @see     #setProperty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * @see     #defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    public String getProperty(String key, String defaultValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        String val = getProperty(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        return (val == null) ? defaultValue : val;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * Returns an enumeration of all the keys in this property list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * including distinct keys in the default property list if a key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * of the same name has not already been found from the main
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * properties list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * @return  an enumeration of all the keys in this property list, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     *          the keys in the default property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * @throws  ClassCastException if any key in this property list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     *          is not a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * @see     java.util.Enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * @see     java.util.Properties#defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * @see     #stringPropertyNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    public Enumeration<?> propertyNames() {
12448
b95438b17098 7157893: Warnings Cleanup in java.util.*
khazra
parents: 11676
diff changeset
  1159
        Hashtable<String,Object> h = new Hashtable<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        enumerate(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        return h.keys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    /**
38772
545bcf25bef0 8059361: Properties.stringPropertyNames() returns a set inconsistent with the assertions from the spec
smarks
parents: 38436
diff changeset
  1165
     * Returns an unmodifiable set of keys from this property list
545bcf25bef0 8059361: Properties.stringPropertyNames() returns a set inconsistent with the assertions from the spec
smarks
parents: 38436
diff changeset
  1166
     * where the key and its corresponding value are strings,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * including distinct keys in the default property list if a key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * of the same name has not already been found from the main
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * properties list.  Properties whose key or value is not
32108
aa5490a167ee 8133188: docs: replace <tt> tags (obsolete in html5) for java.util
avstepan
parents: 30789
diff changeset
  1170
     * of type {@code String} are omitted.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * <p>
38772
545bcf25bef0 8059361: Properties.stringPropertyNames() returns a set inconsistent with the assertions from the spec
smarks
parents: 38436
diff changeset
  1172
     * The returned set is not backed by this {@code Properties} object.
545bcf25bef0 8059361: Properties.stringPropertyNames() returns a set inconsistent with the assertions from the spec
smarks
parents: 38436
diff changeset
  1173
     * Changes to this {@code Properties} object are not reflected in the
545bcf25bef0 8059361: Properties.stringPropertyNames() returns a set inconsistent with the assertions from the spec
smarks
parents: 38436
diff changeset
  1174
     * returned set.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     *
38772
545bcf25bef0 8059361: Properties.stringPropertyNames() returns a set inconsistent with the assertions from the spec
smarks
parents: 38436
diff changeset
  1176
     * @return  an unmodifiable set of keys in this property list where
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     *          the key and its corresponding value are strings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     *          including the keys in the default property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * @see     java.util.Properties#defaults
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    public Set<String> stringPropertyNames() {
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1183
        Map<String, String> h = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        enumerateStringProperties(h);
38772
545bcf25bef0 8059361: Properties.stringPropertyNames() returns a set inconsistent with the assertions from the spec
smarks
parents: 38436
diff changeset
  1185
        return Collections.unmodifiableSet(h.keySet());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * Prints this property list out to the specified output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * This method is useful for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * @param   out   an output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * @throws  ClassCastException if any key in this property list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     *          is not a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
    public void list(PrintStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        out.println("-- listing properties --");
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1198
        Map<String, Object> h = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        enumerate(h);
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1200
        for (Map.Entry<String, Object> e : h.entrySet()) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1201
            String key = e.getKey();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1202
            String val = (String)e.getValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            if (val.length() > 40) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                val = val.substring(0, 37) + "...";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            out.println(key + "=" + val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * Prints this property list out to the specified output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     * This method is useful for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * @param   out   an output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     * @throws  ClassCastException if any key in this property list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     *          is not a string.
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 24371
diff changeset
  1217
     * @since   1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * Rather than use an anonymous inner class to share common code, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     * method is duplicated in order to ensure that a non-1.1 compiler can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     * compile this file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    public void list(PrintWriter out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        out.println("-- listing properties --");
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1226
        Map<String, Object> h = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        enumerate(h);
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1228
        for (Map.Entry<String, Object> e : h.entrySet()) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1229
            String key = e.getKey();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1230
            String val = (String)e.getValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            if (val.length() > 40) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                val = val.substring(0, 37) + "...";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            out.println(key + "=" + val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    /**
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1239
     * Enumerates all key/value pairs into the specified Map.
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1240
     * @param h the Map
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * @throws ClassCastException if any of the property keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     *         is not of String type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     */
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1244
    private void enumerate(Map<String, Object> h) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        if (defaults != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            defaults.enumerate(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        }
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1248
        for (Map.Entry<Object, Object> e : entrySet()) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1249
            String key = (String)e.getKey();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1250
            h.put(key, e.getValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    /**
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1255
     * Enumerates all key/value pairs into the specified Map
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * and omits the property if the key or value is not a string.
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1257
     * @param h the Map
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     */
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1259
    private void enumerateStringProperties(Map<String, String> h) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        if (defaults != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            defaults.enumerateStringProperties(h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        }
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1263
        for (Map.Entry<Object, Object> e : entrySet()) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1264
            Object k = e.getKey();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1265
            Object v = e.getValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            if (k instanceof String && v instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                h.put((String) k, (String) v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * Convert a nibble to a hex character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * @param   nibble  the nibble to convert.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    private static char toHex(int nibble) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        return hexDigit[(nibble & 0xF)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    /** A table of hex digits */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
    private static final char[] hexDigit = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
    };
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1284
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1285
    //
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1286
    // Hashtable methods overridden and delegated to a ConcurrentHashMap instance
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1287
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1288
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1289
    public int size() {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1290
        return map.size();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1291
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1292
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1293
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1294
    public boolean isEmpty() {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1295
        return map.isEmpty();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1296
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1297
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1298
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1299
    public Enumeration<Object> keys() {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1300
        // CHM.keys() returns Iterator w/ remove() - instead wrap keySet()
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1301
        return Collections.enumeration(map.keySet());
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1302
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1303
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1304
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1305
    public Enumeration<Object> elements() {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1306
        // CHM.elements() returns Iterator w/ remove() - instead wrap values()
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1307
        return Collections.enumeration(map.values());
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1308
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1309
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1310
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1311
    public boolean contains(Object value) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1312
        return map.contains(value);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1313
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1314
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1315
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1316
    public boolean containsValue(Object value) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1317
        return map.containsValue(value);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1318
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1319
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1320
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1321
    public boolean containsKey(Object key) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1322
        return map.containsKey(key);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1323
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1324
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1325
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1326
    public Object get(Object key) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1327
        return map.get(key);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1328
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1329
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1330
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1331
    public synchronized Object put(Object key, Object value) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1332
        return map.put(key, value);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1333
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1334
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1335
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1336
    public synchronized Object remove(Object key) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1337
        return map.remove(key);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1338
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1339
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1340
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1341
    public synchronized void putAll(Map<?, ?> t) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1342
        map.putAll(t);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1343
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1344
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1345
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1346
    public synchronized void clear() {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1347
        map.clear();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1348
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1349
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1350
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1351
    public synchronized String toString() {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1352
        return map.toString();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1353
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1354
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1355
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1356
    public Set<Object> keySet() {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1357
        return Collections.synchronizedSet(map.keySet(), this);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1358
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1359
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1360
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1361
    public Collection<Object> values() {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1362
        return Collections.synchronizedCollection(map.values(), this);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1363
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1364
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1365
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1366
    public Set<Map.Entry<Object, Object>> entrySet() {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1367
        return Collections.synchronizedSet(new EntrySet(map.entrySet()), this);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1368
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1369
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1370
    /*
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1371
     * Properties.entrySet() should not support add/addAll, however
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1372
     * ConcurrentHashMap.entrySet() provides add/addAll.  This class wraps the
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1373
     * Set returned from CHM, changing add/addAll to throw UOE.
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1374
     */
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1375
    private static class EntrySet implements Set<Map.Entry<Object, Object>> {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1376
        private Set<Map.Entry<Object,Object>> entrySet;
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1377
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1378
        private EntrySet(Set<Map.Entry<Object, Object>> entrySet) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1379
            this.entrySet = entrySet;
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1380
        }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1381
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1382
        @Override public int size() { return entrySet.size(); }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1383
        @Override public boolean isEmpty() { return entrySet.isEmpty(); }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1384
        @Override public boolean contains(Object o) { return entrySet.contains(o); }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1385
        @Override public Object[] toArray() { return entrySet.toArray(); }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1386
        @Override public <T> T[] toArray(T[] a) { return entrySet.toArray(a); }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1387
        @Override public void clear() { entrySet.clear(); }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1388
        @Override public boolean remove(Object o) { return entrySet.remove(o); }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1389
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1390
        @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1391
        public boolean add(Map.Entry<Object, Object> e) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1392
            throw new UnsupportedOperationException();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1393
        }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1394
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1395
        @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1396
        public boolean addAll(Collection<? extends Map.Entry<Object, Object>> c) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1397
            throw new UnsupportedOperationException();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1398
        }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1399
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1400
        @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1401
        public boolean containsAll(Collection<?> c) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1402
            return entrySet.containsAll(c);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1403
        }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1404
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1405
        @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1406
        public boolean removeAll(Collection<?> c) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1407
            return entrySet.removeAll(c);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1408
        }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1409
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1410
        @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1411
        public boolean retainAll(Collection<?> c) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1412
            return entrySet.retainAll(c);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1413
        }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1414
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1415
        @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1416
        public Iterator<Map.Entry<Object, Object>> iterator() {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1417
            return entrySet.iterator();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1418
        }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1419
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1420
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1421
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1422
    public synchronized boolean equals(Object o) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1423
        return map.equals(o);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1424
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1425
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1426
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1427
    public synchronized int hashCode() {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1428
        return map.hashCode();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1429
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1430
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1431
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1432
    public Object getOrDefault(Object key, Object defaultValue) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1433
        return map.getOrDefault(key, defaultValue);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1434
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1435
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1436
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1437
    public synchronized void forEach(BiConsumer<? super Object, ? super Object> action) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1438
        map.forEach(action);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1439
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1440
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1441
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1442
    public synchronized void replaceAll(BiFunction<? super Object, ? super Object, ?> function) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1443
        map.replaceAll(function);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1444
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1445
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1446
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1447
    public synchronized Object putIfAbsent(Object key, Object value) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1448
        return map.putIfAbsent(key, value);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1449
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1450
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1451
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1452
    public synchronized boolean remove(Object key, Object value) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1453
        return map.remove(key, value);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1454
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1455
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1456
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1457
    public synchronized boolean replace(Object key, Object oldValue, Object newValue) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1458
        return map.replace(key, oldValue, newValue);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1459
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1460
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1461
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1462
    public synchronized Object replace(Object key, Object value) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1463
        return map.replace(key, value);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1464
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1465
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1466
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1467
    public synchronized Object computeIfAbsent(Object key,
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1468
            Function<? super Object, ?> mappingFunction) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1469
        return map.computeIfAbsent(key, mappingFunction);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1470
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1471
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1472
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1473
    public synchronized Object computeIfPresent(Object key,
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1474
            BiFunction<? super Object, ? super Object, ?> remappingFunction) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1475
        return map.computeIfPresent(key, remappingFunction);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1476
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1477
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1478
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1479
    public synchronized Object compute(Object key,
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1480
            BiFunction<? super Object, ? super Object, ?> remappingFunction) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1481
        return map.compute(key, remappingFunction);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1482
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1483
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1484
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1485
    public synchronized Object merge(Object key, Object value,
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1486
            BiFunction<? super Object, ? super Object, ?> remappingFunction) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1487
        return map.merge(key, value, remappingFunction);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1488
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1489
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1490
    //
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1491
    // Special Hashtable methods
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1492
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1493
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1494
    protected void rehash() { /* no-op */ }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1495
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1496
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1497
    public synchronized Object clone() {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1498
        Properties clone = (Properties) cloneHashtable();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1499
        clone.map = new ConcurrentHashMap<>(map);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1500
        return clone;
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1501
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1502
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1503
    //
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1504
    // Hashtable serialization overrides
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1505
    // (these should emit and consume Hashtable-compatible stream)
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1506
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1507
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1508
    void writeHashtable(ObjectOutputStream s) throws IOException {
50677
bcbfd2707e58 8199435: Unsafe publication of java.util.Properties.map
redestad
parents: 48252
diff changeset
  1509
        var map = this.map;
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1510
        List<Object> entryStack = new ArrayList<>(map.size() * 2); // an estimate
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1511
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1512
        for (Map.Entry<Object, Object> entry : map.entrySet()) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1513
            entryStack.add(entry.getValue());
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1514
            entryStack.add(entry.getKey());
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1515
        }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1516
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1517
        // Write out the simulated threshold, loadfactor
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1518
        float loadFactor = 0.75f;
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1519
        int count = entryStack.size() / 2;
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1520
        int length = (int)(count / loadFactor) + (count / 20) + 3;
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1521
        if (length > count && (length & 1) == 0) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1522
            length--;
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1523
        }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1524
        synchronized (map) { // in case of multiple concurrent serializations
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1525
            defaultWriteHashtable(s, length, loadFactor);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1526
        }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1527
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1528
        // Write out simulated length and real count of elements
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1529
        s.writeInt(length);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1530
        s.writeInt(count);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1531
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1532
        // Write out the key/value objects from the stacked entries
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1533
        for (int i = entryStack.size() - 1; i >= 0; i--) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1534
            s.writeObject(entryStack.get(i));
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1535
        }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1536
    }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1537
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1538
    @Override
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1539
    void readHashtable(ObjectInputStream s) throws IOException,
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1540
            ClassNotFoundException {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1541
        // Read in the threshold and loadfactor
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1542
        s.defaultReadObject();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1543
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1544
        // Read the original length of the array and number of elements
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1545
        int origlength = s.readInt();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1546
        int elements = s.readInt();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1547
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1548
        // Validate # of elements
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1549
        if (elements < 0) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1550
            throw new StreamCorruptedException("Illegal # of Elements: " + elements);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1551
        }
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1552
47423
4fc2a4a29f3d 8174109: Better queuing priorities
smarks
parents: 47216
diff changeset
  1553
        // Constructing the backing map will lazily create an array when the first element is
4fc2a4a29f3d 8174109: Better queuing priorities
smarks
parents: 47216
diff changeset
  1554
        // added, so check it before construction. Note that CHM's constructor takes a size
4fc2a4a29f3d 8174109: Better queuing priorities
smarks
parents: 47216
diff changeset
  1555
        // that is the number of elements to be stored -- not the table size -- so it must be
4fc2a4a29f3d 8174109: Better queuing priorities
smarks
parents: 47216
diff changeset
  1556
        // inflated by the default load factor of 0.75, then inflated to the next power of two.
4fc2a4a29f3d 8174109: Better queuing priorities
smarks
parents: 47216
diff changeset
  1557
        // (CHM uses the same power-of-two computation as HashMap, and HashMap.tableSizeFor is
4fc2a4a29f3d 8174109: Better queuing priorities
smarks
parents: 47216
diff changeset
  1558
        // accessible here.) Check Map.Entry[].class since it's the nearest public type to
4fc2a4a29f3d 8174109: Better queuing priorities
smarks
parents: 47216
diff changeset
  1559
        // what is actually created.
4fc2a4a29f3d 8174109: Better queuing priorities
smarks
parents: 47216
diff changeset
  1560
        SharedSecrets.getJavaObjectInputStreamAccess()
4fc2a4a29f3d 8174109: Better queuing priorities
smarks
parents: 47216
diff changeset
  1561
                     .checkArray(s, Map.Entry[].class, HashMap.tableSizeFor((int)(elements / 0.75)));
4fc2a4a29f3d 8174109: Better queuing priorities
smarks
parents: 47216
diff changeset
  1562
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1563
        // create CHM of appropriate capacity
50677
bcbfd2707e58 8199435: Unsafe publication of java.util.Properties.map
redestad
parents: 48252
diff changeset
  1564
        var map = new ConcurrentHashMap<>(elements);
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1565
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1566
        // Read all the key/value objects
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1567
        for (; elements > 0; elements--) {
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1568
            Object key = s.readObject();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1569
            Object value = s.readObject();
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1570
            map.put(key, value);
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1571
        }
50677
bcbfd2707e58 8199435: Unsafe publication of java.util.Properties.map
redestad
parents: 48252
diff changeset
  1572
        this.map = map;
38436
4676f6c9ebee 8029891: Deadlock detected in java/lang/ClassLoader/deadlock/GetResource.java
bchristi
parents: 32108
diff changeset
  1573
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
}