Commit bea63b0a by Ranjit Mathew Committed by Tom Tromey

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
parent 130cd3e1
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> 2003-02-17 Michael Koch <konqueror@gmx.de>
* java/net/DatagramSocket.java * java/net/DatagramSocket.java
......
...@@ -377,9 +377,21 @@ label = Name:\\u0020</pre> ...@@ -377,9 +377,21 @@ label = Name:\\u0020</pre>
= new PrintWriter(new OutputStreamWriter(out, "ISO-8859-1")); = new PrintWriter(new OutputStreamWriter(out, "ISO-8859-1"));
if (header != null) if (header != null)
writer.println("#" + header); writer.println("#" + header);
writer.println("#" + new Date()); writer.println ("#" + Calendar.getInstance ().getTime ());
list(writer);
writer.flush(); 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> ...@@ -453,54 +465,50 @@ label = Name:\\u0020</pre>
} }
/** /**
* Writes the key/value pairs to the given print stream. They are * Prints the key/value pairs to the given print stream. This is
* written in the way described in the method store. This does not visit * mainly useful for debugging purposes.
* the keys in the default properties.
* *
* @param out the stream, where the key/value pairs are written to * @param out the print stream, where the key/value pairs are written to
* @throws ClassCastException if this property contains any key or * @throws ClassCastException if this property contains a key or a
* value that isn't a string * value that isn't a string
* @see #store(OutputStream, String) * @see #list(PrintWriter)
*/ */
public void list(PrintStream out) public void list(PrintStream out)
{ {
Iterator iter = entrySet().iterator(); PrintWriter writer = new PrintWriter (out);
int i = size(); list (writer);
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);
}
} }
/** /**
* Writes the key/value pairs to the given print writer. They are * Prints the key/value pairs to the given print writer. This is
* written in the way, described in the method store. * mainly useful for debugging purposes.
* *
* @param out the writer, where the key/value pairs are written to * @param out the print writer where the key/value pairs are written to
* @throws ClassCastException if this property contains any key or * @throws ClassCastException if this property contains a key or a
* value that isn't a string * value that isn't a string
* @see #store(OutputStream, String)
* @see #list(PrintStream) * @see #list(PrintStream)
* @since 1.1 * @since 1.1
*/ */
public void list(PrintWriter out) public void list(PrintWriter out)
{ {
Iterator iter = entrySet().iterator(); out.println ("-- listing properties --");
int i = size();
StringBuffer s = new StringBuffer(); // Reuse the same buffer. Iterator iter = entrySet ().iterator ();
int i = size ();
while (--i >= 0) while (--i >= 0)
{ {
Map.Entry entry = (Map.Entry) iter.next(); Map.Entry entry = (Map.Entry) iter.next ();
formatForOutput((String) entry.getKey(), s, true); out.print ((String) entry.getKey () + "=");
s.append('=');
formatForOutput((String) entry.getValue(), s, false); // JDK 1.3/1.4 restrict the printed value, but not the key,
out.println(s); // 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 ();
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment