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