8260265: UTF-8 by Default

Reviewed-by: alanb, rriggs
This commit is contained in:
Naoto Sato 2021-08-30 21:13:59 +00:00
parent 32048536e9
commit 7fc8540907
22 changed files with 385 additions and 201 deletions

View file

@ -45,8 +45,8 @@ import java.nio.charset.UnsupportedCharsetException;
* ({@code '\n'}) is written.
*
* <p> All characters printed by a {@code PrintStream} are converted into
* bytes using the given encoding or charset, or the platform's default
* character encoding if not specified.
* bytes using the given encoding or charset, or the default charset if not
* specified.
* The {@link PrintWriter} class should be used in situations that require
* writing characters rather than bytes.
*
@ -58,6 +58,7 @@ import java.nio.charset.UnsupportedCharsetException;
* @author Frank Yellin
* @author Mark Reinhold
* @since 1.0
* @see Charset#defaultCharset()
*/
public class PrintStream extends FilterOutputStream
@ -123,12 +124,13 @@ public class PrintStream extends FilterOutputStream
/**
* Creates a new print stream, without automatic line flushing, with the
* specified OutputStream. Characters written to the stream are converted
* to bytes using the platform's default character encoding.
* to bytes using the default charset.
*
* @param out The output stream to which values and objects will be
* printed
*
* @see java.io.PrintWriter#PrintWriter(java.io.OutputStream)
* @see Charset#defaultCharset()
*/
public PrintStream(OutputStream out) {
this(out, false);
@ -137,7 +139,7 @@ public class PrintStream extends FilterOutputStream
/**
* Creates a new print stream, with the specified OutputStream and line
* flushing. Characters written to the stream are converted to bytes using
* the platform's default character encoding.
* the default charset.
*
* @param out The output stream to which values and objects will be
* printed
@ -147,6 +149,7 @@ public class PrintStream extends FilterOutputStream
* character or byte ({@code '\n'}) is written
*
* @see java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean)
* @see Charset#defaultCharset()
*/
public PrintStream(OutputStream out, boolean autoFlush) {
this(autoFlush, requireNonNull(out, "Null output stream"));
@ -189,7 +192,7 @@ public class PrintStream extends FilterOutputStream
* whenever a byte array is written, one of the
* {@code println} methods is invoked, or a newline
* character or byte ({@code '\n'}) is written
* @param charset A {@linkplain java.nio.charset.Charset charset}
* @param charset A {@linkplain Charset charset}
*
* @since 10
*/
@ -205,7 +208,7 @@ public class PrintStream extends FilterOutputStream
* specified file name. This convenience constructor creates
* the necessary intermediate {@link java.io.OutputStreamWriter
* OutputStreamWriter}, which will encode characters using the
* {@linkplain java.nio.charset.Charset#defaultCharset() default charset}
* {@linkplain Charset#defaultCharset() default charset}
* for this instance of the Java virtual machine.
*
* @param fileName
@ -224,6 +227,7 @@ public class PrintStream extends FilterOutputStream
* If a security manager is present and {@link
* SecurityManager#checkWrite checkWrite(fileName)} denies write
* access to the file
* @see Charset#defaultCharset()
*
* @since 1.5
*/
@ -245,8 +249,7 @@ public class PrintStream extends FilterOutputStream
* will be written to the file and is buffered.
*
* @param csn
* The name of a supported {@linkplain java.nio.charset.Charset
* charset}
* The name of a supported {@linkplain Charset charset}
*
* @throws FileNotFoundException
* If the given file object does not denote an existing, writable
@ -285,7 +288,7 @@ public class PrintStream extends FilterOutputStream
* will be written to the file and is buffered.
*
* @param charset
* A {@linkplain java.nio.charset.Charset charset}
* A {@linkplain Charset charset}
*
* @throws IOException
* if an I/O error occurs while opening or creating the file
@ -306,7 +309,7 @@ public class PrintStream extends FilterOutputStream
* specified file. This convenience constructor creates the necessary
* intermediate {@link java.io.OutputStreamWriter OutputStreamWriter},
* which will encode characters using the {@linkplain
* java.nio.charset.Charset#defaultCharset() default charset} for this
* Charset#defaultCharset() default charset} for this
* instance of the Java virtual machine.
*
* @param file
@ -325,6 +328,7 @@ public class PrintStream extends FilterOutputStream
* If a security manager is present and {@link
* SecurityManager#checkWrite checkWrite(file.getPath())}
* denies write access to the file
* @see Charset#defaultCharset()
*
* @since 1.5
*/
@ -346,8 +350,7 @@ public class PrintStream extends FilterOutputStream
* file and is buffered.
*
* @param csn
* The name of a supported {@linkplain java.nio.charset.Charset
* charset}
* The name of a supported {@linkplain Charset charset}
*
* @throws FileNotFoundException
* If the given file object does not denote an existing, writable
@ -387,7 +390,7 @@ public class PrintStream extends FilterOutputStream
* file and is buffered.
*
* @param charset
* A {@linkplain java.nio.charset.Charset charset}
* A {@linkplain Charset charset}
*
* @throws IOException
* if an I/O error occurs while opening or creating the file
@ -519,9 +522,8 @@ public class PrintStream extends FilterOutputStream
* invoked on the underlying output stream.
*
* <p> Note that the byte is written as given; to write a character that
* will be translated according to the platform's default character
* encoding, use the {@code print(char)} or {@code println(char)}
* methods.
* will be translated according to the default charset, use the
* {@code print(char)} or {@code println(char)} methods.
*
* @param b The byte to be written
* @see #print(char)
@ -552,9 +554,8 @@ public class PrintStream extends FilterOutputStream
* output stream.
*
* <p> Note that the bytes will be written as given; to write characters
* that will be translated according to the platform's default character
* encoding, use the {@code print(char)} or {@code println(char)}
* methods.
* that will be translated according to the default charset, use the
* {@code print(char)} or {@code println(char)} methods.
*
* @param buf A byte array
* @param off Offset from which to start taking bytes
@ -584,9 +585,8 @@ public class PrintStream extends FilterOutputStream
* invoked on the underlying output stream.
*
* <p> Note that the bytes will be written as given; to write characters
* that will be translated according to the platform's default character
* encoding, use the {@code print(char[])} or {@code println(char[])}
* methods.
* that will be translated according to the default charset, use the
* {@code print(char[])} or {@code println(char[])} methods.
*
* @apiNote
* Although declared to throw {@code IOException}, this method never
@ -622,9 +622,8 @@ public class PrintStream extends FilterOutputStream
* will be invoked.
*
* <p> Note that the bytes will be written as given; to write characters
* that will be translated according to the platform's default character
* encoding, use the {@code print(char[])} or {@code println(char[])}
* methods.
* that will be translated according to the default charset, use the
* {@code print(char[])} or {@code println(char[])} methods.
*
* @implSpec
* This method is equivalent to
@ -757,11 +756,12 @@ public class PrintStream extends FilterOutputStream
/**
* Prints a boolean value. The string produced by {@link
* java.lang.String#valueOf(boolean)} is translated into bytes
* according to the platform's default character encoding, and these bytes
* according to the default charset, and these bytes
* are written in exactly the manner of the
* {@link #write(int)} method.
*
* @param b The {@code boolean} to be printed
* @see Charset#defaultCharset()
*/
public void print(boolean b) {
write(String.valueOf(b));
@ -770,10 +770,11 @@ public class PrintStream extends FilterOutputStream
/**
* Prints a character. The character is translated into one or more bytes
* according to the character encoding given to the constructor, or the
* platform's default character encoding if none specified. These bytes
* default charset if none specified. These bytes
* are written in exactly the manner of the {@link #write(int)} method.
*
* @param c The {@code char} to be printed
* @see Charset#defaultCharset()
*/
public void print(char c) {
write(String.valueOf(c));
@ -782,12 +783,13 @@ public class PrintStream extends FilterOutputStream
/**
* Prints an integer. The string produced by {@link
* java.lang.String#valueOf(int)} is translated into bytes
* according to the platform's default character encoding, and these bytes
* according to the default charset, and these bytes
* are written in exactly the manner of the
* {@link #write(int)} method.
*
* @param i The {@code int} to be printed
* @see java.lang.Integer#toString(int)
* @see Charset#defaultCharset()
*/
public void print(int i) {
write(String.valueOf(i));
@ -796,12 +798,13 @@ public class PrintStream extends FilterOutputStream
/**
* Prints a long integer. The string produced by {@link
* java.lang.String#valueOf(long)} is translated into bytes
* according to the platform's default character encoding, and these bytes
* according to the default charset, and these bytes
* are written in exactly the manner of the
* {@link #write(int)} method.
*
* @param l The {@code long} to be printed
* @see java.lang.Long#toString(long)
* @see Charset#defaultCharset()
*/
public void print(long l) {
write(String.valueOf(l));
@ -810,12 +813,13 @@ public class PrintStream extends FilterOutputStream
/**
* Prints a floating-point number. The string produced by {@link
* java.lang.String#valueOf(float)} is translated into bytes
* according to the platform's default character encoding, and these bytes
* according to the default charset, and these bytes
* are written in exactly the manner of the
* {@link #write(int)} method.
*
* @param f The {@code float} to be printed
* @see java.lang.Float#toString(float)
* @see Charset#defaultCharset()
*/
public void print(float f) {
write(String.valueOf(f));
@ -824,12 +828,13 @@ public class PrintStream extends FilterOutputStream
/**
* Prints a double-precision floating-point number. The string produced by
* {@link java.lang.String#valueOf(double)} is translated into
* bytes according to the platform's default character encoding, and these
* bytes according to the default charset, and these
* bytes are written in exactly the manner of the {@link
* #write(int)} method.
*
* @param d The {@code double} to be printed
* @see java.lang.Double#toString(double)
* @see Charset#defaultCharset()
*/
public void print(double d) {
write(String.valueOf(d));
@ -838,10 +843,11 @@ public class PrintStream extends FilterOutputStream
/**
* Prints an array of characters. The characters are converted into bytes
* according to the character encoding given to the constructor, or the
* platform's default character encoding if none specified. These bytes
* default charset if none specified. These bytes
* are written in exactly the manner of the {@link #write(int)} method.
*
* @param s The array of chars to be printed
* @see Charset#defaultCharset()
*
* @throws NullPointerException If {@code s} is {@code null}
*/
@ -853,11 +859,12 @@ public class PrintStream extends FilterOutputStream
* Prints a string. If the argument is {@code null} then the string
* {@code "null"} is printed. Otherwise, the string's characters are
* converted into bytes according to the character encoding given to the
* constructor, or the platform's default character encoding if none
* constructor, or the default charset if none
* specified. These bytes are written in exactly the manner of the
* {@link #write(int)} method.
*
* @param s The {@code String} to be printed
* @see Charset#defaultCharset()
*/
public void print(String s) {
write(String.valueOf(s));
@ -866,12 +873,13 @@ public class PrintStream extends FilterOutputStream
/**
* Prints an object. The string produced by the {@link
* java.lang.String#valueOf(Object)} method is translated into bytes
* according to the platform's default character encoding, and these bytes
* according to the default charset, and these bytes
* are written in exactly the manner of the
* {@link #write(int)} method.
*
* @param obj The {@code Object} to be printed
* @see java.lang.Object#toString()
* @see Charset#defaultCharset()
*/
public void print(Object obj) {
write(String.valueOf(obj));