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

Print this page


   1 /*
   2  * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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  *
  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


 108  * as defined in section 3.3 of
 109  * <cite>The Java&trade; Language Specification</cite>
 110  * whereas the other constructor which takes a Reader does not have that limitation.
 111  *
 112  * @see ResourceBundle
 113  * @see ListResourceBundle
 114  * @see Properties
 115  * @since JDK1.1
 116  */
 117 public class PropertyResourceBundle extends ResourceBundle {
 118     /**
 119      * Creates a property resource bundle from an {@link java.io.InputStream
 120      * InputStream}.  The property file read with this constructor
 121      * must be encoded in ISO-8859-1.
 122      *
 123      * @param stream an InputStream that represents a property file
 124      *        to read from.
 125      * @throws IOException if an I/O error occurs
 126      * @throws NullPointerException if <code>stream</code> is null
 127      */

 128     public PropertyResourceBundle (InputStream stream) throws IOException {
 129         Properties properties = new Properties();
 130         properties.load(stream);
 131         lookup = new HashMap(properties);
 132     }
 133 
 134     /**
 135      * Creates a property resource bundle from a {@link java.io.Reader
 136      * Reader}.  Unlike the constructor
 137      * {@link #PropertyResourceBundle(java.io.InputStream) PropertyResourceBundle(InputStream)},
 138      * there is no limitation as to the encoding of the input property file.
 139      *
 140      * @param reader a Reader that represents a property file to
 141      *        read from.
 142      * @throws IOException if an I/O error occurs
 143      * @throws NullPointerException if <code>reader</code> is null
 144      * @since 1.6
 145      */

 146     public PropertyResourceBundle (Reader reader) throws IOException {
 147         Properties properties = new Properties();
 148         properties.load(reader);
 149         lookup = new HashMap(properties);
 150     }
 151 
 152     // Implements java.util.ResourceBundle.handleGetObject; inherits javadoc specification.
 153     public Object handleGetObject(String key) {
 154         if (key == null) {
 155             throw new NullPointerException();
 156         }
 157         return lookup.get(key);
 158     }
 159 
 160     /**
 161      * Returns an <code>Enumeration</code> of the keys contained in
 162      * this <code>ResourceBundle</code> and its parent bundles.
 163      *
 164      * @return an <code>Enumeration</code> of the keys contained in
 165      *         this <code>ResourceBundle</code> and its parent bundles.


   1 /*
   2  * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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  *
  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


 108  * as defined in section 3.3 of
 109  * <cite>The Java&trade; Language Specification</cite>
 110  * whereas the other constructor which takes a Reader does not have that limitation.
 111  *
 112  * @see ResourceBundle
 113  * @see ListResourceBundle
 114  * @see Properties
 115  * @since JDK1.1
 116  */
 117 public class PropertyResourceBundle extends ResourceBundle {
 118     /**
 119      * Creates a property resource bundle from an {@link java.io.InputStream
 120      * InputStream}.  The property file read with this constructor
 121      * must be encoded in ISO-8859-1.
 122      *
 123      * @param stream an InputStream that represents a property file
 124      *        to read from.
 125      * @throws IOException if an I/O error occurs
 126      * @throws NullPointerException if <code>stream</code> is null
 127      */
 128     @SuppressWarnings({"unchecked", "rawtypes"})
 129     public PropertyResourceBundle (InputStream stream) throws IOException {
 130         Properties properties = new Properties();
 131         properties.load(stream);
 132         lookup = new HashMap(properties);
 133     }
 134 
 135     /**
 136      * Creates a property resource bundle from a {@link java.io.Reader
 137      * Reader}.  Unlike the constructor
 138      * {@link #PropertyResourceBundle(java.io.InputStream) PropertyResourceBundle(InputStream)},
 139      * there is no limitation as to the encoding of the input property file.
 140      *
 141      * @param reader a Reader that represents a property file to
 142      *        read from.
 143      * @throws IOException if an I/O error occurs
 144      * @throws NullPointerException if <code>reader</code> is null
 145      * @since 1.6
 146      */
 147     @SuppressWarnings({"unchecked", "rawtypes"})
 148     public PropertyResourceBundle (Reader reader) throws IOException {
 149         Properties properties = new Properties();
 150         properties.load(reader);
 151         lookup = new HashMap(properties);
 152     }
 153 
 154     // Implements java.util.ResourceBundle.handleGetObject; inherits javadoc specification.
 155     public Object handleGetObject(String key) {
 156         if (key == null) {
 157             throw new NullPointerException();
 158         }
 159         return lookup.get(key);
 160     }
 161 
 162     /**
 163      * Returns an <code>Enumeration</code> of the keys contained in
 164      * this <code>ResourceBundle</code> and its parent bundles.
 165      *
 166      * @return an <code>Enumeration</code> of the keys contained in
 167      *         this <code>ResourceBundle</code> and its parent bundles.