This adds two new 1.6 methods that allow property files
to not use ISO-8859-1 so Unicode characters can be used literally.

ChangeLog:

2008-07-06  Andrew John Hughes  <[EMAIL PROTECTED]>

        * java/util/Properties.java:
        (load(Reader)): Implemented.
        (load(InputStream)): Fixed to use load(Reader).
        * java/util/PropertyResourceBundle.java:
        (PropertyResourceBundle(Reader)): Implemented.

-- 
Andrew :)

Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net
PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint = F8EF F1EA 401E 2E60 15FA  7927 142C 2591 94EF D9D8
Index: java/util/Properties.java
===================================================================
RCS file: /sources/classpath/classpath/java/util/Properties.java,v
retrieving revision 1.38
diff -u -u -r1.38 Properties.java
--- java/util/Properties.java   16 Mar 2008 22:44:41 -0000      1.38
+++ java/util/Properties.java   6 Jul 2008 00:32:14 -0000
@@ -48,6 +48,7 @@
 import java.io.OutputStreamWriter;
 import java.io.PrintStream;
 import java.io.PrintWriter;
+import java.io.Reader;
 
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamConstants;
@@ -157,7 +158,7 @@
   }
 
   /**
-   * Reads a property list from an input stream.  The stream should
+   * Reads a property list from a character stream.  The stream should
    * have the following format: <br>
    *
    * An empty line or a line starting with <code>#</code> or
@@ -189,15 +190,14 @@
 # The safest way to include a space at the end of a value:
 label   = Name:\\u0020</pre>
    *
-   * @param inStream the input stream
+   * @param inReader the input [EMAIL PROTECTED] java.io.Reader}.
    * @throws IOException if an error occurred when reading the input
    * @throws NullPointerException if in is null
+   * @since 1.6
    */
-  public void load(InputStream inStream) throws IOException
+  public void load(Reader inReader) throws IOException
   {
-    // The spec says that the file must be encoded using ISO-8859-1.
-    BufferedReader reader =
-      new BufferedReader(new InputStreamReader(inStream, "ISO-8859-1"));
+    BufferedReader reader = new BufferedReader(inReader);
     String line;
 
     while ((line = reader.readLine()) != null)
@@ -363,6 +363,24 @@
   }
 
   /**
+   * Reads a property list from the supplied input stream.
+   * This method has the same functionality as [EMAIL PROTECTED] #load(Reader)}
+   * but the character encoding is assumed to be ISO-8859-1.
+   * Unicode characters not within the Latin1 set supplied by
+   * ISO-8859-1 should be escaped using '\\uXXXX' where XXXX
+   * is the UTF-16 code unit in hexadecimal.
+   *
+   * @param inStream the byte stream to read the property list from.
+   * @throws IOException if an I/O error occurs.
+   * @see #load(Reader)
+   * @since 1.2
+   */
+  public void load(InputStream inStream) throws IOException
+  {
+    load(new InputStreamReader(inStream, "ISO-8859-1"));
+  }
+
+  /**
    * Calls <code>store(OutputStream out, String header)</code> and
    * ignores the IOException that may be thrown.
    *
Index: java/util/PropertyResourceBundle.java
===================================================================
RCS file: /sources/classpath/classpath/java/util/PropertyResourceBundle.java,v
retrieving revision 1.17
diff -u -u -r1.17 PropertyResourceBundle.java
--- java/util/PropertyResourceBundle.java       10 Dec 2006 20:25:46 -0000      
1.17
+++ java/util/PropertyResourceBundle.java       6 Jul 2008 00:32:14 -0000
@@ -40,6 +40,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.Reader;
 
 /**
  * This class is a concrete <code>ResourceBundle</code> that gets it
@@ -97,7 +98,8 @@
   private Properties properties;
 
   /**
-   * Creates a new property resource bundle.
+   * Creates a new property resource bundle.  The property file must
+   * be encoded using ISO-8859-1.
    *
    * @param stream an input stream, where the resources are read from
    * @throws NullPointerException if stream is null
@@ -110,6 +112,21 @@
   }
 
   /**
+   * Creates a new property resource bundle.  The encoding of the property
+   * file is determined by the supplied [EMAIL PROTECTED] Reader} object.
+   *
+   * @param reader an input stream, where the resources are read from
+   * @throws NullPointerException if stream is null
+   * @throws IOException if reading the stream fails
+   * @since 1.6
+   */
+  public PropertyResourceBundle(Reader reader) throws IOException
+  {
+    properties = new Properties();
+    properties.load(reader);
+  }
+
+  /**
    * Called by <code>getObject</code> when a resource is needed. This
    * returns the resource given by the key.
    *

Reply via email to