summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/java/util/Properties.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/java/util/Properties.java')
-rw-r--r--libjava/classpath/java/util/Properties.java42
1 files changed, 31 insertions, 11 deletions
diff --git a/libjava/classpath/java/util/Properties.java b/libjava/classpath/java/util/Properties.java
index e294fee7ea9..a57004b3415 100644
--- a/libjava/classpath/java/util/Properties.java
+++ b/libjava/classpath/java/util/Properties.java
@@ -38,6 +38,8 @@ exception statement from your version. */
package java.util;
+import gnu.java.lang.CPStringBuilder;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -46,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;
@@ -155,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
@@ -187,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)
@@ -217,7 +219,7 @@ label = Name:\\u0020</pre>
// Try to short-circuit when there is no escape char.
int start = pos;
boolean needsEscape = line.indexOf('\\', pos) != -1;
- StringBuilder key = needsEscape ? new StringBuilder() : null;
+ CPStringBuilder key = needsEscape ? new CPStringBuilder() : null;
while (pos < line.length()
&& ! Character.isWhitespace(c = line.charAt(pos++))
&& c != '=' && c != ':')
@@ -361,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.
*
@@ -421,7 +441,7 @@ label = Name:\\u0020</pre>
Iterator iter = entrySet ().iterator ();
int i = size ();
- StringBuilder s = new StringBuilder (); // Reuse the same buffer.
+ CPStringBuilder s = new CPStringBuilder (); // Reuse the same buffer.
while (--i >= 0)
{
Map.Entry entry = (Map.Entry) iter.next ();
@@ -564,7 +584,7 @@ label = Name:\\u0020</pre>
* leading spaces must be escaped for the value
* @see #store(OutputStream, String)
*/
- private void formatForOutput(String str, StringBuilder buffer, boolean key)
+ private void formatForOutput(String str, CPStringBuilder buffer, boolean key)
{
if (key)
{
@@ -745,7 +765,7 @@ label = Name:\\u0020</pre>
Boolean.FALSE);
XMLStreamReader reader = factory.createXMLStreamReader(in);
String name, key = null;
- StringBuffer buf = null;
+ CPStringBuilder buf = null;
while (reader.hasNext())
{
switch (reader.next())
@@ -760,7 +780,7 @@ label = Name:\\u0020</pre>
String msg = "missing 'key' attribute";
throw new InvalidPropertiesFormatException(msg);
}
- buf = new StringBuffer();
+ buf = new CPStringBuilder();
}
else if (!"properties".equals(name) && !"comment".equals(name))
{
OpenPOWER on IntegriCloud