src/java.base/share/classes/java/io/PrintStream.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58027 930551e8ac62
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
55727
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
     2
 * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.io;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Formatter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Locale;
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    30
import java.nio.charset.Charset;
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    31
import java.nio.charset.IllegalCharsetNameException;
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    32
import java.nio.charset.UnsupportedCharsetException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
    35
 * A {@code PrintStream} adds functionality to another output stream,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * namely the ability to print representations of various data values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * conveniently.  Two other features are provided as well.  Unlike other output
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
    38
 * streams, a {@code PrintStream} never throws an
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
    39
 * {@code IOException}; instead, exceptional situations merely set an
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
    40
 * internal flag that can be tested via the {@code checkError} method.
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
    41
 * Optionally, a {@code PrintStream} can be created so as to flush
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
    42
 * automatically; this means that the {@code flush} method is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * automatically invoked after a byte array is written, one of the
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
    44
 * {@code println} methods is invoked, or a newline character or byte
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
    45
 * ({@code '\n'}) is written.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
    47
 * <p> All characters printed by a {@code PrintStream} are converted into
55727
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
    48
 * bytes using the given encoding or charset, or the platform's default
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
    49
 * character encoding if not specified.
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
    50
 * The {@link PrintWriter} class should be used in situations that require
55727
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
    51
 * writing characters rather than bytes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    53
 * <p> This class always replaces malformed and unmappable character sequences with
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    54
 * the charset's default replacement string.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    55
 * The {@linkplain java.nio.charset.CharsetEncoder} class should be used when more
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    56
 * control over the encoding process is required.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    57
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author     Frank Yellin
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author     Mark Reinhold
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
    60
 * @since      1.0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public class PrintStream extends FilterOutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    implements Appendable, Closeable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    67
    private final boolean autoFlush;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private boolean trouble = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private Formatter formatter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Track both the text- and character-output streams, so that their buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * can be flushed without flushing the entire stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private BufferedWriter textOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private OutputStreamWriter charOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
8166
13423c0952ad 7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents: 7982
diff changeset
    79
     * requireNonNull is explicitly declared here so as not to create an extra
13423c0952ad 7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents: 7982
diff changeset
    80
     * dependency on java.util.Objects.requireNonNull. PrintStream is loaded
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    81
     * early during system initialization.
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    82
     */
