On 02/01/2015 15:38, Claes Redestad wrote:
Hi,
this is a proposal to resolve concerns that
PrintWriter/BufferedWriter behave
inconsistently with j.u.Formatter when setting the line.separator
property to override
system-appropriate line breaks.
Instead of providing a set of new constructors, I propose to simply
add a new default
method j.l.Appendable#lineSeparator, which by default delegates to
System.lineSeparator().
This allows classes such as PrintWriter/BufferedWriter to provide
overrides which
communicate to j.u.Formatter their intended behavior.
In the bug report then I assume the inconsistency only arises because
the test case attempts to change the line separator in the main method,
which is too late. It should work if set on the command-line but this of
course sets it system-wide.
Your proposal to add a lineSeperator() method to Appendable would allow
for customization but I'm not sure that it's the right place (as
Appendable is a very general interface and would require every
Appendable implementation that writes lines to be updated to make use of
the new method).
An alternative to consider is adding the notion of lines to
java.io.Writer and update it to define newLine() and lineSeperator()
methods (i.e. move the BufferWriter::newLine method up to Writer). It's
a bit of extra work to update BufferedWriter's spec, adjust a few things
in PrintWriter/PrintStream, and special-case Writers in Formatter but
something to consider.
-Alan