mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8276970: Default charset for PrintWriter that wraps PrintStream
Reviewed-by: rriggs, alanb
This commit is contained in:
parent
29e552c03a
commit
231fb61aae
4 changed files with 133 additions and 9 deletions
|
@ -118,7 +118,8 @@ public class PrintWriter extends Writer {
|
|||
* Creates a new PrintWriter, without automatic line flushing, from an
|
||||
* existing OutputStream. This convenience constructor creates the
|
||||
* necessary intermediate OutputStreamWriter, which will convert characters
|
||||
* into bytes using the default charset.
|
||||
* into bytes using the default charset, or where {@code out} is a
|
||||
* {@code PrintStream}, the charset used by the print stream.
|
||||
*
|
||||
* @param out An output stream
|
||||
*
|
||||
|
@ -132,8 +133,9 @@ public class PrintWriter extends Writer {
|
|||
/**
|
||||
* Creates a new PrintWriter from an existing OutputStream. This
|
||||
* convenience constructor creates the necessary intermediate
|
||||
* OutputStreamWriter, which will convert characters into bytes using the
|
||||
* default charset.
|
||||
* OutputStreamWriter, which will convert characters into bytes using
|
||||
* the default charset, or where {@code out} is a {@code PrintStream},
|
||||
* the charset used by the print stream.
|
||||
*
|
||||
* @param out An output stream
|
||||
* @param autoFlush A boolean; if true, the {@code println},
|
||||
|
@ -144,7 +146,7 @@ public class PrintWriter extends Writer {
|
|||
* @see Charset#defaultCharset()
|
||||
*/
|
||||
public PrintWriter(OutputStream out, boolean autoFlush) {
|
||||
this(out, autoFlush, Charset.defaultCharset());
|
||||
this(out, autoFlush, out instanceof PrintStream ps ? ps.charset() : Charset.defaultCharset());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue