2 * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
28 import java.io.PrintStream.Formatter;
29 import java.nio.charset.Charset;
30 import java.util.Arrays;
33 * Prints formatted representations of objects to a text-output stream. This
34 * class implements all of the <tt>print</tt> methods found in {@link
35 * PrintStream}. It does not contain methods for writing raw bytes, for which
36 * a program should use unencoded byte streams.
38 * <p> Unlike the {@link PrintStream} class, if automatic flushing is enabled
39 * it will be done only when one of the <tt>println</tt>, <tt>printf</tt>, or
40 * <tt>format</tt> methods is invoked, rather than whenever a newline character
41 * happens to be output. These methods use the platform's own notion of line
42 * separator rather than the newline character.
44 * <p> Methods in this class never throw I/O exceptions, although some of its
45 * constructors may. The client may inquire as to whether any errors have
46 * occurred by invoking {@link #checkError checkError()}.
48 * @author Frank Yellin
49 * @author Mark Reinhold
53 public class PrintWriter extends Writer {
56 * The underlying character-output stream of this
57 * <code>PrintWriter</code>.
63 private final boolean autoFlush;
64 private boolean trouble = false;
65 private Formatter formatter;
66 // private PrintStream psOut = null;
69 * Line separator string. This is the value of the line.separator
70 * property at the moment that the stream was created.
72 private final String lineSeparator;
75 * Returns a charset object for the given charset name.
76 * @throws NullPointerException is csn is null
77 * @throws UnsupportedEncodingException if the charset is not supported
79 private static Charset toCharset(String csn)
80 throws UnsupportedEncodingException
82 return PrintStream.toCharset(csn);
86 * Creates a new PrintWriter, without automatic line flushing.
88 * @param out A character-output stream
90 public PrintWriter (Writer out) {
95 * Creates a new PrintWriter.
97 * @param out A character-output stream
98 * @param autoFlush A boolean; if true, the <tt>println</tt>,
99 * <tt>printf</tt>, or <tt>format</tt> methods will
100 * flush the output buffer
102 public PrintWriter(Writer out,
106 this.autoFlush = autoFlush;
107 lineSeparator = "\n";
111 * Creates a new PrintWriter, without automatic line flushing, from an
112 * existing OutputStream. This convenience constructor creates the
113 * necessary intermediate OutputStreamWriter, which will convert characters
114 * into bytes using the default character encoding.
116 * @param out An output stream
118 * @see java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
120 public PrintWriter(OutputStream out) {
125 * Creates a new PrintWriter from an existing OutputStream. This
126 * convenience constructor creates the necessary intermediate
127 * OutputStreamWriter, which will convert characters into bytes using the
128 * default character encoding.
130 * @param out An output stream
131 * @param autoFlush A boolean; if true, the <tt>println</tt>,
132 * <tt>printf</tt>, or <tt>format</tt> methods will
133 * flush the output buffer
135 * @see java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
137 public PrintWriter(OutputStream out, boolean autoFlush) {
138 this(new BufferedWriter(new OutputStreamWriter(out)), autoFlush);
140 // save print stream for error propagation
141 // if (out instanceof java.io.PrintStream) {
142 // psOut = (PrintStream) out;
147 * Creates a new PrintWriter, without automatic line flushing, with the
148 * specified file name. This convenience constructor creates the necessary
149 * intermediate {@link java.io.OutputStreamWriter OutputStreamWriter},
150 * which will encode characters using the {@linkplain
151 * java.nio.charset.Charset#defaultCharset() default charset} for this
152 * instance of the Java virtual machine.
155 * The name of the file to use as the destination of this writer.
156 * If the file exists then it will be truncated to zero size;
157 * otherwise, a new file will be created. The output will be
158 * written to the file and is buffered.
160 * @throws FileNotFoundException
161 * If the given string does not denote an existing, writable
162 * regular file and a new regular file of that name cannot be
163 * created, or if some other error occurs while opening or
166 * @throws SecurityException
167 * If a security manager is present and {@link
168 * SecurityManager#checkWrite checkWrite(fileName)} denies write
173 public PrintWriter(String fileName) throws FileNotFoundException {
175 throw new FileNotFoundException();
178 /* Private constructor */
179 private PrintWriter(Charset charset, File file)
180 throws FileNotFoundException
183 throw new FileNotFoundException();
187 * Creates a new PrintWriter, without automatic line flushing, with the
188 * specified file name and charset. This convenience constructor creates
189 * the necessary intermediate {@link java.io.OutputStreamWriter
190 * OutputStreamWriter}, which will encode characters using the provided
194 * The name of the file to use as the destination of this writer.
195 * If the file exists then it will be truncated to zero size;
196 * otherwise, a new file will be created. The output will be
197 * written to the file and is buffered.
200 * The name of a supported {@linkplain java.nio.charset.Charset
203 * @throws FileNotFoundException
204 * If the given string does not denote an existing, writable
205 * regular file and a new regular file of that name cannot be
206 * created, or if some other error occurs while opening or
209 * @throws SecurityException
210 * If a security manager is present and {@link
211 * SecurityManager#checkWrite checkWrite(fileName)} denies write
214 * @throws UnsupportedEncodingException
215 * If the named charset is not supported
219 public PrintWriter(String fileName, String csn)
220 throws FileNotFoundException, UnsupportedEncodingException
222 this(toCharset(csn), new File(fileName));
226 * Creates a new PrintWriter, without automatic line flushing, with the
227 * specified file. This convenience constructor creates the necessary
228 * intermediate {@link java.io.OutputStreamWriter OutputStreamWriter},
229 * which will encode characters using the {@linkplain
230 * java.nio.charset.Charset#defaultCharset() default charset} for this
231 * instance of the Java virtual machine.
234 * The file to use as the destination of this writer. If the file
235 * exists then it will be truncated to zero size; otherwise, a new
236 * file will be created. The output will be written to the file
239 * @throws FileNotFoundException
240 * If the given file object does not denote an existing, writable
241 * regular file and a new regular file of that name cannot be
242 * created, or if some other error occurs while opening or
245 * @throws SecurityException
246 * If a security manager is present and {@link
247 * SecurityManager#checkWrite checkWrite(file.getPath())}
248 * denies write access to the file
252 public PrintWriter(File file) throws FileNotFoundException {
254 throw new FileNotFoundException();
258 * Creates a new PrintWriter, without automatic line flushing, with the
259 * specified file and charset. This convenience constructor creates the
260 * necessary intermediate {@link java.io.OutputStreamWriter
261 * OutputStreamWriter}, which will encode characters using the provided
265 * The file to use as the destination of this writer. If the file
266 * exists then it will be truncated to zero size; otherwise, a new
267 * file will be created. The output will be written to the file
271 * The name of a supported {@linkplain java.nio.charset.Charset
274 * @throws FileNotFoundException
275 * If the given file object does not denote an existing, writable
276 * regular file and a new regular file of that name cannot be
277 * created, or if some other error occurs while opening or
280 * @throws SecurityException
281 * If a security manager is present and {@link
282 * SecurityManager#checkWrite checkWrite(file.getPath())}
283 * denies write access to the file
285 * @throws UnsupportedEncodingException
286 * If the named charset is not supported
290 public PrintWriter(File file, String csn)
291 throws FileNotFoundException, UnsupportedEncodingException
293 this(toCharset(csn), file);
296 /** Checks to make sure that the stream has not been closed */
297 private void ensureOpen() throws IOException {
299 throw new IOException("Stream closed");
303 * Flushes the stream.
306 public void flush() {
308 synchronized (lock) {
313 catch (IOException x) {
319 * Closes the stream and releases any system resources associated
320 * with it. Closing a previously closed stream has no effect.
324 public void close() {
326 synchronized (lock) {
333 catch (IOException x) {
339 * Flushes the stream if it's not closed and checks its error state.
341 * @return <code>true</code> if the print stream has encountered an error,
342 * either on the underlying output stream or during a format
345 public boolean checkError() {
349 if (out instanceof java.io.PrintWriter) {
350 PrintWriter pw = (PrintWriter) out;
351 return pw.checkError();
353 // if (psOut != null) {
354 // return psOut.checkError();
360 * Indicates that an error has occurred.
362 * <p> This method will cause subsequent invocations of {@link
363 * #checkError()} to return <tt>true</tt> until {@link
364 * #clearError()} is invoked.
366 protected void setError() {
371 * Clears the error state of this stream.
373 * <p> This method will cause subsequent invocations of {@link
374 * #checkError()} to return <tt>false</tt> until another write
375 * operation fails and invokes {@link #setError()}.
379 protected void clearError() {
384 * Exception-catching, synchronized output operations,
385 * which also implement the write() methods of Writer
389 * Writes a single character.
390 * @param c int specifying a character to be written.
392 public void write(int c) {
394 synchronized (lock) {
399 catch (InterruptedIOException x) {
400 Thread.currentThread().interrupt();
402 catch (IOException x) {
408 * Writes A Portion of an array of characters.
409 * @param buf Array of characters
410 * @param off Offset from which to start writing characters
411 * @param len Number of characters to write
413 public void write(char buf[], int off, int len) {
415 synchronized (lock) {
417 out.write(buf, off, len);
420 catch (InterruptedIOException x) {
421 Thread.currentThread().interrupt();
423 catch (IOException x) {
429 * Writes an array of characters. This method cannot be inherited from the
430 * Writer class because it must suppress I/O exceptions.
431 * @param buf Array of characters to be written
433 public void write(char buf[]) {
434 write(buf, 0, buf.length);
438 * Writes a portion of a string.
440 * @param off Offset from which to start writing characters
441 * @param len Number of characters to write
443 public void write(String s, int off, int len) {
445 synchronized (lock) {
447 out.write(s, off, len);
450 catch (InterruptedIOException x) {
451 Thread.currentThread().interrupt();
453 catch (IOException x) {
459 * Writes a string. This method cannot be inherited from the Writer class
460 * because it must suppress I/O exceptions.
461 * @param s String to be written
463 public void write(String s) {
464 write(s, 0, s.length());
467 private void newLine() {
469 synchronized (lock) {
471 out.write(lineSeparator);
476 catch (InterruptedIOException x) {
477 Thread.currentThread().interrupt();
479 catch (IOException x) {
484 /* Methods that do not terminate lines */
487 * Prints a boolean value. The string produced by <code>{@link
488 * java.lang.String#valueOf(boolean)}</code> is translated into bytes
489 * according to the platform's default character encoding, and these bytes
490 * are written in exactly the manner of the <code>{@link
491 * #write(int)}</code> method.
493 * @param b The <code>boolean</code> to be printed
495 public void print(boolean b) {
496 write(b ? "true" : "false");
500 * Prints a character. The character is translated into one or more bytes
501 * according to the platform's default character encoding, and these bytes
502 * are written in exactly the manner of the <code>{@link
503 * #write(int)}</code> method.
505 * @param c The <code>char</code> to be printed
507 public void print(char c) {
512 * Prints an integer. The string produced by <code>{@link
513 * java.lang.String#valueOf(int)}</code> is translated into bytes according
514 * to the platform's default character encoding, and these bytes are
515 * written in exactly the manner of the <code>{@link #write(int)}</code>
518 * @param i The <code>int</code> to be printed
519 * @see java.lang.Integer#toString(int)
521 public void print(int i) {
522 write(String.valueOf(i));
526 * Prints a long integer. The string produced by <code>{@link
527 * java.lang.String#valueOf(long)}</code> is translated into bytes
528 * according to the platform's default character encoding, and these bytes
529 * are written in exactly the manner of the <code>{@link #write(int)}</code>
532 * @param l The <code>long</code> to be printed
533 * @see java.lang.Long#toString(long)
535 public void print(long l) {
536 write(String.valueOf(l));
540 * Prints a floating-point number. The string produced by <code>{@link
541 * java.lang.String#valueOf(float)}</code> is translated into bytes
542 * according to the platform's default character encoding, and these bytes
543 * are written in exactly the manner of the <code>{@link #write(int)}</code>
546 * @param f The <code>float</code> to be printed
547 * @see java.lang.Float#toString(float)
549 public void print(float f) {
550 write(String.valueOf(f));
554 * Prints a double-precision floating-point number. The string produced by
555 * <code>{@link java.lang.String#valueOf(double)}</code> is translated into
556 * bytes according to the platform's default character encoding, and these
557 * bytes are written in exactly the manner of the <code>{@link
558 * #write(int)}</code> method.
560 * @param d The <code>double</code> to be printed
561 * @see java.lang.Double#toString(double)
563 public void print(double d) {
564 write(String.valueOf(d));
568 * Prints an array of characters. The characters are converted into bytes
569 * according to the platform's default character encoding, and these bytes
570 * are written in exactly the manner of the <code>{@link #write(int)}</code>
573 * @param s The array of chars to be printed
575 * @throws NullPointerException If <code>s</code> is <code>null</code>
577 public void print(char s[]) {
582 * Prints a string. If the argument is <code>null</code> then the string
583 * <code>"null"</code> is printed. Otherwise, the string's characters are
584 * converted into bytes according to the platform's default character
585 * encoding, and these bytes are written in exactly the manner of the
586 * <code>{@link #write(int)}</code> method.
588 * @param s The <code>String</code> to be printed
590 public void print(String s) {
598 * Prints an object. The string produced by the <code>{@link
599 * java.lang.String#valueOf(Object)}</code> method is translated into bytes
600 * according to the platform's default character encoding, and these bytes
601 * are written in exactly the manner of the <code>{@link #write(int)}</code>
604 * @param obj The <code>Object</code> to be printed
605 * @see java.lang.Object#toString()
607 public void print(Object obj) {
608 write(String.valueOf(obj));
611 /* Methods that do terminate lines */
614 * Terminates the current line by writing the line separator string. The
615 * line separator string is defined by the system property
616 * <code>line.separator</code>, and is not necessarily a single newline
617 * character (<code>'\n'</code>).
619 public void println() {
624 * Prints a boolean value and then terminates the line. This method behaves
625 * as though it invokes <code>{@link #print(boolean)}</code> and then
626 * <code>{@link #println()}</code>.
628 * @param x the <code>boolean</code> value to be printed
630 public void println(boolean x) {
631 synchronized (lock) {
638 * Prints a character and then terminates the line. This method behaves as
639 * though it invokes <code>{@link #print(char)}</code> and then <code>{@link
640 * #println()}</code>.
642 * @param x the <code>char</code> value to be printed
644 public void println(char x) {
645 synchronized (lock) {
652 * Prints an integer and then terminates the line. This method behaves as
653 * though it invokes <code>{@link #print(int)}</code> and then <code>{@link
654 * #println()}</code>.
656 * @param x the <code>int</code> value to be printed
658 public void println(int x) {
659 synchronized (lock) {
666 * Prints a long integer and then terminates the line. This method behaves
667 * as though it invokes <code>{@link #print(long)}</code> and then
668 * <code>{@link #println()}</code>.
670 * @param x the <code>long</code> value to be printed
672 public void println(long x) {
673 synchronized (lock) {
680 * Prints a floating-point number and then terminates the line. This method
681 * behaves as though it invokes <code>{@link #print(float)}</code> and then
682 * <code>{@link #println()}</code>.
684 * @param x the <code>float</code> value to be printed
686 public void println(float x) {
687 synchronized (lock) {
694 * Prints a double-precision floating-point number and then terminates the
695 * line. This method behaves as though it invokes <code>{@link
696 * #print(double)}</code> and then <code>{@link #println()}</code>.
698 * @param x the <code>double</code> value to be printed
700 public void println(double x) {
701 synchronized (lock) {
708 * Prints an array of characters and then terminates the line. This method
709 * behaves as though it invokes <code>{@link #print(char[])}</code> and then
710 * <code>{@link #println()}</code>.
712 * @param x the array of <code>char</code> values to be printed
714 public void println(char x[]) {
715 synchronized (lock) {
722 * Prints a String and then terminates the line. This method behaves as
723 * though it invokes <code>{@link #print(String)}</code> and then
724 * <code>{@link #println()}</code>.
726 * @param x the <code>String</code> value to be printed
728 public void println(String x) {
729 synchronized (lock) {
736 * Prints an Object and then terminates the line. This method calls
737 * at first String.valueOf(x) to get the printed object's string value,
739 * though it invokes <code>{@link #print(String)}</code> and then
740 * <code>{@link #println()}</code>.
742 * @param x The <code>Object</code> to be printed.
744 public void println(Object x) {
745 String s = String.valueOf(x);
746 synchronized (lock) {
753 * A convenience method to write a formatted string to this writer using
754 * the specified format string and arguments. If automatic flushing is
755 * enabled, calls to this method will flush the output buffer.
757 * <p> An invocation of this method of the form <tt>out.printf(format,
758 * args)</tt> behaves in exactly the same way as the invocation
761 * out.format(format, args) </pre>
764 * A format string as described in <a
765 * href="../util/Formatter.html#syntax">Format string syntax</a>.
768 * Arguments referenced by the format specifiers in the format
769 * string. If there are more arguments than format specifiers, the
770 * extra arguments are ignored. The number of arguments is
771 * variable and may be zero. The maximum number of arguments is
772 * limited by the maximum dimension of a Java array as defined by
773 * <cite>The Java™ Virtual Machine Specification</cite>.
775 * <tt>null</tt> argument depends on the <a
776 * href="../util/Formatter.html#syntax">conversion</a>.
778 * @throws IllegalFormatException
779 * If a format string contains an illegal syntax, a format
780 * specifier that is incompatible with the given arguments,
781 * insufficient arguments given the format string, or other
782 * illegal conditions. For specification of all possible
783 * formatting errors, see the <a
784 * href="../util/Formatter.html#detail">Details</a> section of the
785 * formatter class specification.
787 * @throws NullPointerException
788 * If the <tt>format</tt> is <tt>null</tt>
790 * @return This writer
794 public PrintWriter printf(String format, Object ... args) {
795 return format(format, args);
799 * A convenience method to write a formatted string to this writer using
800 * the specified format string and arguments. If automatic flushing is
801 * enabled, calls to this method will flush the output buffer.
803 * <p> An invocation of this method of the form <tt>out.printf(l, format,
804 * args)</tt> behaves in exactly the same way as the invocation
807 * out.format(l, format, args) </pre>
810 * The {@linkplain java.util.Locale locale} to apply during
811 * formatting. If <tt>l</tt> is <tt>null</tt> then no localization
815 * A format string as described in <a
816 * href="../util/Formatter.html#syntax">Format string syntax</a>.
819 * Arguments referenced by the format specifiers in the format
820 * string. If there are more arguments than format specifiers, the
821 * extra arguments are ignored. The number of arguments is
822 * variable and may be zero. The maximum number of arguments is
823 * limited by the maximum dimension of a Java array as defined by
824 * <cite>The Java™ Virtual Machine Specification</cite>.
826 * <tt>null</tt> argument depends on the <a
827 * href="../util/Formatter.html#syntax">conversion</a>.
829 * @throws IllegalFormatException
830 * If a format string contains an illegal syntax, a format
831 * specifier that is incompatible with the given arguments,
832 * insufficient arguments given the format string, or other
833 * illegal conditions. For specification of all possible
834 * formatting errors, see the <a
835 * href="../util/Formatter.html#detail">Details</a> section of the
836 * formatter class specification.
838 * @throws NullPointerException
839 * If the <tt>format</tt> is <tt>null</tt>
841 * @return This writer
845 // public PrintWriter printf(Locale l, String format, Object ... args) {
846 // return format(l, format, args);
850 * Writes a formatted string to this writer using the specified format
851 * string and arguments. If automatic flushing is enabled, calls to this
852 * method will flush the output buffer.
854 * <p> The locale always used is the one returned by {@link
855 * java.util.Locale#getDefault() Locale.getDefault()}, regardless of any
856 * previous invocations of other formatting methods on this object.
859 * A format string as described in <a
860 * href="../util/Formatter.html#syntax">Format string syntax</a>.
863 * Arguments referenced by the format specifiers in the format
864 * string. If there are more arguments than format specifiers, the
865 * extra arguments are ignored. The number of arguments is
866 * variable and may be zero. The maximum number of arguments is
867 * limited by the maximum dimension of a Java array as defined by
868 * <cite>The Java™ Virtual Machine Specification</cite>.
870 * <tt>null</tt> argument depends on the <a
871 * href="../util/Formatter.html#syntax">conversion</a>.
873 * @throws IllegalFormatException
874 * If a format string contains an illegal syntax, a format
875 * specifier that is incompatible with the given arguments,
876 * insufficient arguments given the format string, or other
877 * illegal conditions. For specification of all possible
878 * formatting errors, see the <a
879 * href="../util/Formatter.html#detail">Details</a> section of the
880 * Formatter class specification.
882 * @throws NullPointerException
883 * If the <tt>format</tt> is <tt>null</tt>
885 * @return This writer
889 public PrintWriter format(String format, Object ... args) {
890 append(format).append(Arrays.toString(args));
895 * Writes a formatted string to this writer using the specified format
896 * string and arguments. If automatic flushing is enabled, calls to this
897 * method will flush the output buffer.
900 * The {@linkplain java.util.Locale locale} to apply during
901 * formatting. If <tt>l</tt> is <tt>null</tt> then no localization
905 * A format string as described in <a
906 * href="../util/Formatter.html#syntax">Format string syntax</a>.
909 * Arguments referenced by the format specifiers in the format
910 * string. If there are more arguments than format specifiers, the
911 * extra arguments are ignored. The number of arguments is
912 * variable and may be zero. The maximum number of arguments is
913 * limited by the maximum dimension of a Java array as defined by
914 * <cite>The Java™ Virtual Machine Specification</cite>.
916 * <tt>null</tt> argument depends on the <a
917 * href="../util/Formatter.html#syntax">conversion</a>.
919 * @throws IllegalFormatException
920 * If a format string contains an illegal syntax, a format
921 * specifier that is incompatible with the given arguments,
922 * insufficient arguments given the format string, or other
923 * illegal conditions. For specification of all possible
924 * formatting errors, see the <a
925 * href="../util/Formatter.html#detail">Details</a> section of the
926 * formatter class specification.
928 * @throws NullPointerException
929 * If the <tt>format</tt> is <tt>null</tt>
931 * @return This writer
935 // public PrintWriter format(Locale l, String format, Object ... args) {
936 // return format(format, args);
940 * Appends the specified character sequence to this writer.
942 * <p> An invocation of this method of the form <tt>out.append(csq)</tt>
943 * behaves in exactly the same way as the invocation
946 * out.write(csq.toString()) </pre>
948 * <p> Depending on the specification of <tt>toString</tt> for the
949 * character sequence <tt>csq</tt>, the entire sequence may not be
950 * appended. For instance, invoking the <tt>toString</tt> method of a
951 * character buffer will return a subsequence whose content depends upon
952 * the buffer's position and limit.
955 * The character sequence to append. If <tt>csq</tt> is
956 * <tt>null</tt>, then the four characters <tt>"null"</tt> are
957 * appended to this writer.
959 * @return This writer
963 public PrintWriter append(CharSequence csq) {
967 write(csq.toString());
972 * Appends a subsequence of the specified character sequence to this writer.
974 * <p> An invocation of this method of the form <tt>out.append(csq, start,
975 * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
976 * exactly the same way as the invocation
979 * out.write(csq.subSequence(start, end).toString()) </pre>
982 * The character sequence from which a subsequence will be
983 * appended. If <tt>csq</tt> is <tt>null</tt>, then characters
984 * will be appended as if <tt>csq</tt> contained the four
985 * characters <tt>"null"</tt>.
988 * The index of the first character in the subsequence
991 * The index of the character following the last character in the
994 * @return This writer
996 * @throws IndexOutOfBoundsException
997 * If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
998 * is greater than <tt>end</tt>, or <tt>end</tt> is greater than
999 * <tt>csq.length()</tt>
1003 public PrintWriter append(CharSequence csq, int start, int end) {
1004 CharSequence cs = (csq == null ? "null" : csq);
1005 write(cs.subSequence(start, end).toString());
1010 * Appends the specified character to this writer.
1012 * <p> An invocation of this method of the form <tt>out.append(c)</tt>
1013 * behaves in exactly the same way as the invocation
1016 * out.write(c) </pre>
1019 * The 16-bit character to append
1021 * @return This writer
1025 public PrintWriter append(char c) {