RFR: JDK-8031482: Some jcmd commands generate output with \n as a line separator instead of \r\n on Windows
David Holmes
david.holmes at oracle.com
Thu Jan 11 22:40:46 UTC 2018
Hi Gary,
On 12/01/2018 2:28 AM, Gary Adams wrote:
> Here's a simple fix to the split pattern when output lines are using
> mixed line separators in the same outputstream . e.g. split("\r\n|\n")
This is rather crude. I'd prefer to see reuse of existing library
classes that already handle all the supported versions of newlines.
BufferedReader does that.
private List<String> asLines(String buffer) {
return new BufferedReader(new
StringReader(buffer)).lines().collect(Collectors.toList());
}
Going forward we could stream-ify outputAnalyzer further. :)
Cheers,
David
-----
import java.util.stream.Collectors;
import java.util.List;
import java.io.BufferedReader;
import java.io.StringReader;
public class Lines {
public static void main(String[] args) {
List<String> l = asLines("Line1\nLine2\r\nLine3\rLine4");
for (String s : l) {
System.out.println(s);
}
}
static private List<String> asLines(String buffer) {
return new BufferedReader(new
StringReader(buffer)).lines().collect(Collectors.toList());
}
}
>
> Issue: https://bugs.openjdk.java.net/browse/JDK-8031482
> Webrev: http://cr.openjdk.java.net/~gadams/JDK-8031482
>
> testing in progress ...
More information about the serviceability-dev
mailing list