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
This commit is contained in:
parent
130cd3e1df
commit
bea63b0acc
2 changed files with 50 additions and 33 deletions
|
@ -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 ();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue