1 /* |
1 /* |
2 * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
49 import sun.security.action.GetPropertyAction; |
49 import sun.security.action.GetPropertyAction; |
50 import sun.util.PropertyResourceBundleCharset; |
50 import sun.util.PropertyResourceBundleCharset; |
51 import sun.util.ResourceBundleEnumeration; |
51 import sun.util.ResourceBundleEnumeration; |
52 |
52 |
53 /** |
53 /** |
54 * <code>PropertyResourceBundle</code> is a concrete subclass of |
54 * {@code PropertyResourceBundle} is a concrete subclass of |
55 * <code>ResourceBundle</code> that manages resources for a locale |
55 * {@code ResourceBundle} that manages resources for a locale |
56 * using a set of static strings from a property file. See |
56 * using a set of static strings from a property file. See |
57 * {@link ResourceBundle ResourceBundle} for more information about resource |
57 * {@link ResourceBundle ResourceBundle} for more information about resource |
58 * bundles. |
58 * bundles. |
59 * |
59 * |
60 * <p> |
60 * <p> |
61 * Unlike other types of resource bundle, you don't subclass |
61 * Unlike other types of resource bundle, you don't subclass |
62 * <code>PropertyResourceBundle</code>. Instead, you supply properties |
62 * {@code PropertyResourceBundle}. Instead, you supply properties |
63 * files containing the resource data. <code>ResourceBundle.getBundle</code> |
63 * files containing the resource data. {@code ResourceBundle.getBundle} |
64 * will automatically look for the appropriate properties file and create a |
64 * will automatically look for the appropriate properties file and create a |
65 * <code>PropertyResourceBundle</code> that refers to it. See |
65 * {@code PropertyResourceBundle} that refers to it. See |
66 * {@link ResourceBundle#getBundle(String, Locale, ClassLoader) ResourceBundle.getBundle} |
66 * {@link ResourceBundle#getBundle(String, Locale, ClassLoader) ResourceBundle.getBundle} |
67 * for a complete description of the search and instantiation strategy. |
67 * for a complete description of the search and instantiation strategy. |
68 * |
68 * |
69 * <p> |
69 * <p> |
70 * The following <a id="sample">example</a> shows a member of a resource |
70 * The following <a id="sample">example</a> shows a member of a resource |
71 * bundle family with the base name "MyResources". |
71 * bundle family with the base name "MyResources". |
72 * The text defines the bundle "MyResources_de", |
72 * The text defines the bundle "MyResources_de", |
73 * the German member of the bundle family. |
73 * the German member of the bundle family. |
74 * This member is based on <code>PropertyResourceBundle</code>, and the text |
74 * This member is based on {@code PropertyResourceBundle}, and the text |
75 * therefore is the content of the file "MyResources_de.properties" |
75 * therefore is the content of the file "MyResources_de.properties" |
76 * (a related <a href="ListResourceBundle.html#sample">example</a> shows |
76 * (a related <a href="ListResourceBundle.html#sample">example</a> shows |
77 * how you can add bundles to this family that are implemented as subclasses |
77 * how you can add bundles to this family that are implemented as subclasses |
78 * of <code>ListResourceBundle</code>). |
78 * of {@code ListResourceBundle}). |
79 * The keys in this example are of the form "s1" etc. The actual |
79 * The keys in this example are of the form "s1" etc. The actual |
80 * keys are entirely up to your choice, so long as they are the same as |
80 * keys are entirely up to your choice, so long as they are the same as |
81 * the keys you use in your program to retrieve the objects from the bundle. |
81 * the keys you use in your program to retrieve the objects from the bundle. |
82 * Keys are case-sensitive. |
82 * Keys are case-sensitive. |
83 * <blockquote> |
83 * <blockquote> |
160 * Changing or removing the property has no effect after the initialization. |
160 * Changing or removing the property has no effect after the initialization. |
161 * |
161 * |
162 * @param stream an InputStream that represents a property file |
162 * @param stream an InputStream that represents a property file |
163 * to read from. |
163 * to read from. |
164 * @throws IOException if an I/O error occurs |
164 * @throws IOException if an I/O error occurs |
165 * @throws NullPointerException if <code>stream</code> is null |
165 * @throws NullPointerException if {@code stream} is null |
166 * @throws IllegalArgumentException if {@code stream} contains a |
166 * @throws IllegalArgumentException if {@code stream} contains a |
167 * malformed Unicode escape sequence. |
167 * malformed Unicode escape sequence. |
168 * @throws MalformedInputException if the system property |
168 * @throws MalformedInputException if the system property |
169 * {@code java.util.PropertyResourceBundle.encoding} is set to "UTF-8" |
169 * {@code java.util.PropertyResourceBundle.encoding} is set to "UTF-8" |
170 * and {@code stream} contains an invalid UTF-8 byte sequence. |
170 * and {@code stream} contains an invalid UTF-8 byte sequence. |
187 * there is no limitation as to the encoding of the input property file. |
187 * there is no limitation as to the encoding of the input property file. |
188 * |
188 * |
189 * @param reader a Reader that represents a property file to |
189 * @param reader a Reader that represents a property file to |
190 * read from. |
190 * read from. |
191 * @throws IOException if an I/O error occurs |
191 * @throws IOException if an I/O error occurs |
192 * @throws NullPointerException if <code>reader</code> is null |
192 * @throws NullPointerException if {@code reader} is null |
193 * @throws IllegalArgumentException if a malformed Unicode escape sequence appears |
193 * @throws IllegalArgumentException if a malformed Unicode escape sequence appears |
194 * from {@code reader}. |
194 * from {@code reader}. |
195 * @since 1.6 |
195 * @since 1.6 |
196 */ |
196 */ |
197 @SuppressWarnings({"unchecked", "rawtypes"}) |
197 @SuppressWarnings({"unchecked", "rawtypes"}) |
208 } |
208 } |
209 return lookup.get(key); |
209 return lookup.get(key); |
210 } |
210 } |
211 |
211 |
212 /** |
212 /** |
213 * Returns an <code>Enumeration</code> of the keys contained in |
213 * Returns an {@code Enumeration} of the keys contained in |
214 * this <code>ResourceBundle</code> and its parent bundles. |
214 * this {@code ResourceBundle} and its parent bundles. |
215 * |
215 * |
216 * @return an <code>Enumeration</code> of the keys contained in |
216 * @return an {@code Enumeration} of the keys contained in |
217 * this <code>ResourceBundle</code> and its parent bundles. |
217 * this {@code ResourceBundle} and its parent bundles. |
218 * @see #keySet() |
218 * @see #keySet() |
219 */ |
219 */ |
220 public Enumeration<String> getKeys() { |
220 public Enumeration<String> getKeys() { |
221 ResourceBundle parent = this.parent; |
221 ResourceBundle parent = this.parent; |
222 return new ResourceBundleEnumeration(lookup.keySet(), |
222 return new ResourceBundleEnumeration(lookup.keySet(), |
223 (parent != null) ? parent.getKeys() : null); |
223 (parent != null) ? parent.getKeys() : null); |
224 } |
224 } |
225 |
225 |
226 /** |
226 /** |
227 * Returns a <code>Set</code> of the keys contained |
227 * Returns a {@code Set} of the keys contained |
228 * <em>only</em> in this <code>ResourceBundle</code>. |
228 * <em>only</em> in this {@code ResourceBundle}. |
229 * |
229 * |
230 * @return a <code>Set</code> of the keys contained only in this |
230 * @return a {@code Set} of the keys contained only in this |
231 * <code>ResourceBundle</code> |
231 * {@code ResourceBundle} |
232 * @since 1.6 |
232 * @since 1.6 |
233 * @see #keySet() |
233 * @see #keySet() |
234 */ |
234 */ |
235 protected Set<String> handleKeySet() { |
235 protected Set<String> handleKeySet() { |
236 return lookup.keySet(); |
236 return lookup.keySet(); |