summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2008-07-06 00:38:56 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2008-07-06 00:38:56 +0000
commit256eb63d10a0fa402e44ca5cb42a4d9220cff762 (patch)
treeb0ebf2392a5769580b170bb3710890aaa50f330c
parent9d94cb8f9dc3efbb1018024bc6298730f52f12b6 (diff)
downloadclasspath-256eb63d10a0fa402e44ca5cb42a4d9220cff762.tar.gz
Add support for non-ISO-8859-1 property files.
2008-07-06 Andrew John Hughes <gnu_andrew@member.fsf.org> * java/util/Properties.java: (load(Reader)): Implemented. (load(InputStream)): Fixed to use load(Reader). * java/util/PropertyResourceBundle.java: (PropertyResourceBundle(Reader)): Implemented.
-rw-r--r--ChangeLog8
-rw-r--r--java/util/Properties.java30
-rw-r--r--java/util/PropertyResourceBundle.java19
3 files changed, 50 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index e97672859..9eff75a2e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-07-06 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ * java/util/Properties.java:
+ (load(Reader)): Implemented.
+ (load(InputStream)): Fixed to use load(Reader).
+ * java/util/PropertyResourceBundle.java:
+ (PropertyResourceBundle(Reader)): Implemented.
+
2008-07-03 Andrew John Hughes <gnu_andrew@member.fsf.org>
* resource/gnu/java/locale/LocaleInformation.properties,
diff --git a/java/util/Properties.java b/java/util/Properties.java
index 21894b1ab..a57004b34 100644
--- a/java/util/Properties.java
+++ b/java/util/Properties.java
@@ -48,6 +48,7 @@ import java.io.OutputStream;
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 @@ public class Properties extends Hashtable<Object, Object>
}
/**
- * 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 @@ weekdays: Sunday,Monday,Tuesday,Wednesday,\\
# 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 {@link 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 @@ label = Name:\\u0020</pre>
}
/**
+ * Reads a property list from the supplied input stream.
+ * This method has the same functionality as {@link #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.
*
diff --git a/java/util/PropertyResourceBundle.java b/java/util/PropertyResourceBundle.java
index 53a1af536..b528f08ca 100644
--- a/java/util/PropertyResourceBundle.java
+++ b/java/util/PropertyResourceBundle.java
@@ -40,6 +40,7 @@ package java.util;
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 @@ public class PropertyResourceBundle extends ResourceBundle
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 @@ public class PropertyResourceBundle extends ResourceBundle
}
/**
+ * Creates a new property resource bundle. The encoding of the property
+ * file is determined by the supplied {@link 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.
*