jdk/src/java.base/share/classes/java/util/PropertyResourceBundle.java
author redestad
Thu, 21 Apr 2016 13:39:53 +0200
changeset 37593 824750ada3d6
parent 31902 1c90f9a5a76d
child 37781 71ed5645f17c
permissions -rw-r--r--
8154231: Simplify access to System properties from JDK code Reviewed-by: rriggs, chegar, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
31902
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
     2
 * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * The original version of this source code and documentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * is copyrighted and owned by Taligent, Inc., a wholly-owned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * subsidiary of IBM. These materials are provided under terms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * of a License Agreement between Taligent and Sun. This technology
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * is protected by multiple US and International patents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
package java.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.InputStream;
31902
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
    43
import java.io.InputStreamReader;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.io.Reader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.io.IOException;
31902
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
    46
import java.nio.charset.MalformedInputException;
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
    47
import java.nio.charset.StandardCharsets;
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
    48
import java.nio.charset.UnmappableCharacterException;
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
    49
import java.security.AccessController;
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
    50
import java.util.Locale;
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
    51
import sun.security.action.GetPropertyAction;
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
    52
import sun.util.PropertyResourceBundleCharset;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.util.ResourceBundleEnumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <code>PropertyResourceBundle</code> is a concrete subclass of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <code>ResourceBundle</code> that manages resources for a locale
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * using a set of static strings from a property file. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * {@link ResourceBundle ResourceBundle} for more information about resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * bundles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Unlike other types of resource bundle, you don't subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <code>PropertyResourceBundle</code>.  Instead, you supply properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * files containing the resource data.  <code>ResourceBundle.getBundle</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * will automatically look for the appropriate properties file and create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <code>PropertyResourceBundle</code> that refers to it. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * {@link ResourceBundle#getBundle(java.lang.String, java.util.Locale, java.lang.ClassLoader) ResourceBundle.getBundle}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * for a complete description of the search and instantiation strategy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * The following <a name="sample">example</a> shows a member of a resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * bundle family with the base name "MyResources".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * The text defines the bundle "MyResources_de",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * the German member of the bundle family.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * This member is based on <code>PropertyResourceBundle</code>, and the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * therefore is the content of the file "MyResources_de.properties"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * (a related <a href="ListResourceBundle.html#sample">example</a> shows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * how you can add bundles to this family that are implemented as subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * of <code>ListResourceBundle</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * The keys in this example are of the form "s1" etc. The actual
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * keys are entirely up to your choice, so long as they are the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * the keys you use in your program to retrieve the objects from the bundle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * Keys are case-sensitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * # MessageFormat pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * s1=Die Platte \"{1}\" enth&auml;lt {0}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * # location of {0} in pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * s2=1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * # sample disk name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * s3=Meine Platte
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * # first ChoiceFormat choice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * s4=keine Dateien
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * # second ChoiceFormat choice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * s5=eine Datei
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * # third ChoiceFormat choice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * s6={0,number} Dateien
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * # sample date
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * s7=3. M&auml;rz 1996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * <p>
21949
d97fd8123cbe 8028368: There is no description whether or not java.util.ResourceBundle is thread-safe
naoto
parents: 17724
diff changeset
   111
 * The implementation of a {@code PropertyResourceBundle} subclass must be
d97fd8123cbe 8028368: There is no description whether or not java.util.ResourceBundle is thread-safe
naoto
parents: 17724
diff changeset
   112
 * thread-safe if it's simultaneously used by multiple threads. The default
d97fd8123cbe 8028368: There is no description whether or not java.util.ResourceBundle is thread-safe
naoto
parents: 17724
diff changeset
   113
 * implementations of the non-abstract methods in this class are thread-safe.
d97fd8123cbe 8028368: There is no description whether or not java.util.ResourceBundle is thread-safe
naoto
parents: 17724
diff changeset
   114
 *
d97fd8123cbe 8028368: There is no description whether or not java.util.ResourceBundle is thread-safe
naoto
parents: 17724
diff changeset
   115
 * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <strong>Note:</strong> PropertyResourceBundle can be constructed either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * from an InputStream or a Reader, which represents a property file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * Constructing a PropertyResourceBundle instance from an InputStream requires
31902
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   119
 * that the input stream be encoded in UTF-8. By default, if a
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   120
 * {@link java.nio.charset.MalformedInputException} or an
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   121
 * {@link java.nio.charset.UnmappableCharacterException} occurs on reading the
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   122
 * input stream, then the PropertyResourceBundle instance resets to the state
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   123
 * before the exception, re-reads the input stream in {@code ISO-8859-1}, and
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   124
 * continues reading. If the system property
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   125
 * {@code java.util.PropertyResourceBundle.encoding} is set to either
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   126
 * "ISO-8859-1" or "UTF-8", the input stream is solely read in that encoding,
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   127
 * and throws the exception if it encounters an invalid sequence.
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   128
 * If "ISO-8859-1" is specified, characters that cannot be represented in
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   129
 * ISO-8859-1 encoding must be represented by Unicode Escapes as defined in section
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   130
 * 3.3 of <cite>The Java&trade; Language Specification</cite>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * whereas the other constructor which takes a Reader does not have that limitation.
