src/java.base/share/classes/java/io/PrintWriter.java
author jlahoda
Mon, 30 Apr 2018 15:03:08 +0200
changeset 49924 84d0fe3cefd4
parent 48252 77b88d8f8380
child 55259 61fff1345ee6
permissions -rw-r--r--
8202105: Console echo is disabled when exiting jshell Summary: Preserving original terminal echo state when Console.readPassword finishes. Reviewed-by: sherman, martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
     2
 * Copyright (c) 1996, 2017, 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
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    28
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Formatter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Locale;
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    31
import java.nio.charset.Charset;
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    32
import java.nio.charset.IllegalCharsetNameException;
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    33
import java.nio.charset.UnsupportedCharsetException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Prints formatted representations of objects to a text-output stream.  This
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
    37
 * class implements all of the {@code print} methods found in {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * PrintStream}.  It does not contain methods for writing raw bytes, for which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * a program should use unencoded byte streams.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p> Unlike the {@link PrintStream} class, if automatic flushing is enabled
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
    42
 * it will be done only when one of the {@code println}, {@code printf}, or
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
    43
 * {@code format} methods is invoked, rather than whenever a newline character
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * happens to be output.  These methods use the platform's own notion of line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * separator rather than the newline character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p> Methods in this class never throw I/O exceptions, although some of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * constructors may.  The client may inquire as to whether any errors have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * occurred by invoking {@link #checkError checkError()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    51
 * <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
    52
 * the charset's default replacement string.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    53
 * 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
    54
 * control over the encoding process is required.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
    55
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @author      Frank Yellin
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author      Mark Reinhold
24865
09b1d992ca72 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents: 14342
diff changeset
    58
 * @since       1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public class PrintWriter extends Writer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * The underlying character-output stream of this
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
    65
     * {@code PrintWriter}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    protected Writer out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    71
    private final boolean autoFlush;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private boolean trouble = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    private Formatter formatter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private PrintStream psOut = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    77
     * 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
    78
     * @throws NullPointerException          is csn is null
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    79
     * @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
    80
     */
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    81
    private static Charset toCharset(String csn)
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    82
        throws UnsupportedEncodingException
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    83
    {
8166
13423c0952ad 7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents: 7966
diff changeset
    84
        Objects.requireNonNull(csn, "charsetName");
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    85
        try {
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    86
            return Charset.forName(csn);
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    87
        } catch (IllegalCharsetNameException|UnsupportedCharsetException unused) {
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    88
            // UnsupportedEncodingException should be thrown
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    89
            throw new UnsupportedEncodingException(csn);
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    90
        }
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
    91
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Creates a new PrintWriter, without automatic line flushing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param  out        A character-output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public PrintWriter (Writer out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this(out, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Creates a new PrintWriter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param  out        A character-output stream
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   106
     * @param  autoFlush  A boolean; if true, the {@code println},
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   107
     *                    {@code printf}, or {@code format} methods will
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *                    flush the output buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public PrintWriter(Writer out,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                       boolean autoFlush) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        super(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        this.out = out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        this.autoFlush = autoFlush;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Creates a new PrintWriter, without automatic line flushing, from an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * existing OutputStream.  This convenience constructor creates the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * necessary intermediate OutputStreamWriter, which will convert characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * into bytes using the default character encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param  out        An output stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @see java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public PrintWriter(OutputStream out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        this(out, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Creates a new PrintWriter from an existing OutputStream.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * convenience constructor creates the necessary intermediate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * OutputStreamWriter, which will convert characters into bytes using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * default character encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param  out        An output stream
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   138
     * @param  autoFlush  A boolean; if true, the {@code println},
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   139
     *                    {@code printf}, or {@code format} methods will
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *                    flush the output buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @see java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public PrintWriter(OutputStream out, boolean autoFlush) {
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   145
        this(out, autoFlush, Charset.defaultCharset());
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   146
    }
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   147
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   148
    /**
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   149
     * Creates a new PrintWriter from an existing OutputStream.  This
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   150
     * convenience constructor creates the necessary intermediate
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   151
     * OutputStreamWriter, which will convert characters into bytes using the
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   152
     * specified charset.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   153
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   154
     * @param  out        An output stream
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   155
     * @param  autoFlush  A boolean; if true, the {@code println},
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   156
     *                    {@code printf}, or {@code format} methods will
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   157
     *                    flush the output buffer
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   158
     * @param  charset
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   159
     *         A {@linkplain java.nio.charset.Charset charset}
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   160
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   161
     * @since 10
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   162
     */
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   163
    public PrintWriter(OutputStream out, boolean autoFlush, Charset charset) {
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   164
        this(new BufferedWriter(new OutputStreamWriter(out, charset)), autoFlush);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        // save print stream for error propagation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (out instanceof java.io.PrintStream) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            psOut = (PrintStream) out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Creates a new PrintWriter, without automatic line flushing, with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * specified file name.  This convenience constructor creates the necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * intermediate {@link java.io.OutputStreamWriter OutputStreamWriter},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * which will encode characters using the {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * java.nio.charset.Charset#defaultCharset() default charset} for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * instance of the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param  fileName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *         The name of the file to use as the destination of this writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *         If the file exists then it will be truncated to zero size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *         otherwise, a new file will be created.  The output will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *         written to the file and is buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @throws  FileNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *          If the given string does not denote an existing, writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *          regular file and a new regular file of that name cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *          created, or if some other error occurs while opening or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *          creating the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *          If a security manager is present and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *          SecurityManager#checkWrite checkWrite(fileName)} denies write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *          access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public PrintWriter(String fileName) throws FileNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        this(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName))),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
             false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   204
    /* Private constructor */
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   205
    private PrintWriter(Charset charset, File file)
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   206
        throws FileNotFoundException
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   207
    {
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   208
        this(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), charset)),
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   209
             false);
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   210
    }
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   211
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Creates a new PrintWriter, without automatic line flushing, with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * specified file name and charset.  This convenience constructor creates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * the necessary intermediate {@link java.io.OutputStreamWriter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * OutputStreamWriter}, which will encode characters using the provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * charset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param  fileName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *         The name of the file to use as the destination of this writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *         If the file exists then it will be truncated to zero size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *         otherwise, a new file will be created.  The output will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *         written to the file and is buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param  csn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *         The name of a supported {@linkplain java.nio.charset.Charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *         charset}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @throws  FileNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *          If the given string does not denote an existing, writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *          regular file and a new regular file of that name cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *          created, or if some other error occurs while opening or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *          creating the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *          If a security manager is present and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *          SecurityManager#checkWrite checkWrite(fileName)} denies write
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *          access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @throws  UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *          If the named charset is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public PrintWriter(String fileName, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        throws FileNotFoundException, UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   248
        this(toCharset(csn), new File(fileName));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Creates a new PrintWriter, without automatic line flushing, with the
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   253
     * specified file name and charset.  This convenience constructor creates
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   254
     * the necessary intermediate {@link java.io.OutputStreamWriter
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   255
     * OutputStreamWriter}, which will encode characters using the provided
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   256
     * charset.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   257
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   258
     * @param  fileName
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   259
     *         The name of the file to use as the destination of this writer.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   260
     *         If the file exists then it will be truncated to zero size;
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   261
     *         otherwise, a new file will be created.  The output will be
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   262
     *         written to the file and is buffered.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   263
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   264
     * @param  charset
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   265
     *         A {@linkplain java.nio.charset.Charset charset}
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   266
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   267
     * @throws  IOException
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   268
     *          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
   269
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   270
     * @throws  SecurityException
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   271
     *          If a security manager is present and {@link
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   272
     *          SecurityManager#checkWrite checkWrite(fileName)} denies write
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   273
     *          access to the file
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   274
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   275
     * @since  10
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   276
     */
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   277
    public PrintWriter(String fileName, Charset charset) throws IOException {
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   278
        this(Objects.requireNonNull(charset, "charset"), new File(fileName));
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   279
    }
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
    /**
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   282
     * Creates a new PrintWriter, without automatic line flushing, with the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * specified file.  This convenience constructor creates the necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * intermediate {@link java.io.OutputStreamWriter OutputStreamWriter},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * which will encode characters using the {@linkplain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * java.nio.charset.Charset#defaultCharset() default charset} for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * instance of the Java virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param  file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *         The file to use as the destination of this writer.  If the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *         exists then it will be truncated to zero size; otherwise, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *         file will be created.  The output will be written to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *         and is buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @throws  FileNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *          If the given file object does not denote an existing, writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *          regular file and a new regular file of that name cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *          created, or if some other error occurs while opening or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *          creating the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *          If a security manager is present and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *          SecurityManager#checkWrite checkWrite(file.getPath())}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *          denies write access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public PrintWriter(File file) throws FileNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        this(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
             false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Creates a new PrintWriter, without automatic line flushing, with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * specified file and charset.  This convenience constructor creates the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * necessary intermediate {@link java.io.OutputStreamWriter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * OutputStreamWriter}, which will encode characters using the provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * charset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @param  file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *         The file to use as the destination of this writer.  If the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *         exists then it will be truncated to zero size; otherwise, a new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *         file will be created.  The output will be written to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *         and is buffered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @param  csn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *         The name of a supported {@linkplain java.nio.charset.Charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *         charset}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @throws  FileNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *          If the given file object does not denote an existing, writable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *          regular file and a new regular file of that name cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *          created, or if some other error occurs while opening or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *          creating the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *          If a security manager is present and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *          SecurityManager#checkWrite checkWrite(file.getPath())}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *          denies write access to the file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @throws  UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *          If the named charset is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public PrintWriter(File file, String csn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        throws FileNotFoundException, UnsupportedEncodingException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    {
7966
a23e3f47c5a8 7000511: PrintStream, PrintWriter, Formatter, Scanner leave files open when exception thrown
chegar
parents: 5506
diff changeset
   349
        this(toCharset(csn), file);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
48252
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   352
    /**
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   353
     * Creates a new PrintWriter, without automatic line flushing, with the
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   354
     * specified file and charset.  This convenience constructor creates the
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   355
     * necessary intermediate {@link java.io.OutputStreamWriter
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   356
     * OutputStreamWriter}, which will encode characters using the provided
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   357
     * charset.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   358
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   359
     * @param  file
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   360
     *         The file to use as the destination of this writer.  If the file
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   361
     *         exists then it will be truncated to zero size; otherwise, a new
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   362
     *         file will be created.  The output will be written to the file
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   363
     *         and is buffered.
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   364
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   365
     * @param  charset
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   366
     *         A {@linkplain java.nio.charset.Charset charset}
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   367
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   368
     * @throws  IOException
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   369
     *          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
   370
     *
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   371
     * @throws  SecurityException
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   372
     *          If a security manager is present and {@link
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   373
     *          SecurityManager#checkWrite checkWrite(file.getPath())}
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   374
     *          denies write access to the file
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
     * @since  10
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   377
     */
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   378
    public PrintWriter(File file, Charset charset) throws IOException {
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   379
        this(Objects.requireNonNull(charset, "charset"), file);
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   380
    }
77b88d8f8380 8183743: Umbrella: add overloads that take a Charset parameter
joehw
parents: 47216
diff changeset
   381
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /** Checks to make sure that the stream has not been closed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    private void ensureOpen() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        if (out == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            throw new IOException("Stream closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * Flushes the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @see #checkError()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public void flush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Closes the stream and releases any system resources associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * with it. Closing a previously closed stream has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @see #checkError()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    public void close() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                if (out == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                out = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * Flushes the stream if it's not closed and checks its error state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   427
     * @return {@code true} if the print stream has encountered an error,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *          either on the underlying output stream or during a format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *          conversion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public boolean checkError() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        if (out != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        if (out instanceof java.io.PrintWriter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            PrintWriter pw = (PrintWriter) out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            return pw.checkError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        } else if (psOut != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            return psOut.checkError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return trouble;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Indicates that an error has occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * <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: 28422
diff changeset
   448
     * #checkError()} to return {@code true} until {@link
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * #clearError()} is invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    protected void setError() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Clears the error state of this stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * <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: 28422
diff changeset
   459
     * #checkError()} to return {@code false} until another write
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * operation fails and invokes {@link #setError()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    protected void clearError() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        trouble = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * Exception-catching, synchronized output operations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * which also implement the write() methods of Writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Writes a single character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @param c int specifying a character to be written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public void write(int c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                out.write(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        catch (InterruptedIOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * Writes A Portion of an array of characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @param buf Array of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @param off Offset from which to start writing characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @param len Number of characters to write
38373
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   497
     *
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   498
     * @throws  IndexOutOfBoundsException
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   499
     *          If the values of the {@code off} and {@code len} parameters
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   500
     *          cause the corresponding method of the underlying {@code Writer}
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   501
     *          to throw an {@code IndexOutOfBoundsException}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    public void write(char buf[], int off, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                out.write(buf, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        catch (InterruptedIOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            trouble = true;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * Writes an array of characters.  This method cannot be inherited from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * Writer class because it must suppress I/O exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @param buf Array of characters to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public void write(char buf[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        write(buf, 0, buf.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * Writes a portion of a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @param s A String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @param off Offset from which to start writing characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @param len Number of characters to write
38373
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   532
     *
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   533
     * @throws  IndexOutOfBoundsException
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   534
     *          If the values of the {@code off} and {@code len} parameters
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   535
     *          cause the corresponding method of the underlying {@code Writer}
21f4f5eee7cc 8130679: Writer/StringWriter.write methods do not specify index out bounds
bpb
parents: 32033
diff changeset
   536
     *          to throw an {@code IndexOutOfBoundsException}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public void write(String s, int off, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                out.write(s, off, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        catch (InterruptedIOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * Writes a string.  This method cannot be inherited from the Writer class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * because it must suppress I/O exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @param s String to be written
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    public void write(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        write(s, 0, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    private void newLine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                ensureOpen();
28422
a571480286c5 8068498: Remove constructor dependency on line.separator from PrintWriter and BufferedWriter
redestad
parents: 25859
diff changeset
   566
                out.write(System.lineSeparator());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                if (autoFlush)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                    out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        catch (InterruptedIOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    /* Methods that do not terminate lines */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   582
     * 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: 28422
diff changeset
   583
     * java.lang.String#valueOf(boolean)} is translated into bytes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * according to the platform's default character encoding, and these bytes
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   585
     * 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: 28422
diff changeset
   586
     * #write(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   588
     * @param      b   The {@code boolean} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    public void print(boolean b) {
40410
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38373
diff changeset
   591
        write(String.valueOf(b));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * Prints a character.  The character is translated into one or more bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * according to the platform's default character encoding, and these bytes
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   597
     * 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: 28422
diff changeset
   598
     * #write(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   600
     * @param      c   The {@code char} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    public void print(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        write(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   607
     * 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: 28422
diff changeset
   608
     * java.lang.String#valueOf(int)} is translated into bytes according
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * to the platform's default character encoding, and these bytes are
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   610
     * written in exactly the manner of the {@link #write(int)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   613
     * @param      i   The {@code int} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @see        java.lang.Integer#toString(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    public void print(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        write(String.valueOf(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   621
     * 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: 28422
diff changeset
   622
     * java.lang.String#valueOf(long)} is translated into bytes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * according to the platform's default character encoding, and these bytes
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   624
     * are written in exactly the manner of the {@link #write(int)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   627
     * @param      l   The {@code long} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @see        java.lang.Long#toString(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    public void print(long l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        write(String.valueOf(l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   635
     * 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: 28422
diff changeset
   636
     * java.lang.String#valueOf(float)} is translated into bytes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * according to the platform's default character encoding, and these bytes
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   638
     * are written in exactly the manner of the {@link #write(int)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   641
     * @param      f   The {@code float} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * @see        java.lang.Float#toString(float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    public void print(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        write(String.valueOf(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * 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: 28422
diff changeset
   650
     * {@link java.lang.String#valueOf(double)} is translated into
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * 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: 28422
diff changeset
   652
     * 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: 28422
diff changeset
   653
     * #write(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   655
     * @param      d   The {@code double} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @see        java.lang.Double#toString(double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    public void print(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        write(String.valueOf(d));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * Prints an array of characters.  The characters are converted into bytes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * according to the platform's default character encoding, and these bytes
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   665
     * are written in exactly the manner of the {@link #write(int)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @param      s   The array of chars to be printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   670
     * @throws  NullPointerException  If {@code s} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    public void print(char s[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        write(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   677
     * 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: 28422
diff changeset
   678
     * {@code "null"} is printed.  Otherwise, the string's characters are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * converted into bytes according to the platform's default character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * encoding, and 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: 28422
diff changeset
   681
     * {@link #write(int)} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   683
     * @param      s   The {@code String} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    public void print(String s) {
40410
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38373
diff changeset
   686
        write(String.valueOf(s));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    /**
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   690
     * 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: 28422
diff changeset
   691
     * java.lang.String#valueOf(Object)} method is translated into bytes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * according to the platform's default character encoding, and these bytes
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   693
     * are written in exactly the manner of the {@link #write(int)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   696
     * @param      obj   The {@code Object} to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * @see        java.lang.Object#toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    public void print(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        write(String.valueOf(obj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    /* Methods that do terminate lines */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * Terminates the current line by writing the line separator string.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * 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: 28422
diff changeset
   708
     * {@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: 28422
diff changeset
   709
     * character ({@code '\n'}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    public void println() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        newLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * Prints a boolean value and then terminates the line.  This method behaves
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   717
     * as 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: 28422
diff changeset
   718
     * {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   720
     * @param x the {@code boolean} value to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    public void println(boolean x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            print(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * Prints a character and then terminates 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: 28422
diff changeset
   731
     * though it invokes {@link #print(char)} and then {@link
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   732
     * #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   734
     * @param x the {@code char} value to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    public void println(char x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            print(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * Prints an integer and then terminates 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: 28422
diff changeset
   745
     * though it invokes {@link #print(int)} and then {@link
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   746
     * #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   748
     * @param x the {@code int} value to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    public void println(int x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            print(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * Prints a long integer and then terminates the line.  This method behaves
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   759
     * as 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: 28422
diff changeset
   760
     * {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   762
     * @param x the {@code long} value to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    public void println(long x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            print(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            println();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * Prints a floating-point number and then terminates the line.  This method
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   773
     * behaves as 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: 28422
diff changeset
   774
     * {@link #println()}.
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: 28422
diff changeset
   776
     * @param x the {@code float} value to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    public void println(float x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            print(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * Prints a double-precision floating-point number and then terminates the
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   787
     * line.  This method behaves as though it invokes {@link
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   788
     * #print(double)} and then {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   790
     * @param x the {@code double} value to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    public void println(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            print(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * Prints an array of characters and then terminates the line.  This method
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   801
     * behaves as 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: 28422
diff changeset
   802
     * {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   804
     * @param x the array of {@code char} values to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    public void println(char x[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            print(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * Prints a String and then terminates 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: 28422
diff changeset
   815
     * 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: 28422
diff changeset
   816
     * {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   818
     * @param x the {@code String} value to be printed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    public void println(String x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            print(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * Prints an Object and then terminates the line.  This method calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * at first String.valueOf(x) to get the printed object's string value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * then behaves as
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   831
     * 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: 28422
diff changeset
   832
     * {@link #println()}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   834
     * @param x  The {@code Object} to be printed.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    public void println(Object x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        String s = String.valueOf(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            print(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * A convenience method to write a formatted string to this writer using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * the specified format string and arguments.  If automatic flushing is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * enabled, calls to this method will flush the output buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   849
     * <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: 28422
diff changeset
   850
     * {@code out.printf(format, args)}
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   851
     * behaves in exactly the same way as the invocation
2
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: 28422
diff changeset
   853
     * <pre>{@code
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   854
     *     out.format(format, args)
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   855
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @param  format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     *         A format string as described in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     *         href="../util/Formatter.html#syntax">Format string syntax</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @param  args
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     *         Arguments referenced by the format specifiers in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     *         string.  If there are more arguments than format specifiers, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     *         extra arguments are ignored.  The number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     *         variable and may be zero.  The maximum number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     *         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
   867
     *         <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
   868
     *         The behaviour on a
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   869
     *         {@code null} argument depends on the <a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     *         href="../util/Formatter.html#syntax">conversion</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     *
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 9266
diff changeset
   872
     * @throws  java.util.IllegalFormatException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     *          If a format string contains an illegal syntax, a format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     *          specifier that is incompatible with the given arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     *          insufficient arguments given the format string, or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     *          illegal conditions.  For specification of all possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     *          formatting errors, see the <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     *          href="../util/Formatter.html#detail">Details</a> section of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     *          formatter class specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * @throws  NullPointerException
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   882
     *          If the {@code format} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @return  This writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    public PrintWriter printf(String format, Object ... args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        return format(format, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * A convenience method to write a formatted string to this writer using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * the specified format string and arguments.  If automatic flushing is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * enabled, calls to this method will flush the output buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   897
     * <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: 28422
diff changeset
   898
     * {@code out.printf(l, format, args)}
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   899
     * behaves in exactly the same way as the invocation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   901
     * <pre>{@code
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   902
     *     out.format(l, format, args)
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   903
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * @param  l
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     *         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: 28422
diff changeset
   907
     *         formatting.  If {@code l} is {@code null} then no localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     *         is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * @param  format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     *         A format string as described in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     *         href="../util/Formatter.html#syntax">Format string syntax</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * @param  args
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     *         Arguments referenced by the format specifiers in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     *         string.  If there are more arguments than format specifiers, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     *         extra arguments are ignored.  The number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     *         variable and may be zero.  The maximum number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     *         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
   920
     *         <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
   921
     *         The behaviour on a
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   922
     *         {@code null} argument depends on the <a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     *         href="../util/Formatter.html#syntax">conversion</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     *
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 9266
diff changeset
   925
     * @throws  java.util.IllegalFormatException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     *          If a format string contains an illegal syntax, a format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     *          specifier that is incompatible with the given arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     *          insufficient arguments given the format string, or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     *          illegal conditions.  For specification of all possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     *          formatting errors, see the <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     *          href="../util/Formatter.html#detail">Details</a> section of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     *          formatter class specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * @throws  NullPointerException
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   935
     *          If the {@code format} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * @return  This writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    public PrintWriter printf(Locale l, String format, Object ... args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        return format(l, format, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * Writes a formatted string to this writer using the specified format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * string and arguments.  If automatic flushing is enabled, calls to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * method will flush the output buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * <p> The locale always used is the one returned by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * java.util.Locale#getDefault() Locale.getDefault()}, regardless of any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * previous invocations of other formatting methods on this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * @param  format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     *         A format string as described in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     *         href="../util/Formatter.html#syntax">Format string syntax</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * @param  args
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     *         Arguments referenced by the format specifiers in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     *         string.  If there are more arguments than format specifiers, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     *         extra arguments are ignored.  The number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     *         variable and may be zero.  The maximum number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     *         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
   964
     *         <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
   965
     *         The behaviour on a
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   966
     *         {@code null} argument depends on the <a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     *         href="../util/Formatter.html#syntax">conversion</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     *
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 9266
diff changeset
   969
     * @throws  java.util.IllegalFormatException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     *          If a format string contains an illegal syntax, a format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     *          specifier that is incompatible with the given arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     *          insufficient arguments given the format string, or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     *          illegal conditions.  For specification of all possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     *          formatting errors, see the <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     *          href="../util/Formatter.html#detail">Details</a> section of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     *          Formatter class specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * @throws  NullPointerException
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
   979
     *          If the {@code format} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * @return  This writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    public PrintWriter format(String format, Object ... args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                if ((formatter == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                    || (formatter.locale() != Locale.getDefault()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                    formatter = new Formatter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                formatter.format(Locale.getDefault(), format, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                if (autoFlush)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                    out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        } catch (InterruptedIOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        } catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * Writes a formatted string to this writer using the specified format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * string and arguments.  If automatic flushing is enabled, calls to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * method will flush the output buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * @param  l
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     *         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: 28422
diff changeset
  1011
     *         formatting.  If {@code l} is {@code null} then no localization
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     *         is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * @param  format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     *         A format string as described in <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     *         href="../util/Formatter.html#syntax">Format string syntax</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * @param  args
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     *         Arguments referenced by the format specifiers in the format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     *         string.  If there are more arguments than format specifiers, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     *         extra arguments are ignored.  The number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     *         variable and may be zero.  The maximum number of arguments is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     *         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
  1024
     *         <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
  1025
     *         The behaviour on a
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1026
     *         {@code null} argument depends on the <a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     *         href="../util/Formatter.html#syntax">conversion</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     *
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 9266
diff changeset
  1029
     * @throws  java.util.IllegalFormatException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     *          If a format string contains an illegal syntax, a format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     *          specifier that is incompatible with the given arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     *          insufficient arguments given the format string, or other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     *          illegal conditions.  For specification of all possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     *          formatting errors, see the <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     *          href="../util/Formatter.html#detail">Details</a> section of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     *          formatter class specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * @throws  NullPointerException
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1039
     *          If the {@code format} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * @return  This writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    public PrintWriter format(Locale l, String format, Object ... args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                ensureOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                if ((formatter == null) || (formatter.locale() != l))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                    formatter = new Formatter(this, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                formatter.format(l, format, args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                if (autoFlush)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                    out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        } catch (InterruptedIOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            Thread.currentThread().interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        } catch (IOException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            trouble = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * Appends the specified character sequence to this writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1066
     * <p> An invocation of this method of the form {@code out.append(csq)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * behaves in exactly the same way as the invocation
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: 28422
diff changeset
  1069
     * <pre>{@code
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1070
     *     out.write(csq.toString())
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1071
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1073
     * <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: 28422
diff changeset
  1074
     * 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: 28422
diff changeset
  1075
     * appended. For instance, invoking the {@code toString} method of a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * character buffer will return a subsequence whose content depends upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * the buffer's position and limit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * @param  csq
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1080
     *         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: 28422
diff changeset
  1081
     *         {@code null}, then the four characters {@code "null"} are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     *         appended to this writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * @return  This writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    public PrintWriter append(CharSequence csq) {
40410
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38373
diff changeset
  1089
        write(String.valueOf(csq));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     * Appends a subsequence of the specified character sequence to this writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1096
     * <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: 28422
diff changeset
  1097
     * {@code out.append(csq, start, end)}
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1098
     * when {@code csq} is not {@code null}, behaves in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1101
     * <pre>{@code
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1102
     *     out.write(csq.subSequence(start, end).toString())
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1103
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * @param  csq
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     *         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: 28422
diff changeset
  1107
     *         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: 28422
diff changeset
  1108
     *         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: 28422
diff changeset
  1109
     *         characters {@code "null"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * @param  start
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     *         The index of the first character in the subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * @param  end
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     *         The index of the character following the last character in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     *         subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * @return  This writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * @throws  IndexOutOfBoundsException
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1121
     *          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: 28422
diff changeset
  1122
     *          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: 28422
diff changeset
  1123
     *          {@code csq.length()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * @since  1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    public PrintWriter append(CharSequence csq, int start, int end) {
40410
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38373
diff changeset
  1128
        if (csq == null) csq = "null";
5fd4a1f809f8 8163517: Various cleanup in java.io code
igerasim
parents: 38373
diff changeset
  1129
        return append(csq.subSequence(start, end));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * Appends the specified character to this writer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1135
     * <p> An invocation of this method of the form {@code out.append(c)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     *
32033
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1138
     * <pre>{@code
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1139
     *     out.write(c)
bf24e33c7919 8132468: docs: replace <tt> tags (obsolete in html5) for java.io, java.lang, java.math
avstepan
parents: 28422
diff changeset
  1140
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * @param  c
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     *         The 16-bit character to append
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * @return  This writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    public PrintWriter append(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        write(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
}