From bea63b0accf638e9b45b75efc2b75a746aba88a6 Mon Sep 17 00:00:00 2001
From: Ranjit Mathew <rmathew@hotmail.com>
Date: Mon, 17 Feb 2003 19:05:56 +0000
Subject: [PATCH] Properties.java (store): Move the code formerly in list(),
 into this method.

2003-02-17  Ranjit Mathew  <rmathew@hotmail.com>

	* java/util/Properties.java (store): Move the code formerly in
	list(), into this method.
	(list (PrintStream)): Just call list (PrintWriter) with a
	PrintWriter object constructed from the given PrintStream object.
	(list (PrintWriter)): Emulate the output of Properties.list()
	as found in JDK 1.3/1.4.

From-SVN: r63006
---
 libjava/ChangeLog                 |  9 ++++
 libjava/java/util/Properties.java | 74 +++++++++++++++++--------------
 2 files changed, 50 insertions(+), 33 deletions(-)

diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 18ae76856635..e417849ee5a2 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,12 @@
+2003-02-17  Ranjit Mathew  <rmathew@hotmail.com>
+
+	* java/util/Properties.java (store): Move the code formerly in
+	list(), into this method.
+	(list (PrintStream)): Just call list (PrintWriter) with a 
+	PrintWriter object constructed from the given PrintStream object.
+	(list (PrintWriter)): Emulate the output of Properties.list()
+	as found in JDK 1.3/1.4.
+
 2003-02-17  Michael Koch  <konqueror@gmx.de>
 
 	* java/net/DatagramSocket.java
diff --git a/libjava/java/util/Properties.java b/libjava/java/util/Properties.java
index 907ec2c4d7a6..279cf1e7b82a 100644
--- a/libjava/java/util/Properties.java
+++ b/libjava/java/util/Properties.java
@@ -377,9 +377,21 @@ label   = Name:\\u0020</pre>
       = new PrintWriter(new OutputStreamWriter(out, "ISO-8859-1"));
     if (header != null)
       writer.println("#" + header);
-    writer.println("#" + new Date());
-    list(writer);
-    writer.flush();
+    writer.println ("#" + Calendar.getInstance ().getTime ());
+    
+    Iterator iter = entrySet ().iterator ();
+    int i = size ();
+    StringBuffer s = new StringBuffer (); // Reuse the same buffer.
+    while (--i >= 0)
+      {
+        Map.Entry entry = (Map.Entry) iter.next ();
+        formatForOutput ((String) entry.getKey (), s, true);
+        s.append ('=');
+        formatForOutput ((String) entry.getValue (), s, false);
+        writer.println (s);
+      }
+
+    writer.flush ();
   }
 
   /**
@@ -453,54 +465,50 @@ label   = Name:\\u0020</pre>
   }
 
   /**
-   * Writes the key/value pairs to the given print stream.  They are
-   * written in the way described in the method store. This does not visit
-   * the keys in the default properties.
+   * Prints the key/value pairs to the given print stream.  This is 
+   * mainly useful for debugging purposes.
    *
-   * @param out the stream, where the key/value pairs are written to
-   * @throws ClassCastException if this property contains any key or
+   * @param out the print stream, where the key/value pairs are written to
+   * @throws ClassCastException if this property contains a key or a
    *         value that isn't a string
-   * @see #store(OutputStream, String)
+   * @see #list(PrintWriter)
    */
   public void list(PrintStream out)
   {
-    Iterator iter = entrySet().iterator();
-    int i = size();
-    StringBuffer s = new StringBuffer(); // Reuse the same buffer.
-    while (--i >= 0)
-      {
-        Map.Entry entry = (Map.Entry) iter.next();
-        formatForOutput((String) entry.getKey(), s, true);
-        s.append('=');
-        formatForOutput((String) entry.getValue(), s, false);
-        out.println(s);
-      }
+    PrintWriter writer = new PrintWriter (out);
+    list (writer);
   }
 
   /**
-   * Writes the key/value pairs to the given print writer.  They are
-   * written in the way, described in the method store.
+   * Prints the key/value pairs to the given print writer.  This is
+   * mainly useful for debugging purposes.
    *
-   * @param out the writer, where the key/value pairs are written to
-   * @throws ClassCastException if this property contains any key or
+   * @param out the print writer where the key/value pairs are written to
+   * @throws ClassCastException if this property contains a key or a
    *         value that isn't a string
-   * @see #store(OutputStream, String)
    * @see #list(PrintStream)
    * @since 1.1
    */
   public void list(PrintWriter out)
   {
-    Iterator iter = entrySet().iterator();
-    int i = size();
-    StringBuffer s = new StringBuffer(); // Reuse the same buffer.
+    out.println ("-- listing properties --");
+
+    Iterator iter = entrySet ().iterator ();
+    int i = size ();
     while (--i >= 0)
       {
-        Map.Entry entry = (Map.Entry) iter.next();
-        formatForOutput((String) entry.getKey(), s, true);
-        s.append('=');
-        formatForOutput((String) entry.getValue(), s, false);
-        out.println(s);
+        Map.Entry entry = (Map.Entry) iter.next ();
+        out.print ((String) entry.getKey () + "=");
+
+        // JDK 1.3/1.4 restrict the printed value, but not the key,
+        // to 40 characters, including the truncating ellipsis.
+        String s = (String ) entry.getValue ();
+        if (s != null && s.length () > 40)
+          out.println (s.substring (0, 37) + "...");
+        else
+          out.println (s);
       }
+    out.flush ();
   }
 
   /**
-- 
GitLab