31902
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   132
 * Other encoding values are ignored for this system property.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * @see ResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * @see ListResourceBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * @see Properties
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   137
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
public class PropertyResourceBundle extends ResourceBundle {
31902
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   140
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   141
    // Check whether the strict encoding is specified.
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   142
    // The possible encoding is either "ISO-8859-1" or "UTF-8".
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   143
    private static final String encoding =
37593
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 31902
diff changeset
   144
        GetPropertyAction
824750ada3d6 8154231: Simplify access to System properties from JDK code
redestad
parents: 31902
diff changeset
   145
                .getProperty("java.util.PropertyResourceBundle.encoding", "")
31902
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   146
        .toUpperCase(Locale.ROOT);
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   147
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Creates a property resource bundle from an {@link java.io.InputStream
31902
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   150
    * InputStream}. This constructor reads the property file in UTF-8 by default.
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   151
    * If a {@link java.nio.charset.MalformedInputException} or an
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   152
    * {@link java.nio.charset.UnmappableCharacterException} occurs on reading the
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   153
    * input stream, then the PropertyResourceBundle instance resets to the state
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   154
    * before the exception, re-reads the input stream in {@code ISO-8859-1} and
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   155
    * continues reading. If the system property
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   156
    * {@code java.util.PropertyResourceBundle.encoding} is set to either
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   157
    * "ISO-8859-1" or "UTF-8", the input stream is solely read in that encoding,
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   158
    * and throws the exception if it encounters an invalid sequence. Other
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   159
    * encoding values are ignored for this system property.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param stream an InputStream that represents a property file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *        to read from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @throws IOException if an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @throws NullPointerException if <code>stream</code> is null
17724
3d31ab54bbc5 6251788: (rb) PropertyResourceBundle doesn't document exceptions
naoto
parents: 13795
diff changeset
   165
     * @throws IllegalArgumentException if {@code stream} contains a
3d31ab54bbc5 6251788: (rb) PropertyResourceBundle doesn't document exceptions
naoto
parents: 13795
diff changeset
   166
     *     malformed Unicode escape sequence.
31902
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   167
     * @throws MalformedInputException if the system property
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   168
     *     {@code java.util.PropertyResourceBundle.encoding} is set to "UTF-8"
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   169
     *     and {@code stream} contains an invalid UTF-8 byte sequence.
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   170
     * @throws UnmappableCharacterException if the system property
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   171
     *     {@code java.util.PropertyResourceBundle.encoding} is set to "UTF-8"
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   172
     *     and {@code stream} contains an unmappable UTF-8 byte sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
13795
73850c397272 7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents: 9266
diff changeset
   174
    @SuppressWarnings({"unchecked", "rawtypes"})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public PropertyResourceBundle (InputStream stream) throws IOException {
31902
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   176
        this(new InputStreamReader(stream,
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   177
            "ISO-8859-1".equals(encoding) ?
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   178
                StandardCharsets.ISO_8859_1.newDecoder() :
1c90f9a5a76d 8027607: (rb) Provide UTF-8 based properties resource bundles
naoto
parents: 25859
diff changeset
   179
                new PropertyResourceBundleCharset("UTF-8".equals(encoding)).newDecoder()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Creates a property resource bundle from a {@link java.io.Reader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * Reader}.  Unlike the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * {@link #PropertyResourceBundle(java.io.InputStream) PropertyResourceBundle(InputStream)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * there is no limitation as to the encoding of the input property file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param reader a Reader that represents a property file to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *        read from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @throws IOException if an I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @throws NullPointerException if <code>reader</code> is null
17724
3d31ab54bbc5 6251788: (rb) PropertyResourceBundle doesn't document exceptions
naoto
parents: 13795
diff changeset
   192
     * @throws IllegalArgumentException if a malformed Unicode escape sequence appears
3d31ab54bbc5 6251788: (rb) PropertyResourceBundle doesn't document exceptions
naoto
parents: 13795
diff changeset
   193
     *     from {@code reader}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
13795
73850c397272 7193406: Clean-up JDK Build Warnings in java.util, java.io
dxu
parents: 9266
diff changeset
   196
    @SuppressWarnings({"unchecked", "rawtypes"})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public PropertyResourceBundle (Reader reader) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        Properties properties = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        properties.load(reader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        lookup = new HashMap(properties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    // Implements java.util.ResourceBundle.handleGetObject; inherits javadoc specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public Object handleGetObject(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (key == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return lookup.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Returns an <code>Enumeration</code> of the keys contained in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * this <code>ResourceBundle</code> and its parent bundles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @return an <code>Enumeration</code> of the keys contained in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *         this <code>ResourceBundle</code> and its parent bundles.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @see #keySet()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public Enumeration<String> getKeys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        ResourceBundle parent = this.parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return new ResourceBundleEnumeration(lookup.keySet(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                (parent != null) ? parent.getKeys() : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Returns a <code>Set</code> of the keys contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * <em>only</em> in this <code>ResourceBundle</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @return a <code>Set</code> of the keys contained only in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *         <code>ResourceBundle</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see #keySet()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    protected Set<String> handleKeySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return lookup.keySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    // ==================privates====================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    private Map<String,Object> lookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
}