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