8166
13423c0952ad 7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents: 7982
diff changeset
    83
    private static <T> T requireNonNull(T obj, String message) {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    84
        if (obj == null)
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    85
            throw new NullPointerException(message);
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    86
        return obj;
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    87
    }
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    88
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    89
    /**
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    90
     * Returns a charset object for the given charset name.
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    91
     * @throws NullPointerException          is csn is null
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    92
     * @throws UnsupportedEncodingException  if the charset is not supported
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    93
     */
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    94
    private static Charset toCharset(String csn)
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    95
        throws UnsupportedEncodingException
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    96
    {
8166
13423c0952ad 7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents: 7982
diff changeset
    97
        requireNonNull(csn, "charsetName");
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    98
        try {
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    99
            return Charset.forName(csn);
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   100
        } catch (IllegalCharsetNameException|UnsupportedCharsetException unused) {
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   101
            // UnsupportedEncodingException should be thrown
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   102
            throw new UnsupportedEncodingException(csn);
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   103
        }
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   104
    }
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   105
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   106
    /* Private constructors */
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   107
    private PrintStream(boolean autoFlush, OutputStream out) {
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   108
        super(out);
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   109
        this.autoFlush = autoFlush;
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   110
        this.charOut = new OutputStreamWriter(this);
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   111
        this.textOut = new BufferedWriter(charOut);
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   112
    }
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   113
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   114
    /* Variant of the private constructor so that the given charset name
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   115
     * can be verified before evaluating the OutputStream argument. Used
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   116
     * by constructors creating a FileOutputStream that also take a
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   117
     * charset name.
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   118
     */
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   119
    private PrintStream(boolean autoFlush, Charset charset, OutputStream out) {
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   120
        this(out, autoFlush, charset);
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   121
    }
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   122
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   123
    /**
55727
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   124
     * Creates a new print stream, without automatic line flushing, with the
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   125
     * specified OutputStream. Characters written to the stream are converted
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   126
     * to bytes using the platform's default character encoding.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param  out        The output stream to which values and objects will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *                    printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @see java.io.PrintWriter#PrintWriter(java.io.OutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public PrintStream(OutputStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        this(out, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
55727
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   138
     * Creates a new print stream, with the specified OutputStream and line
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   139
     * flushing. Characters written to the stream are converted to bytes using
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   140
     * the platform's default character encoding.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param  out        The output stream to which values and objects will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *                    printed
55727
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   144
     * @param  autoFlush  Whether the output buffer will be flushed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *                    whenever a byte array is written, one of the
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   146
     *                    {@code println} methods is invoked, or a newline
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   147
     *                    character or byte ({@code '\n'}) is written
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @see java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public PrintStream(OutputStream out, boolean autoFlush) {
8166
13423c0952ad 7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents: 7982
diff changeset
   152
        this(autoFlush, requireNonNull(out, "Null output stream"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
55727
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   156
     * Creates a new print stream, with the specified OutputStream, line
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   157
     * flushing, and character encoding.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param  out        The output stream to which values and objects will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *                    printed
55727
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   161
     * @param  autoFlush  Whether the output buffer will be flushed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *                    whenever a byte array is written, one of the
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   163
     *                    {@code println} methods is invoked, or a newline
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   164
     *                    character or byte ({@code '\n'}) is written
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @param  encoding   The name of a supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *                    <a href="../lang/package-summary.html#charenc">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *                    character encoding</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @throws  UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *          If the named encoding is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @since  1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public PrintStream(OutputStream out, boolean autoFlush, String encoding)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        throws UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    {
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   177
        this(requireNonNull(out, "Null output stream"), autoFlush, toCharset(encoding));
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   178
    }
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   179
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   180
    /**
55727
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   181
     * Creates a new print stream, with the specified OutputStream, line
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   182
     * flushing and charset.  This convenience constructor creates the necessary
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   183
     * intermediate {@link java.io.OutputStreamWriter OutputStreamWriter},
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   184
     * which will encode characters using the provided charset.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   185
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   186
     * @param  out        The output stream to which values and objects will be
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   187
     *                    printed
55727
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   188
     * @param  autoFlush  Whether the output buffer will be flushed
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   189
     *                    whenever a byte array is written, one of the
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   190
     *                    {@code println} methods is invoked, or a newline
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   191
     *                    character or byte ({@code '\n'}) is written
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   192
     * @param  charset    A {@linkplain java.nio.charset.Charset charset}
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   193
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   194
     * @since  10
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   195
     */
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   196
    public PrintStream(OutputStream out, boolean autoFlush, Charset charset) {
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   197
        super(out);
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   198
        this.autoFlush = autoFlush;
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   199
        this.charOut = new OutputStreamWriter(this, charset);
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   200
        this.textOut = new BufferedWriter(charOut);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Creates a new print stream, without automatic line flushing, with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * specified file name.  This convenience constructor creates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * the necessary intermediate {@link java.io.OutputStreamWriter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * OutputStreamWriter}, which will encode characters using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * for this instance of the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @param  fileName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *         The name of the file to use as the destination of this print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *         stream.  If the file exists, then it will be truncated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *         zero size; otherwise, a new file will be created.  The output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *         will be written to the file and is buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @throws  FileNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *          If the given file object does not denote an existing, writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *          regular file and a new regular file of that name cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *          created, or if some other error occurs while opening or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *          creating the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *          If a security manager is present and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *          SecurityManager#checkWrite checkWrite(fileName)} denies write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *          access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public PrintStream(String fileName) throws FileNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        this(false, new FileOutputStream(fileName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Creates a new print stream, without automatic line flushing, with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * specified file name and charset.  This convenience constructor creates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * the necessary intermediate {@link java.io.OutputStreamWriter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * OutputStreamWriter}, which will encode characters using the provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * charset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param  fileName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *         The name of the file to use as the destination of this print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *         stream.  If the file exists, then it will be truncated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *         zero size; otherwise, a new file will be created.  The output
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *         will be written to the file and is buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @param  csn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *         The name of a supported {@linkplain java.nio.charset.Charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *         charset}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @throws  FileNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *          If the given file object does not denote an existing, writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *          regular file and a new regular file of that name cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *          created, or if some other error occurs while opening or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *          creating the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *          If a security manager is present and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *          SecurityManager#checkWrite checkWrite(fileName)} denies write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *          access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @throws  UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *          If the named charset is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public PrintStream(String fileName, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        throws FileNotFoundException, UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   270
        // ensure charset is checked before the file is opened
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   271
        this(false, toCharset(csn), new FileOutputStream(fileName));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * Creates a new print stream, without automatic line flushing, with the
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   276
     * specified file name and charset.  This convenience constructor creates
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   277
     * the necessary intermediate {@link java.io.OutputStreamWriter
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   278
     * OutputStreamWriter}, which will encode characters using the provided
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   279
     * charset.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   280
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   281
     * @param  fileName
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   282
     *         The name of the file to use as the destination of this print
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   283
     *         stream.  If the file exists, then it will be truncated to
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   284
     *         zero size; otherwise, a new file will be created.  The output
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   285
     *         will be written to the file and is buffered.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   286
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   287
     * @param  charset
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   288
     *         A {@linkplain java.nio.charset.Charset charset}
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   289
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   290
     * @throws  IOException
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   291
     *          if an I/O error occurs while opening or creating the file
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   292
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   293
     * @throws  SecurityException
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   294
     *          If a security manager is present and {@link
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   295
     *          SecurityManager#checkWrite checkWrite(fileName)} denies write
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   296
     *          access to the file
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   297
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   298
     * @since  10
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   299
     */
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   300
    public PrintStream(String fileName, Charset charset) throws IOException {
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   301
        this(false, requireNonNull(charset, "charset"), new FileOutputStream(fileName));
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   302
    }
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   303
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   304
    /**
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   305
     * Creates a new print stream, without automatic line flushing, with the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * specified file.  This convenience constructor creates the necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * intermediate {@link java.io.OutputStreamWriter OutputStreamWriter},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * which will encode characters using the {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * java.nio.charset.Charset#defaultCharset() default charset} for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * instance of the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @param  file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *         The file to use as the destination of this print stream.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *         file exists, then it will be truncated to zero size; otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *         a new file will be created.  The output will be written to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *         file and is buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * @throws  FileNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *          If the given file object does not denote an existing, writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *          regular file and a new regular file of that name cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *          created, or if some other error occurs while opening or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *          creating the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *          If a security manager is present and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *          SecurityManager#checkWrite checkWrite(file.getPath())}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *          denies write access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public PrintStream(File file) throws FileNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        this(false, new FileOutputStream(file));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * Creates a new print stream, without automatic line flushing, with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * specified file and charset.  This convenience constructor creates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * the necessary intermediate {@link java.io.OutputStreamWriter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * OutputStreamWriter}, which will encode characters using the provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * charset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @param  file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *         The file to use as the destination of this print stream.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *         file exists, then it will be truncated to zero size; otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     *         a new file will be created.  The output will be written to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *         file and is buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @param  csn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *         The name of a supported {@linkplain java.nio.charset.Charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *         charset}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @throws  FileNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *          If the given file object does not denote an existing, writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *          regular file and a new regular file of that name cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *          created, or if some other error occurs while opening or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *          creating the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @throws  SecurityException
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 18156
diff changeset
   359
     *          If a security manager is present and {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *          SecurityManager#checkWrite checkWrite(file.getPath())}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *          denies write access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @throws  UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *          If the named charset is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public PrintStream(File file, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        throws FileNotFoundException, UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   371
        // ensure charset is checked before the file is opened
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   372
        this(false, toCharset(csn), new FileOutputStream(file));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   375
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   376
    /**
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   377
     * Creates a new print stream, without automatic line flushing, with the
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   378
     * specified file and charset.  This convenience constructor creates
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   379
     * the necessary intermediate {@link java.io.OutputStreamWriter
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   380
     * OutputStreamWriter}, which will encode characters using the provided
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   381
     * charset.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   382
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   383
     * @param  file
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   384
     *         The file to use as the destination of this print stream.  If the
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   385
     *         file exists, then it will be truncated to zero size; otherwise,
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   386
     *         a new file will be created.  The output will be written to the
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   387
     *         file and is buffered.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   388
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   389
     * @param  charset
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   390
     *         A {@linkplain java.nio.charset.Charset charset}
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   391
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   392
     * @throws  IOException
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   393
     *          if an I/O error occurs while opening or creating the file
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   394
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   395
     * @throws  SecurityException
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   396
     *          If a security manager is present and {@link
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   397
     *          SecurityManager#checkWrite checkWrite(file.getPath())}
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   398
     *          denies write access to the file
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   399
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   400
     * @since  10
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   401
     */
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   402
    public PrintStream(File file, Charset charset) throws IOException {
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   403
        this(false, requireNonNull(charset, "charset"), new FileOutputStream(file));
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   404
    }
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   405
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /** Check to make sure that the stream has not been closed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    private void ensureOpen() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (out == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            throw new IOException("Stream closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Flushes the stream.  This is done by writing any buffered output bytes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * the underlying output stream and then flushing that stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @see        java.io.OutputStream#flush()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     */
58027
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   418
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    public void flush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    private boolean closing = false; /* To avoid recursive closing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * Closes the stream.  This is done by flushing the stream and then closing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * the underlying output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @see        java.io.OutputStream#close()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
58027
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   439
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public void close() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            if (! closing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                closing = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    textOut.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                textOut = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                charOut = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                out = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * Flushes the stream and checks its error state. The internal error state
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   460
     * is set to {@code true} when the underlying output stream throws an
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   461
     * {@code IOException} other than {@code InterruptedIOException},
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   462
     * and when the {@code setError} method is invoked.  If an operation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * on the underlying output stream throws an
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   464
     * {@code InterruptedIOException}, then the {@code PrintStream}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * converts the exception back into an interrupt by doing:
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   466
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *     Thread.currentThread().interrupt();
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   468
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * or the equivalent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   471
     * @return {@code true} if and only if this stream has encountered an
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   472
     *         {@code IOException} other than
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   473
     *         {@code InterruptedIOException}, or the
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   474
     *         {@code setError} method has been invoked
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    public boolean checkError() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (out != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        if (out instanceof java.io.PrintStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            PrintStream ps = (PrintStream) out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            return ps.checkError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return trouble;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   487
     * Sets the error state of the stream to {@code true}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * <p> This method will cause subsequent invocations of {@link
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   490
     * #checkError()} to return {@code true} until
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   491
     * {@link #clearError()} is invoked.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 23010
diff changeset
   493
     * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    protected void setError() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * Clears the internal error state of this stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * <p> This method will cause subsequent invocations of {@link
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   503
     * #checkError()} to return {@code false} until another write
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * operation fails and invokes {@link #setError()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    protected void clearError() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        trouble = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * Exception-catching, synchronized output operations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * which also implement the write() methods of OutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * Writes the specified byte to this stream.  If the byte is a newline and
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   519
     * automatic flushing is enabled then the {@code flush} method will be
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * <p> Note that the byte is written as given; to write a character that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * will be translated according to the platform's default character
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   524
     * encoding, use the {@code print(char)} or {@code println(char)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @param  b  The byte to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @see #print(char)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @see #println(char)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
58027
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   531
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    public void write(int b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                out.write(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                if ((b == '\n') && autoFlush)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        catch (InterruptedIOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   550
     * Writes {@code len} bytes from the specified byte array starting at
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   551
     * offset {@code off} to this stream.  If automatic flushing is
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   552
     * enabled then the {@code flush} method will be invoked.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * <p> Note that the bytes will be written as given; to write characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * that will be translated according to the platform's default character
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   556
     * encoding, use the {@code print(char)} or {@code println(char)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @param  buf   A byte array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @param  off   Offset from which to start taking bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @param  len   Number of bytes to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     */
58027
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   563
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    public void write(byte buf[], int off, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                out.write(buf, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                if (autoFlush)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        catch (InterruptedIOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
58027
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   581
    /**
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   582
     * Writes all bytes from the specified byte array to this stream. If
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   583
     * automatic flushing is enabled then the {@code flush} method will be
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   584
     * invoked.
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   585
     *
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   586
     * <p> Note that the bytes will be written as given; to write characters
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   587
     * that will be translated according to the platform's default character
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   588
     * encoding, use the {@code print(char[])} or {@code println(char[])}
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   589
     * methods.
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   590
     *
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   591
     * @apiNote
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   592
     * Although declared to throw {@code IOException}, this method never
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   593
     * actually does so. Instead, like other methods that this class
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   594
     * overrides, it sets an internal flag which may be tested via the
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   595
     * {@link #checkError()} method. To write an array of bytes without having
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   596
     * to write a {@code catch} block for the {@code IOException}, use either
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   597
     * {@link #writeBytes(byte[] buf) writeBytes(buf)} or
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   598
     * {@link #write(byte[], int, int) write(buf, 0, buf.length)}.
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   599
     *
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   600
     * @implSpec
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   601
     * This method is equivalent to
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   602
     * {@link java.io.PrintStream#write(byte[],int,int)
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   603
     * this.write(buf, 0, buf.length)}.
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   604
     *
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   605
     * @param  buf   A byte array
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   606
     *
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   607
     * @throws IOException If an I/O error occurs.
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   608
     *
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   609
     * @see #writeBytes(byte[])
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   610
     * @see #write(byte[],int,int)
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   611
     *
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   612
     * @since 14
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   613
     */
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   614
    @Override
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   615
    public void write(byte buf[]) throws IOException {
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   616
        this.write(buf, 0, buf.length);
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   617
    }
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   618
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   619
    /**
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   620
     * Writes all bytes from the specified byte array to this stream.
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   621
     * If automatic flushing is enabled then the {@code flush} method
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   622
     * will be invoked.
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   623
     *
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   624
     * <p> Note that the bytes will be written as given; to write characters
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   625
     * that will be translated according to the platform's default character
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   626
     * encoding, use the {@code print(char[])} or {@code println(char[])}
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   627
     * methods.
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   628
     *
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   629
     * @implSpec
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   630
     * This method is equivalent to
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   631
     * {@link #write(byte[], int, int) this.write(buf, 0, buf.length)}.
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   632
     *
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   633
     * @param  buf   A byte array
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   634
     *
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   635
     * @since 14
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   636
     */
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   637
    public void writeBytes(byte buf[]) {
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   638
        this.write(buf, 0, buf.length);
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   639
    }
930551e8ac62 8187898: PrintStream should override FilterOutputStream#write(byte[]) with a method that has no throws clause
bpb
parents: 55727
diff changeset
   640
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * The following private methods on the text- and character-output streams
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * always flush the stream buffers, so that writes to the underlying byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * stream occur as promptly as with the original PrintStream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
53148
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   647
    private void write(char[] buf) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                textOut.write(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                textOut.flushBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                charOut.flushBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                if (autoFlush) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                    for (int i = 0; i < buf.length; i++)
53148
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   656
                        if (buf[i] == '\n') {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                            out.flush();
53148
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   658
                            break;
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   659
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            }
53148
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   662
        } catch (InterruptedIOException x) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   663
            Thread.currentThread().interrupt();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   664
        } catch (IOException x) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   665
            trouble = true;
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   666
        }
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   667
    }
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   668
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   669
    // Used to optimize away back-to-back flushing and synchronization when
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   670
    // using println, but since subclasses could exist which depend on
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   671
    // observing a call to print followed by newLine() we only use this if
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   672
    // getClass() == PrintStream.class to avoid compatibility issues.
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   673
    private void writeln(char[] buf) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   674
        try {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   675
            synchronized (this) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   676
                ensureOpen();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   677
                textOut.write(buf);
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   678
                textOut.newLine();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   679
                textOut.flushBuffer();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   680
                charOut.flushBuffer();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   681
                if (autoFlush)
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   682
                    out.flush();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   683
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        catch (InterruptedIOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    private void write(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                textOut.write(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                textOut.flushBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                charOut.flushBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                if (autoFlush && (s.indexOf('\n') >= 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                    out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        catch (InterruptedIOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
53148
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   712
    // Used to optimize away back-to-back flushing and synchronization when
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   713
    // using println, but since subclasses could exist which depend on
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   714
    // observing a call to print followed by newLine we only use this if
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   715
    // getClass() == PrintStream.class to avoid compatibility issues.
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   716
    private void writeln(String s) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   717
        try {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   718
            synchronized (this) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   719
                ensureOpen();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   720
                textOut.write(s);
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   721
                textOut.newLine();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   722
                textOut.flushBuffer();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   723
                charOut.flushBuffer();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   724
                if (autoFlush)
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   725
                    out.flush();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   726
            }
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   727
        }
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   728
        catch (InterruptedIOException x) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   729
            Thread.currentThread().interrupt();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   730
        }
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   731
        catch (IOException x) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   732
            trouble = true;
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   733
        }
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   734
    }
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   735
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    private void newLine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                textOut.newLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                textOut.flushBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                charOut.flushBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                if (autoFlush)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                    out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        catch (InterruptedIOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    /* Methods that do not terminate lines */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   758
     * Prints a boolean value.  The string produced by {@link
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   759
     * java.lang.String#valueOf(boolean)} is translated into bytes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * according to the platform's default character encoding, and these bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * are written in exactly the manner of the
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   762
     * {@link #write(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   764
     * @param      b   The {@code boolean} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    public void print(boolean b) {
40410
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38786
diff changeset
   767
        write(String.valueOf(b));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * Prints a character.  The character is translated into one or more bytes
55727
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   772
     * according to the character encoding given to the constructor, or the
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   773
     * platform's default character encoding if none specified. These bytes
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   774
     * are written in exactly the manner of the {@link #write(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   776
     * @param      c   The {@code char} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    public void print(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        write(String.valueOf(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   783
     * Prints an integer.  The string produced by {@link
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   784
     * java.lang.String#valueOf(int)} is translated into bytes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * according to the platform's default character encoding, and these bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * are written in exactly the manner of the
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   787
     * {@link #write(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   789
     * @param      i   The {@code int} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * @see        java.lang.Integer#toString(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    public void print(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        write(String.valueOf(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   797
     * Prints a long integer.  The string produced by {@link
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   798
     * java.lang.String#valueOf(long)} is translated into bytes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * according to the platform's default character encoding, and these bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * are written in exactly the manner of the
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   801
     * {@link #write(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   803
     * @param      l   The {@code long} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * @see        java.lang.Long#toString(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    public void print(long l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        write(String.valueOf(l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   811
     * Prints a floating-point number.  The string produced by {@link
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   812
     * java.lang.String#valueOf(float)} is translated into bytes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * according to the platform's default character encoding, and these bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * are written in exactly the manner of the
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   815
     * {@link #write(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   817
     * @param      f   The {@code float} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * @see        java.lang.Float#toString(float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    public void print(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        write(String.valueOf(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * Prints a double-precision floating-point number.  The string produced by
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   826
     * {@link java.lang.String#valueOf(double)} is translated into
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * bytes according to the platform's default character encoding, and these
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   828
     * bytes are written in exactly the manner of the {@link
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   829
     * #write(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   831
     * @param      d   The {@code double} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @see        java.lang.Double#toString(double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    public void print(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        write(String.valueOf(d));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * Prints an array of characters.  The characters are converted into bytes
55727
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   840
     * according to the character encoding given to the constructor, or the
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   841
     * platform's default character encoding if none specified. These bytes
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   842
     * are written in exactly the manner of the {@link #write(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * @param      s   The array of chars to be printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   846
     * @throws  NullPointerException  If {@code s} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    public void print(char s[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        write(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   853
     * Prints a string.  If the argument is {@code null} then the string
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   854
     * {@code "null"} is printed.  Otherwise, the string's characters are
55727
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   855
     * converted into bytes according to the character encoding given to the
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   856
     * constructor, or the platform's default character encoding if none
070ffafc4294 8131664: Javadoc for PrintStream is now incorrect
bpb
parents: 53148
diff changeset
   857
     * specified. These bytes are written in exactly the manner of the
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   858
     * {@link #write(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   860
     * @param      s   The {@code String} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    public void print(String s) {
40410
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38786
diff changeset
   863
        write(String.valueOf(s));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   867
     * Prints an object.  The string produced by the {@link
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   868
     * java.lang.String#valueOf(Object)} method is translated into bytes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * according to the platform's default character encoding, and these bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * are written in exactly the manner of the
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   871
     * {@link #write(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   873
     * @param      obj   The {@code Object} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * @see        java.lang.Object#toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    public void print(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        write(String.valueOf(obj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    /* Methods that do terminate lines */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * Terminates the current line by writing the line separator string.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * line separator string is defined by the system property
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   886
     * {@code line.separator}, and is not necessarily a single newline
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   887
     * character ({@code '\n'}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    public void println() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        newLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * Prints a boolean and then terminate the line.  This method behaves as
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   895
     * though it invokes {@link #print(boolean)} and then
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   896
     * {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   898
     * @param x  The {@code boolean} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    public void println(boolean x) {
53148
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   901
        if (getClass() == PrintStream.class) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   902
            writeln(String.valueOf(x));
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   903
        } else {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   904
            synchronized (this) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   905
                print(x);
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   906
                newLine();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   907
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * Prints a character and then terminate the line.  This method behaves as
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   913
     * though it invokes {@link #print(char)} and then
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   914
     * {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   916
     * @param x  The {@code char} to be printed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    public void println(char x) {
53148
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   919
        if (getClass() == PrintStream.class) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   920
            writeln(String.valueOf(x));
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   921
        } else {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   922
            synchronized (this) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   923
                print(x);
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   924
                newLine();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   925
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * Prints an integer and then terminate the line.  This method behaves as
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   931
     * though it invokes {@link #print(int)} and then
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   932
     * {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   934
     * @param x  The {@code int} to be printed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    public void println(int x) {
53148
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   937
        if (getClass() == PrintStream.class) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   938
            writeln(String.valueOf(x));
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   939
        } else {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   940
            synchronized (this) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   941
                print(x);
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   942
                newLine();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   943
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * Prints a long and then terminate the line.  This method behaves as
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   949
     * though it invokes {@link #print(long)} and then
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   950
     * {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   952
     * @param x  a The {@code long} to be printed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    public void println(long x) {
53148
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   955
        if (getClass() == PrintStream.class) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   956
            writeln(String.valueOf(x));
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   957
        } else {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   958
            synchronized (this) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   959
                print(x);
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   960
                newLine();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   961
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * Prints a float and then terminate the line.  This method behaves as
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   967
     * though it invokes {@link #print(float)} and then
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   968
     * {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   970
     * @param x  The {@code float} to be printed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    public void println(float x) {
53148
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   973
        if (getClass() == PrintStream.class) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   974
            writeln(String.valueOf(x));
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   975
        } else {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   976
            synchronized (this) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   977
                print(x);
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   978
                newLine();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   979
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * Prints a double and then terminate the line.  This method behaves as
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   985
     * though it invokes {@link #print(double)} and then
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   986
     * {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
   988
     * @param x  The {@code double} to be printed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    public void println(double x) {
53148
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   991
        if (getClass() == PrintStream.class) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   992
            writeln(String.valueOf(x));
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   993
        } else {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   994
            synchronized (this) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   995
                print(x);
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   996
                newLine();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
   997
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * Prints an array of characters and then terminate the line.  This method
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1003
     * behaves as though it invokes {@link #print(char[])} and
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1004
     * then {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * @param x  an array of chars to print.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     */
53148
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1008
    public void println(char[] x) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1009
        if (getClass() == PrintStream.class) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1010
            writeln(x);
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1011
        } else {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1012
            synchronized (this) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1013
                print(x);
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1014
                newLine();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1015
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * Prints a String and then terminate the line.  This method behaves as
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1021
     * though it invokes {@link #print(String)} and then
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1022
     * {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1024
     * @param x  The {@code String} to be printed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    public void println(String x) {
53148
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1027
        if (getClass() == PrintStream.class) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1028
            writeln(String.valueOf(x));
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1029
        } else {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1030
            synchronized (this) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1031
                print(x);
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1032
                newLine();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1033
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * Prints an Object and then terminate the line.  This method calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * at first String.valueOf(x) to get the printed object's string value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * then behaves as
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1041
     * though it invokes {@link #print(String)} and then
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1042
     * {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1044
     * @param x  The {@code Object} to be printed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    public void println(Object x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        String s = String.valueOf(x);
53148
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1048
        if (getClass() == PrintStream.class) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1049
            // need to apply String.valueOf again since first invocation
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1050
            // might return null
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1051
            writeln(String.valueOf(s));
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1052
        } else {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1053
            synchronized (this) {
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1054
                print(s);
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1055
                newLine();
17d568776429 8215412: Optimize PrintStream.println methods
redestad
parents: 48252
diff changeset
  1056
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * A convenience method to write a formatted string to this output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * using the specified format string and arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1065
     * <p> An invocation of this method of the form
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1066
     * {@code out.printf(format, args)} behaves
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1067
     * in exactly the same way as the invocation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1069
     * <pre>{@code
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1070
     *     out.format(format, args)
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1071
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * @param  format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     *         A format string as described in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     *         href="../util/Formatter.html#syntax">Format string syntax</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * @param  args
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     *         Arguments referenced by the format specifiers in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     *         string.  If there are more arguments than format specifiers, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     *         extra arguments are ignored.  The number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     *         variable and may be zero.  The maximum number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     *         limited by the maximum dimension of a Java array as defined by
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8166
diff changeset
  1083
     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8166
diff changeset
  1084
     *         The behaviour on a
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1085
     *         {@code null} argument depends on the <a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     *         href="../util/Formatter.html#syntax">conversion</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 9266
diff changeset
  1088
     * @throws  java.util.IllegalFormatException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     *          If a format string contains an illegal syntax, a format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     *          specifier that is incompatible with the given arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     *          insufficient arguments given the format string, or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     *          illegal conditions.  For specification of all possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     *          formatting errors, see the <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     *          href="../util/Formatter.html#detail">Details</a> section of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     *          formatter class specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * @throws  NullPointerException
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1098
     *          If the {@code format} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * @return  This output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    public PrintStream printf(String format, Object ... args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        return format(format, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * A convenience method to write a formatted string to this output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * using the specified format string and arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1112
     * <p> An invocation of this method of the form
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1113
     * {@code out.printf(l, format, args)} behaves
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1114
     * in exactly the same way as the invocation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1116
     * <pre>{@code
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1117
     *     out.format(l, format, args)
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1118
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * @param  l
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     *         The {@linkplain java.util.Locale locale} to apply during
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1122
     *         formatting.  If {@code l} is {@code null} then no localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     *         is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * @param  format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     *         A format string as described in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     *         href="../util/Formatter.html#syntax">Format string syntax</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * @param  args
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     *         Arguments referenced by the format specifiers in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     *         string.  If there are more arguments than format specifiers, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     *         extra arguments are ignored.  The number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     *         variable and may be zero.  The maximum number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     *         limited by the maximum dimension of a Java array as defined by
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8166
diff changeset
  1135
     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8166
diff changeset
  1136
     *         The behaviour on a
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1137
     *         {@code null} argument depends on the <a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     *         href="../util/Formatter.html#syntax">conversion</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 9266
diff changeset
  1140
     * @throws  java.util.IllegalFormatException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     *          If a format string contains an illegal syntax, a format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     *          specifier that is incompatible with the given arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     *          insufficient arguments given the format string, or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     *          illegal conditions.  For specification of all possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     *          formatting errors, see the <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     *          href="../util/Formatter.html#detail">Details</a> section of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     *          formatter class specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * @throws  NullPointerException
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1150
     *          If the {@code format} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * @return  This output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    public PrintStream printf(Locale l, String format, Object ... args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        return format(l, format, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * Writes a formatted string to this output stream using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     * format string and arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * <p> The locale always used is the one returned by {@link
38786
8e7b0ac05815 8146156: Inconsistent default locale in string formatter methods
naoto
parents: 32033
diff changeset
  1165
     * java.util.Locale#getDefault(Locale.Category)} with
8e7b0ac05815 8146156: Inconsistent default locale in string formatter methods
naoto
parents: 32033
diff changeset
  1166
     * {@link java.util.Locale.Category#FORMAT FORMAT} category specified,
8e7b0ac05815 8146156: Inconsistent default locale in string formatter methods
naoto
parents: 32033
diff changeset
  1167
     * regardless of any previous invocations of other formatting methods on
8e7b0ac05815 8146156: Inconsistent default locale in string formatter methods
naoto
parents: 32033
diff changeset
  1168
     * this object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * @param  format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     *         A format string as described in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     *         href="../util/Formatter.html#syntax">Format string syntax</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * @param  args
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     *         Arguments referenced by the format specifiers in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     *         string.  If there are more arguments than format specifiers, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     *         extra arguments are ignored.  The number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     *         variable and may be zero.  The maximum number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     *         limited by the maximum dimension of a Java array as defined by
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8166
diff changeset
  1180
     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8166
diff changeset
  1181
     *         The behaviour on a
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1182
     *         {@code null} argument depends on the <a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     *         href="../util/Formatter.html#syntax">conversion</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 9266
diff changeset
  1185
     * @throws  java.util.IllegalFormatException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     *          If a format string contains an illegal syntax, a format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     *          specifier that is incompatible with the given arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     *          insufficient arguments given the format string, or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     *          illegal conditions.  For specification of all possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     *          formatting errors, see the <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     *          href="../util/Formatter.html#detail">Details</a> section of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     *          formatter class specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * @throws  NullPointerException
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1195
     *          If the {@code format} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     * @return  This output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    public PrintStream format(String format, Object ... args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                if ((formatter == null)
38786
8e7b0ac05815 8146156: Inconsistent default locale in string formatter methods
naoto
parents: 32033
diff changeset
  1206
                    || (formatter.locale() !=
8e7b0ac05815 8146156: Inconsistent default locale in string formatter methods
naoto
parents: 32033
diff changeset
  1207
                        Locale.getDefault(Locale.Category.FORMAT)))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                    formatter = new Formatter((Appendable) this);
38786
8e7b0ac05815 8146156: Inconsistent default locale in string formatter methods
naoto
parents: 32033
diff changeset
  1209
                formatter.format(Locale.getDefault(Locale.Category.FORMAT),
8e7b0ac05815 8146156: Inconsistent default locale in string formatter methods
naoto
parents: 32033
diff changeset
  1210
                                 format, args);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        } catch (InterruptedIOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        } catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     * Writes a formatted string to this output stream using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     * format string and arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * @param  l
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     *         The {@linkplain java.util.Locale locale} to apply during
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1226
     *         formatting.  If {@code l} is {@code null} then no localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     *         is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * @param  format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     *         A format string as described in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     *         href="../util/Formatter.html#syntax">Format string syntax</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * @param  args
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     *         Arguments referenced by the format specifiers in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     *         string.  If there are more arguments than format specifiers, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     *         extra arguments are ignored.  The number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     *         variable and may be zero.  The maximum number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     *         limited by the maximum dimension of a Java array as defined by
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8166
diff changeset
  1239
     *         <cite>The Java&trade; Virtual Machine Specification</cite>.
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 8166
diff changeset
  1240
     *         The behaviour on a
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1241
     *         {@code null} argument depends on the <a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     *         href="../util/Formatter.html#syntax">conversion</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 9266
diff changeset
  1244
     * @throws  java.util.IllegalFormatException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     *          If a format string contains an illegal syntax, a format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     *          specifier that is incompatible with the given arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     *          insufficient arguments given the format string, or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     *          illegal conditions.  For specification of all possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     *          formatting errors, see the <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     *          href="../util/Formatter.html#detail">Details</a> section of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     *          formatter class specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     * @throws  NullPointerException
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1254
     *          If the {@code format} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * @return  This output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    public PrintStream format(Locale l, String format, Object ... args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                if ((formatter == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                    || (formatter.locale() != l))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                    formatter = new Formatter(this, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                formatter.format(l, format, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        } catch (InterruptedIOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        } catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * Appends the specified character sequence to this output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1280
     * <p> An invocation of this method of the form {@code out.append(csq)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1283
     * <pre>{@code
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1284
     *     out.print(csq.toString())
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1285
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1287
     * <p> Depending on the specification of {@code toString} for the
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1288
     * character sequence {@code csq}, the entire sequence may not be
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1289
     * appended.  For instance, invoking then {@code toString} method of a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     * character buffer will return a subsequence whose content depends upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     * the buffer's position and limit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * @param  csq
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1294
     *         The character sequence to append.  If {@code csq} is
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1295
     *         {@code null}, then the four characters {@code "null"} are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     *         appended to this output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * @return  This output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    public PrintStream append(CharSequence csq) {
40410
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38786
diff changeset
  1303
        print(String.valueOf(csq));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * Appends a subsequence of the specified character sequence to this output
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     * stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1311
     * <p> An invocation of this method of the form
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1312
     * {@code out.append(csq, start, end)} when
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1313
     * {@code csq} is not {@code null}, behaves in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     * exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1316
     * <pre>{@code
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1317
     *     out.print(csq.subSequence(start, end).toString())
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1318
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     * @param  csq
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     *         The character sequence from which a subsequence will be
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1322
     *         appended.  If {@code csq} is {@code null}, then characters
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1323
     *         will be appended as if {@code csq} contained the four
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1324
     *         characters {@code "null"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * @param  start
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     *         The index of the first character in the subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     * @param  end
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     *         The index of the character following the last character in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     *         subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
     * @return  This output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     * @throws  IndexOutOfBoundsException
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1336
     *          If {@code start} or {@code end} are negative, {@code start}
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1337
     *          is greater than {@code end}, or {@code end} is greater than
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1338
     *          {@code csq.length()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    public PrintStream append(CharSequence csq, int start, int end) {
40410
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38786
diff changeset
  1343
        if (csq == null) csq = "null";
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38786
diff changeset
  1344
        return append(csq.subSequence(start, end));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * Appends the specified character to this output stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1350
     * <p> An invocation of this method of the form {@code out.append(c)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1353
     * <pre>{@code
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1354
     *     out.print(c)
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 25859
diff changeset
  1355
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     * @param  c
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     *         The 16-bit character to append
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     * @return  This output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    public PrintStream append(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        print(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
}