< prev index next >

src/java.base/share/classes/java/util/PropertyResourceBundle.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


  26 /*
  27  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  28  * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  29  *
  30  * The original version of this source code and documentation
  31  * is copyrighted and owned by Taligent, Inc., a wholly-owned
  32  * subsidiary of IBM. These materials are provided under terms
  33  * of a License Agreement between Taligent and Sun. This technology
  34  * is protected by multiple US and International patents.
  35  *
  36  * This notice and attribution to Taligent may not be removed.
  37  * Taligent is a registered trademark of Taligent, Inc.
  38  */
  39 
  40 package java.util;
  41 
  42 import java.io.InputStream;
  43 import java.io.InputStreamReader;
  44 import java.io.Reader;
  45 import java.io.IOException;
  46 import java.nio.charset.Charset;
  47 import java.nio.charset.MalformedInputException;
  48 import java.nio.charset.StandardCharsets;
  49 import java.nio.charset.UnmappableCharacterException;
  50 import java.security.AccessController;
  51 import java.util.Locale;
  52 import sun.security.action.GetPropertyAction;
  53 import sun.util.PropertyResourceBundleCharset;
  54 import sun.util.ResourceBundleEnumeration;
  55 
  56 /**
  57  * <code>PropertyResourceBundle</code> is a concrete subclass of
  58  * <code>ResourceBundle</code> that manages resources for a locale
  59  * using a set of static strings from a property file. See
  60  * {@link ResourceBundle ResourceBundle} for more information about resource
  61  * bundles.
  62  *
  63  * <p>
  64  * Unlike other types of resource bundle, you don't subclass
  65  * <code>PropertyResourceBundle</code>.  Instead, you supply properties
  66  * files containing the resource data.  <code>ResourceBundle.getBundle</code>


 125  * continues reading. If the system property
 126  * {@code java.util.PropertyResourceBundle.encoding} is set to either
 127  * "ISO-8859-1" or "UTF-8", the input stream is solely read in that encoding,
 128  * and throws the exception if it encounters an invalid sequence.
 129  * If "ISO-8859-1" is specified, characters that cannot be represented in
 130  * ISO-8859-1 encoding must be represented by Unicode Escapes as defined in section
 131  * 3.3 of <cite>The Java&trade; Language Specification</cite>
 132  * whereas the other constructor which takes a Reader does not have that limitation.
 133  * Other encoding values are ignored for this system property.
 134  *
 135  * @see ResourceBundle
 136  * @see ListResourceBundle
 137  * @see Properties
 138  * @since 1.1
 139  */
 140 public class PropertyResourceBundle extends ResourceBundle {
 141 
 142     // Check whether the strict encoding is specified.
 143     // The possible encoding is either "ISO-8859-1" or "UTF-8".
 144     private static final String encoding =
 145         AccessController.doPrivileged(
 146             new GetPropertyAction("java.util.PropertyResourceBundle.encoding", ""))
 147         .toUpperCase(Locale.ROOT);
 148 
 149     /**
 150      * Creates a property resource bundle from an {@link java.io.InputStream
 151     * InputStream}. This constructor reads the property file in UTF-8 by default.
 152     * If a {@link java.nio.charset.MalformedInputException} or an
 153     * {@link java.nio.charset.UnmappableCharacterException} occurs on reading the
 154     * input stream, then the PropertyResourceBundle instance resets to the state
 155     * before the exception, re-reads the input stream in {@code ISO-8859-1} and
 156     * continues reading. If the system property
 157     * {@code java.util.PropertyResourceBundle.encoding} is set to either
 158     * "ISO-8859-1" or "UTF-8", the input stream is solely read in that encoding,
 159     * and throws the exception if it encounters an invalid sequence. Other
 160     * encoding values are ignored for this system property.
 161      *
 162      * @param stream an InputStream that represents a property file
 163      *        to read from.
 164      * @throws IOException if an I/O error occurs
 165      * @throws NullPointerException if <code>stream</code> is null
 166      * @throws IllegalArgumentException if {@code stream} contains a




  26 /*
  27  * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
  28  * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
  29  *
  30  * The original version of this source code and documentation
  31  * is copyrighted and owned by Taligent, Inc., a wholly-owned
  32  * subsidiary of IBM. These materials are provided under terms
  33  * of a License Agreement between Taligent and Sun. This technology
  34  * is protected by multiple US and International patents.
  35  *
  36  * This notice and attribution to Taligent may not be removed.
  37  * Taligent is a registered trademark of Taligent, Inc.
  38  */
  39 
  40 package java.util;
  41 
  42 import java.io.InputStream;
  43 import java.io.InputStreamReader;
  44 import java.io.Reader;
  45 import java.io.IOException;

  46 import java.nio.charset.MalformedInputException;
  47 import java.nio.charset.StandardCharsets;
  48 import java.nio.charset.UnmappableCharacterException;
  49 import java.security.AccessController;
  50 import java.util.Locale;
  51 import sun.security.action.GetPropertyAction;
  52 import sun.util.PropertyResourceBundleCharset;
  53 import sun.util.ResourceBundleEnumeration;
  54 
  55 /**
  56  * <code>PropertyResourceBundle</code> is a concrete subclass of
  57  * <code>ResourceBundle</code> that manages resources for a locale
  58  * using a set of static strings from a property file. See
  59  * {@link ResourceBundle ResourceBundle} for more information about resource
  60  * bundles.
  61  *
  62  * <p>
  63  * Unlike other types of resource bundle, you don't subclass
  64  * <code>PropertyResourceBundle</code>.  Instead, you supply properties
  65  * files containing the resource data.  <code>ResourceBundle.getBundle</code>


 124  * continues reading. If the system property
 125  * {@code java.util.PropertyResourceBundle.encoding} is set to either
 126  * "ISO-8859-1" or "UTF-8", the input stream is solely read in that encoding,
 127  * and throws the exception if it encounters an invalid sequence.
 128  * If "ISO-8859-1" is specified, characters that cannot be represented in
 129  * ISO-8859-1 encoding must be represented by Unicode Escapes as defined in section
 130  * 3.3 of <cite>The Java&trade; Language Specification</cite>
 131  * whereas the other constructor which takes a Reader does not have that limitation.
 132  * Other encoding values are ignored for this system property.
 133  *
 134  * @see ResourceBundle
 135  * @see ListResourceBundle
 136  * @see Properties
 137  * @since 1.1
 138  */
 139 public class PropertyResourceBundle extends ResourceBundle {
 140 
 141     // Check whether the strict encoding is specified.
 142     // The possible encoding is either "ISO-8859-1" or "UTF-8".
 143     private static final String encoding =
 144         GetPropertyAction
 145                 .getProperty("java.util.PropertyResourceBundle.encoding", "")
 146         .toUpperCase(Locale.ROOT);
 147 
 148     /**
 149      * Creates a property resource bundle from an {@link java.io.InputStream
 150     * InputStream}. This constructor reads the property file in UTF-8 by default.
 151     * If a {@link java.nio.charset.MalformedInputException} or an
 152     * {@link java.nio.charset.UnmappableCharacterException} occurs on reading the
 153     * input stream, then the PropertyResourceBundle instance resets to the state
 154     * before the exception, re-reads the input stream in {@code ISO-8859-1} and
 155     * continues reading. If the system property
 156     * {@code java.util.PropertyResourceBundle.encoding} is set to either
 157     * "ISO-8859-1" or "UTF-8", the input stream is solely read in that encoding,
 158     * and throws the exception if it encounters an invalid sequence. Other
 159     * encoding values are ignored for this system property.
 160      *
 161      * @param stream an InputStream that represents a property file
 162      *        to read from.
 163      * @throws IOException if an I/O error occurs
 164      * @throws NullPointerException if <code>stream</code> is null
 165      * @throws IllegalArgumentException if {@code stream} contains a


< prev index next >