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

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -198,16 +198,17 @@ public class ByteArrayOutputStream extends OutputStream {
/**
* Converts the buffer's contents into a string decoding bytes using the
* platform's default character set. The length of the new {@code String}
* is a function of the character set, and hence may not be equal to the
* default charset. The length of the new {@code String}
* is a function of the charset, and hence may not be equal to the
* size of the buffer.
*
* <p> This method always replaces malformed-input and unmappable-character
* sequences with the default replacement string for the platform's
* default character set. The {@linkplain java.nio.charset.CharsetDecoder}
* sequences with the default replacement string for the
* default charset. The {@linkplain java.nio.charset.CharsetDecoder}
* class should be used when more control over the decoding process is
* required.
*
* @see Charset#defaultCharset()
* @return String decoded from the buffer's contents.
* @since 1.1
*/
@ -217,10 +218,10 @@ public class ByteArrayOutputStream extends OutputStream {
/**
* Converts the buffer's contents into a string by decoding the bytes using
* the named {@link java.nio.charset.Charset charset}.
* the named {@link Charset charset}.
*
* <p> This method is equivalent to {@code #toString(charset)} that takes a
* {@link java.nio.charset.Charset charset}.
* {@link Charset charset}.
*
* <p> An invocation of this method of the form
*
@ -240,7 +241,7 @@ public class ByteArrayOutputStream extends OutputStream {
*
*
* @param charsetName the name of a supported
* {@link java.nio.charset.Charset charset}
* {@link Charset charset}
* @return String decoded from the buffer's contents.
* @throws UnsupportedEncodingException
* If the named charset is not supported
@ -254,7 +255,7 @@ public class ByteArrayOutputStream extends OutputStream {
/**
* Converts the buffer's contents into a string by decoding the bytes using
* the specified {@link java.nio.charset.Charset charset}. The length of the new
* the specified {@link Charset charset}. The length of the new
* {@code String} is a function of the charset, and hence may not be equal
* to the length of the byte array.
*
@ -263,7 +264,7 @@ public class ByteArrayOutputStream extends OutputStream {
* java.nio.charset.CharsetDecoder} class should be used when more control
* over the decoding process is required.
*
* @param charset the {@linkplain java.nio.charset.Charset charset}
* @param charset the {@linkplain Charset charset}
* to be used to decode the {@code bytes}
* @return String decoded from the buffer's contents.
* @since 10
@ -286,14 +287,14 @@ public class ByteArrayOutputStream extends OutputStream {
* As of JDK&nbsp;1.1, the preferred way to do this is via the
* {@link #toString(String charsetName)} or {@link #toString(Charset charset)}
* method, which takes an encoding-name or charset argument,
* or the {@code toString()} method, which uses the platform's default
* character encoding.
* or the {@code toString()} method, which uses the default charset.
*
* @param hibyte the high byte of each resulting Unicode character.
* @return the current contents of the output stream, as a string.
* @see java.io.ByteArrayOutputStream#size()
* @see java.io.ByteArrayOutputStream#toString(String)
* @see java.io.ByteArrayOutputStream#toString()
* @see Charset#defaultCharset()
*/
@Deprecated
public synchronized String toString(int hibyte) {

View file

@ -29,6 +29,7 @@ import java.util.*;
import java.nio.charset.Charset;
import jdk.internal.access.JavaIOAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.util.StaticProperty;
import sun.nio.cs.StreamDecoder;
import sun.nio.cs.StreamEncoder;
import sun.security.action.GetPropertyAction;
@ -572,22 +573,34 @@ public final class Console implements Flushable
private static final Charset CHARSET;
static {
String csname = encoding();
Charset cs = null;
if (csname == null) {
csname = GetPropertyAction.privilegedGetProperty("sun.stdout.encoding");
boolean istty = istty();
if (istty) {
String csname = encoding();
if (csname == null) {
csname = GetPropertyAction.privilegedGetProperty("sun.stdout.encoding");
}
if (csname != null) {
try {
cs = Charset.forName(csname);
} catch (Exception ignored) { }
}
}
if (csname != null) {
if (cs == null) {
try {
cs = Charset.forName(csname);
} catch (Exception ignored) { }
cs = Charset.forName(StaticProperty.nativeEncoding());
} catch (Exception ignored) {
cs = Charset.defaultCharset();
}
}
CHARSET = cs == null ? Charset.defaultCharset() : cs;
CHARSET = cs;
// Set up JavaIOAccess in SharedSecrets
SharedSecrets.setJavaIOAccess(new JavaIOAccess() {
public Console console() {
if (istty()) {
if (istty) {
if (cons == null)
cons = new Console();
return cons;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,9 +29,8 @@ import java.nio.charset.Charset;
/**
* Reads text from character files using a default buffer size. Decoding from bytes
* to characters uses either a specified {@linkplain java.nio.charset.Charset charset}
* or the platform's
* {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
* to characters uses either a specified {@linkplain Charset charset}
* or the {@linkplain Charset#defaultCharset() default charset}.
*
* <p>
* The {@code FileReader} is meant for reading streams of characters. For reading
@ -39,6 +38,7 @@ import java.nio.charset.Charset;
*
* @see InputStreamReader
* @see FileInputStream
* @see Charset#defaultCharset()
*
* @author Mark Reinhold
* @since 1.1
@ -47,14 +47,14 @@ public class FileReader extends InputStreamReader {
/**
* Creates a new {@code FileReader}, given the name of the file to read,
* using the platform's
* {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
* using the {@linkplain Charset#defaultCharset() default charset}.
*
* @param fileName the name of the file to read
* @throws FileNotFoundException if the named file does not exist,
* is a directory rather than a regular file,
* or for some other reason cannot be opened for
* reading.
* @see Charset#defaultCharset()
*/
public FileReader(String fileName) throws FileNotFoundException {
super(new FileInputStream(fileName));
@ -62,14 +62,14 @@ public class FileReader extends InputStreamReader {
/**
* Creates a new {@code FileReader}, given the {@code File} to read,
* using the platform's
* {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
* using the {@linkplain Charset#defaultCharset() default charset}.
*
* @param file the {@code File} to read
* @throws FileNotFoundException if the file does not exist,
* is a directory rather than a regular file,
* or for some other reason cannot be opened for
* reading.
* @see Charset#defaultCharset()
*/
public FileReader(File file) throws FileNotFoundException {
super(new FileInputStream(file));
@ -77,10 +77,10 @@ public class FileReader extends InputStreamReader {
/**
* Creates a new {@code FileReader}, given the {@code FileDescriptor} to read,
* using the platform's
* {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
* using the {@linkplain Charset#defaultCharset() default charset}.
*
* @param fd the {@code FileDescriptor} to read
* @see Charset#defaultCharset()
*/
public FileReader(FileDescriptor fd) {
super(new FileInputStream(fd));
@ -88,10 +88,10 @@ public class FileReader extends InputStreamReader {
/**
* Creates a new {@code FileReader}, given the name of the file to read
* and the {@linkplain java.nio.charset.Charset charset}.
* and the {@linkplain Charset charset}.
*
* @param fileName the name of the file to read
* @param charset the {@linkplain java.nio.charset.Charset charset}
* @param charset the {@linkplain Charset charset}
* @throws IOException if the named file does not exist,
* is a directory rather than a regular file,
* or for some other reason cannot be opened for
@ -105,10 +105,10 @@ public class FileReader extends InputStreamReader {
/**
* Creates a new {@code FileReader}, given the {@code File} to read and
* the {@linkplain java.nio.charset.Charset charset}.
* the {@linkplain Charset charset}.
*
* @param file the {@code File} to read
* @param charset the {@linkplain java.nio.charset.Charset charset}
* @param charset the {@linkplain Charset charset}
* @throws IOException if the file does not exist,
* is a directory rather than a regular file,
* or for some other reason cannot be opened for

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,9 +29,8 @@ import java.nio.charset.Charset;
/**
* Writes text to character files using a default buffer size. Encoding from characters
* to bytes uses either a specified {@linkplain java.nio.charset.Charset charset}
* or the platform's
* {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
* to bytes uses either a specified {@linkplain Charset charset}
* or the {@linkplain Charset#defaultCharset() default charset}.
*
* <p>
* Whether or not a file is available or may be created depends upon the
@ -46,6 +45,7 @@ import java.nio.charset.Charset;
*
* @see OutputStreamWriter
* @see FileOutputStream
* @see Charset#defaultCharset()
*
* @author Mark Reinhold
* @since 1.1
@ -54,13 +54,14 @@ import java.nio.charset.Charset;
public class FileWriter extends OutputStreamWriter {
/**
* Constructs a {@code FileWriter} given a file name, using the platform's
* {@linkplain java.nio.charset.Charset#defaultCharset() default charset}
* Constructs a {@code FileWriter} given a file name, using the
* {@linkplain Charset#defaultCharset() default charset}
*
* @param fileName String The system-dependent filename.
* @throws IOException if the named file exists but is a directory rather
* than a regular file, does not exist but cannot be
* created, or cannot be opened for any other reason
* @see Charset#defaultCharset()
*/
public FileWriter(String fileName) throws IOException {
super(new FileOutputStream(fileName));
@ -68,8 +69,8 @@ public class FileWriter extends OutputStreamWriter {
/**
* Constructs a {@code FileWriter} given a file name and a boolean indicating
* whether to append the data written, using the platform's
* {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
* whether to append the data written, using the
* {@linkplain Charset#defaultCharset() default charset}.
*
* @param fileName String The system-dependent filename.
* @param append boolean if {@code true}, then data will be written
@ -77,6 +78,7 @@ public class FileWriter extends OutputStreamWriter {
* @throws IOException if the named file exists but is a directory rather
* than a regular file, does not exist but cannot be
* created, or cannot be opened for any other reason
* @see Charset#defaultCharset()
*/
public FileWriter(String fileName, boolean append) throws IOException {
super(new FileOutputStream(fileName, append));
@ -84,13 +86,13 @@ public class FileWriter extends OutputStreamWriter {
/**
* Constructs a {@code FileWriter} given the {@code File} to write,
* using the platform's
* {@linkplain java.nio.charset.Charset#defaultCharset() default charset}
* using the {@linkplain Charset#defaultCharset() default charset}
*
* @param file the {@code File} to write.
* @throws IOException if the file exists but is a directory rather than
* a regular file, does not exist but cannot be created,
* or cannot be opened for any other reason
* @see Charset#defaultCharset()
*/
public FileWriter(File file) throws IOException {
super(new FileOutputStream(file));
@ -98,8 +100,8 @@ public class FileWriter extends OutputStreamWriter {
/**
* Constructs a {@code FileWriter} given the {@code File} to write and
* a boolean indicating whether to append the data written, using the platform's
* {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
* a boolean indicating whether to append the data written, using the
* {@linkplain Charset#defaultCharset() default charset}.
*
* @param file the {@code File} to write
* @param append if {@code true}, then bytes will be written
@ -107,6 +109,7 @@ public class FileWriter extends OutputStreamWriter {
* @throws IOException if the file exists but is a directory rather than
* a regular file, does not exist but cannot be created,
* or cannot be opened for any other reason
* @see Charset#defaultCharset()
* @since 1.4
*/
public FileWriter(File file, boolean append) throws IOException {
@ -115,10 +118,10 @@ public class FileWriter extends OutputStreamWriter {
/**
* Constructs a {@code FileWriter} given a file descriptor,
* using the platform's
* {@linkplain java.nio.charset.Charset#defaultCharset() default charset}.
* using the {@linkplain Charset#defaultCharset() default charset}.
*
* @param fd the {@code FileDescriptor} to write.
* @see Charset#defaultCharset()
*/
public FileWriter(FileDescriptor fd) {
super(new FileOutputStream(fd));
@ -127,10 +130,10 @@ public class FileWriter extends OutputStreamWriter {
/**
* Constructs a {@code FileWriter} given a file name and
* {@linkplain java.nio.charset.Charset charset}.
* {@linkplain Charset charset}.
*
* @param fileName the name of the file to write
* @param charset the {@linkplain java.nio.charset.Charset charset}
* @param charset the {@linkplain Charset charset}
* @throws IOException if the named file exists but is a directory rather
* than a regular file, does not exist but cannot be
* created, or cannot be opened for any other reason
@ -143,11 +146,11 @@ public class FileWriter extends OutputStreamWriter {
/**
* Constructs a {@code FileWriter} given a file name,
* {@linkplain java.nio.charset.Charset charset} and a boolean indicating
* {@linkplain Charset charset} and a boolean indicating
* whether to append the data written.
*
* @param fileName the name of the file to write
* @param charset the {@linkplain java.nio.charset.Charset charset}
* @param charset the {@linkplain Charset charset}
* @param append a boolean. If {@code true}, the writer will write the data
* to the end of the file rather than the beginning.
* @throws IOException if the named file exists but is a directory rather
@ -162,10 +165,10 @@ public class FileWriter extends OutputStreamWriter {
/**
* Constructs a {@code FileWriter} given the {@code File} to write and
* {@linkplain java.nio.charset.Charset charset}.
* {@linkplain Charset charset}.
*
* @param file the {@code File} to write
* @param charset the {@linkplain java.nio.charset.Charset charset}
* @param charset the {@linkplain Charset charset}
* @throws IOException if the file exists but is a directory rather than
* a regular file, does not exist but cannot be created,
* or cannot be opened for any other reason
@ -178,11 +181,11 @@ public class FileWriter extends OutputStreamWriter {
/**
* Constructs a {@code FileWriter} given the {@code File} to write,
* {@linkplain java.nio.charset.Charset charset} and a boolean indicating
* {@linkplain Charset charset} and a boolean indicating
* whether to append the data written.
*
* @param file the {@code File} to write
* @param charset the {@linkplain java.nio.charset.Charset charset}
* @param charset the {@linkplain Charset charset}
* @param append a boolean. If {@code true}, the writer will write the data
* to the end of the file rather than the beginning.
* @throws IOException if the file exists but is a directory rather than

View file

@ -34,9 +34,9 @@ import sun.nio.cs.StreamDecoder;
/**
* An InputStreamReader is a bridge from byte streams to character streams: It
* reads bytes and decodes them into characters using a specified {@link
* java.nio.charset.Charset charset}. The charset that it uses
* may be specified by name or may be given explicitly, or the platform's
* {@link Charset#defaultCharset() default charset} may be accepted.
* Charset charset}. The charset that it uses
* may be specified by name or may be given explicitly, or the
* {@link Charset#defaultCharset() default charset} may be used.
*
* <p> Each invocation of one of an InputStreamReader's read() methods may
* cause one or more bytes to be read from the underlying byte-input stream.
@ -54,7 +54,7 @@ import sun.nio.cs.StreamDecoder;
*
* @see BufferedReader
* @see InputStream
* @see java.nio.charset.Charset
* @see Charset
*
* @author Mark Reinhold
* @since 1.1
@ -85,8 +85,7 @@ public class InputStreamReader extends Reader {
* An InputStream
*
* @param charsetName
* The name of a supported
* {@link java.nio.charset.Charset charset}
* The name of a supported {@link Charset charset}
*
* @throws UnsupportedEncodingException
* If the named charset is not supported
@ -145,7 +144,7 @@ public class InputStreamReader extends Reader {
* @return The historical name of this encoding, or
* {@code null} if the stream has been closed
*
* @see java.nio.charset.Charset
* @see Charset
*
* @revised 1.4
*/

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,8 +34,8 @@ import sun.nio.cs.StreamEncoder;
/**
* An OutputStreamWriter is a bridge from character streams to byte streams:
* Characters written to it are encoded into bytes using a specified {@link
* java.nio.charset.Charset charset}. The charset that it uses
* may be specified by name or may be given explicitly, or the platform's
* Charset charset}. The charset that it uses
* may be specified by name or may be given explicitly, or the
* default charset may be accepted.
*
* <p> Each invocation of a write() method causes the encoding converter to be
@ -48,7 +48,7 @@ import sun.nio.cs.StreamEncoder;
*
* <pre>
* Writer out
* = new BufferedWriter(new OutputStreamWriter(System.out));
* = new BufferedWriter(new OutputStreamWriter(anOutputStream));
* </pre>
*
* <p> A <i>surrogate pair</i> is a character represented by a sequence of two
@ -62,12 +62,12 @@ import sun.nio.cs.StreamEncoder;
*
* <p> This class always replaces malformed surrogate elements and unmappable
* character sequences with the charset's default <i>substitution sequence</i>.
* The {@linkplain java.nio.charset.CharsetEncoder} class should be used when more
* The {@linkplain CharsetEncoder} class should be used when more
* control over the encoding process is required.
*
* @see BufferedWriter
* @see OutputStream
* @see java.nio.charset.Charset
* @see Charset
*
* @author Mark Reinhold
* @since 1.1
@ -84,8 +84,7 @@ public class OutputStreamWriter extends Writer {
* An OutputStream
*
* @param charsetName
* The name of a supported
* {@link java.nio.charset.Charset charset}
* The name of a supported {@link Charset charset}
*
* @throws UnsupportedEncodingException
* If the named encoding is not supported
@ -103,6 +102,7 @@ public class OutputStreamWriter extends Writer {
* Creates an OutputStreamWriter that uses the default character encoding.
*
* @param out An OutputStream
* @see Charset#defaultCharset()
*/
public OutputStreamWriter(OutputStream out) {
super(out);
@ -161,7 +161,7 @@ public class OutputStreamWriter extends Writer {
* @return The historical name of this encoding, or possibly
* {@code null} if the stream has been closed
*
* @see java.nio.charset.Charset
* @see Charset
*
* @revised 1.4
*/

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));

View file

@ -118,11 +118,12 @@ 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 character encoding.
* into bytes using the default charset.
*
* @param out An output stream
*
* @see java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
* @see OutputStreamWriter#OutputStreamWriter(OutputStream)
* @see Charset#defaultCharset()
*/
public PrintWriter(OutputStream out) {
this(out, false);
@ -132,14 +133,15 @@ 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 character encoding.
* default charset.
*
* @param out An output stream
* @param autoFlush A boolean; if true, the {@code println},
* {@code printf}, or {@code format} methods will
* flush the output buffer
*
* @see java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
* @see OutputStreamWriter#OutputStreamWriter(OutputStream)
* @see Charset#defaultCharset()
*/
public PrintWriter(OutputStream out, boolean autoFlush) {
this(out, autoFlush, Charset.defaultCharset());
@ -156,7 +158,7 @@ public class PrintWriter extends Writer {
* {@code printf}, or {@code format} methods will
* flush the output buffer
* @param charset
* A {@linkplain java.nio.charset.Charset charset}
* A {@linkplain Charset charset}
*
* @since 10
*/
@ -172,9 +174,9 @@ public class PrintWriter extends Writer {
/**
* Creates a new PrintWriter, without automatic line flushing, with the
* specified file name. This convenience constructor creates the necessary
* intermediate {@link java.io.OutputStreamWriter OutputStreamWriter},
* intermediate {@link 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 fileName
@ -193,6 +195,7 @@ public class PrintWriter extends Writer {
* If a security manager is present and {@link
* SecurityManager#checkWrite checkWrite(fileName)} denies write
* access to the file
* @see Charset#defaultCharset()
*
* @since 1.5
*/
@ -212,7 +215,7 @@ public class PrintWriter extends Writer {
/**
* Creates a new PrintWriter, without automatic line flushing, with the
* specified file name and charset. This convenience constructor creates
* the necessary intermediate {@link java.io.OutputStreamWriter
* the necessary intermediate {@link OutputStreamWriter
* OutputStreamWriter}, which will encode characters using the provided
* charset.
*
@ -223,8 +226,7 @@ public class PrintWriter extends Writer {
* 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 string does not denote an existing, writable
@ -251,7 +253,7 @@ public class PrintWriter extends Writer {
/**
* Creates a new PrintWriter, without automatic line flushing, with the
* specified file name and charset. This convenience constructor creates
* the necessary intermediate {@link java.io.OutputStreamWriter
* the necessary intermediate {@link OutputStreamWriter
* OutputStreamWriter}, which will encode characters using the provided
* charset.
*
@ -262,7 +264,7 @@ public class PrintWriter extends Writer {
* 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
@ -281,9 +283,9 @@ public class PrintWriter extends Writer {
/**
* Creates a new PrintWriter, without automatic line flushing, with the
* specified file. This convenience constructor creates the necessary
* intermediate {@link java.io.OutputStreamWriter OutputStreamWriter},
* intermediate {@link 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
@ -302,6 +304,7 @@ public class PrintWriter extends Writer {
* 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
*/
@ -313,7 +316,7 @@ public class PrintWriter extends Writer {
/**
* Creates a new PrintWriter, without automatic line flushing, with the
* specified file and charset. This convenience constructor creates the
* necessary intermediate {@link java.io.OutputStreamWriter
* necessary intermediate {@link OutputStreamWriter
* OutputStreamWriter}, which will encode characters using the provided
* charset.
*
@ -324,8 +327,7 @@ public class PrintWriter extends Writer {
* 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
@ -363,7 +365,7 @@ public class PrintWriter extends Writer {
* 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
@ -580,11 +582,12 @@ public class PrintWriter extends Writer {
/**
* 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));
@ -592,11 +595,12 @@ public class PrintWriter extends Writer {
/**
* Prints a character. The character is translated into one or more 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 c The {@code char} to be printed
* @see Charset#defaultCharset()
*/
public void print(char c) {
write(c);
@ -605,12 +609,13 @@ public class PrintWriter extends Writer {
/**
* 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 are
* 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));
@ -619,12 +624,13 @@ public class PrintWriter extends Writer {
/**
* 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));
@ -633,12 +639,13 @@ public class PrintWriter extends Writer {
/**
* 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));
@ -647,12 +654,13 @@ public class PrintWriter extends Writer {
/**
* 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));
@ -660,11 +668,12 @@ public class PrintWriter extends Writer {
/**
* Prints an array of characters. The characters are converted 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 s The array of chars to be printed
* @see Charset#defaultCharset()
*
* @throws NullPointerException If {@code s} is {@code null}
*/
@ -675,11 +684,12 @@ public class PrintWriter extends Writer {
/**
* 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 platform's default character
* encoding, and these bytes are written in exactly the manner of the
* converted into bytes according to the default charset,
* and 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));
@ -688,12 +698,13 @@ public class PrintWriter extends Writer {
/**
* 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));