pre-RFR (s): 8049847: Enhance PrintWriter line.separator handling
Claes Redestad
claes.redestad at oracle.com
Fri Jan 2 15:38:44 UTC 2015
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.
This indirectly provides a way to control the lineSeparator by
allowing users to
override PrintWriter or similar in custom classes which override
lineSeparator, e.g.:
PrintWriter unixPrintWriter = new PrintWriter(out) {
@Override
public String lineSeparator() { return "\n"; }
};
PrintWriter windowsPrintWriter = new PrintWriter(out) {
@Override
public String lineSeparator() { return "\r\n"; }
};
Bonus: This approach can be used to optimize j.l.Throwable to get rid
of all static
inner classes to wrap PrintWriter/PrintStream and instead use
j.l.Appendable, which
more than enough will mitigate the startup hit adding a method to
Appendable will incur.
bug: https://bugs.openjdk.java.net/browse/JDK-8049847
webrev: http://cr.openjdk.java.net/~redestad/8049847/webrev.00/
I've not filed requests to change the public API just yet, rather
wanted to throw this out
for preview to see if there's some concern and feedback first.
/Claes
More information about the core-libs-dev
mailing list