8276970: Default charset for PrintWriter that wraps PrintStream

Reviewed-by: rriggs, alanb
This commit is contained in:
Naoto Sato 2021-11-18 01:12:12 +00:00
parent 29e552c03a
commit 231fb61aae
4 changed files with 133 additions and 9 deletions

View file

@ -99,7 +99,9 @@ public class OutputStreamWriter extends Writer {
}
/**
* Creates an OutputStreamWriter that uses the default character encoding.
* Creates an OutputStreamWriter that uses the default character encoding, or
* where {@code out} is a {@code PrintStream}, the charset used by the print
* stream.
*
* @param out An OutputStream
* @see Charset#defaultCharset()
@ -107,7 +109,7 @@ public class OutputStreamWriter extends Writer {
public OutputStreamWriter(OutputStream out) {
super(out);
se = StreamEncoder.forOutputStreamWriter(out, this,
Charset.defaultCharset());
out instanceof PrintStream ps ? ps.charset() : Charset.defaultCharset());
}
/**