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.nio.charset.Charset;
29 import java.util.Arrays;
33 * A <code>PrintStream</code> adds functionality to another output stream,
34 * namely the ability to print representations of various data values
35 * conveniently. Two other features are provided as well. Unlike other output
36 * streams, a <code>PrintStream</code> never throws an
37 * <code>IOException</code>; instead, exceptional situations merely set an
38 * internal flag that can be tested via the <code>checkError</code> method.
39 * Optionally, a <code>PrintStream</code> can be created so as to flush
40 * automatically; this means that the <code>flush</code> method is
41 * automatically invoked after a byte array is written, one of the
42 * <code>println</code> methods is invoked, or a newline character or byte
43 * (<code>'\n'</code>) is written.
45 * <p> All characters printed by a <code>PrintStream</code> are converted into
46 * bytes using the platform's default character encoding. The <code>{@link
47 * PrintWriter}</code> class should be used in situations that require writing
48 * characters rather than bytes.
50 * @author Frank Yellin
51 * @author Mark Reinhold
55 public class PrintStream extends FilterOutputStream
56 implements Appendable, Closeable
59 private final boolean autoFlush;
60 private boolean trouble = false;
61 private Formatter formatter;
64 * Track both the text- and character-output streams, so that their buffers
65 * can be flushed without flushing the entire stream.
67 private BufferedWriter textOut;
68 private OutputStreamWriter charOut;
71 * requireNonNull is explicitly declared here so as not to create an extra
72 * dependency on java.util.Objects.requireNonNull. PrintStream is loaded
73 * early during system initialization.
75 private static <T> T requireNonNull(T obj, String message) {
77 throw new NullPointerException(message);
81 /* Private constructors */
82 private PrintStream(boolean autoFlush, OutputStream out) {
84 this.autoFlush = autoFlush;
85 this.charOut = new OutputStreamWriter(this);
86 this.textOut = new BufferedWriter(charOut);
89 static final class Formatter {
92 static Charset toCharset(String ch) throws UnsupportedEncodingException {
93 if (!"UTF-8".equals(ch)) {
94 throw new UnsupportedEncodingException();
99 private PrintStream(boolean autoFlush, OutputStream out, Charset charset) {
101 this.autoFlush = autoFlush;
102 this.charOut = new OutputStreamWriter(this);
103 this.textOut = new BufferedWriter(charOut);
106 /* Variant of the private constructor so that the given charset name
107 * can be verified before evaluating the OutputStream argument. Used
108 * by constructors creating a FileOutputStream that also take a
111 private PrintStream(boolean autoFlush, Charset charset, OutputStream out)
112 throws UnsupportedEncodingException
114 this(autoFlush, out, charset);
118 * Creates a new print stream. This stream will not flush automatically.
120 * @param out The output stream to which values and objects will be
123 * @see java.io.PrintWriter#PrintWriter(java.io.OutputStream)
125 public PrintStream(OutputStream out) {
130 * Creates a new print stream.
132 * @param out The output stream to which values and objects will be
134 * @param autoFlush A boolean; if true, the output buffer will be flushed
135 * whenever a byte array is written, one of the
136 * <code>println</code> methods is invoked, or a newline
137 * character or byte (<code>'\n'</code>) is written
139 * @see java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean)
141 public PrintStream(OutputStream out, boolean autoFlush) {
142 this(autoFlush, requireNonNull(out, "Null output stream"));
146 * Creates a new print stream.
148 * @param out The output stream to which values and objects will be
150 * @param autoFlush A boolean; if true, the output buffer will be flushed
151 * whenever a byte array is written, one of the
152 * <code>println</code> methods is invoked, or a newline
153 * character or byte (<code>'\n'</code>) is written
154 * @param encoding The name of a supported
155 * <a href="../lang/package-summary.html#charenc">
156 * character encoding</a>
158 * @throws UnsupportedEncodingException
159 * If the named encoding is not supported
163 public PrintStream(OutputStream out, boolean autoFlush, String encoding)
164 throws UnsupportedEncodingException
167 requireNonNull(out, "Null output stream"),
168 toCharset(encoding));
172 * Creates a new print stream, without automatic line flushing, with the
173 * specified file name. This convenience constructor creates
174 * the necessary intermediate {@link java.io.OutputStreamWriter
175 * OutputStreamWriter}, which will encode characters using the
176 * {@linkplain java.nio.charset.Charset#defaultCharset() default charset}
177 * for this instance of the Java virtual machine.
180 * The name of the file to use as the destination of this print
181 * stream. If the file exists, then it will be truncated to
182 * zero size; otherwise, a new file will be created. The output
183 * will be written to the file and is buffered.
185 * @throws FileNotFoundException
186 * If the given file object does not denote an existing, writable
187 * regular file and a new regular file of that name cannot be
188 * created, or if some other error occurs while opening or
191 * @throws SecurityException
192 * If a security manager is present and {@link
193 * SecurityManager#checkWrite checkWrite(fileName)} denies write
198 public PrintStream(String fileName) throws FileNotFoundException {
200 throw new FileNotFoundException();
204 * Creates a new print stream, without automatic line flushing, with the
205 * specified file name and charset. This convenience constructor creates
206 * the necessary intermediate {@link java.io.OutputStreamWriter
207 * OutputStreamWriter}, which will encode characters using the provided
211 * The name of the file to use as the destination of this print
212 * stream. If the file exists, then it will be truncated to
213 * zero size; otherwise, a new file will be created. The output
214 * will be written to the file and is buffered.
217 * The name of a supported {@linkplain java.nio.charset.Charset
220 * @throws FileNotFoundException
221 * If the given file object does not denote an existing, writable
222 * regular file and a new regular file of that name cannot be
223 * created, or if some other error occurs while opening or
226 * @throws SecurityException
227 * If a security manager is present and {@link
228 * SecurityManager#checkWrite checkWrite(fileName)} denies write
231 * @throws UnsupportedEncodingException
232 * If the named charset is not supported
236 public PrintStream(String fileName, String csn)
237 throws FileNotFoundException, UnsupportedEncodingException
240 throw new FileNotFoundException();
244 * Creates a new print stream, without automatic line flushing, with the
245 * specified file. This convenience constructor creates the necessary
246 * intermediate {@link java.io.OutputStreamWriter OutputStreamWriter},
247 * which will encode characters using the {@linkplain
248 * java.nio.charset.Charset#defaultCharset() default charset} for this
249 * instance of the Java virtual machine.
252 * The file to use as the destination of this print stream. If the
253 * file exists, then it will be truncated to zero size; otherwise,
254 * a new file will be created. The output will be written to the
255 * file and is buffered.
257 * @throws FileNotFoundException
258 * If the given file object does not denote an existing, writable
259 * regular file and a new regular file of that name cannot be
260 * created, or if some other error occurs while opening or
263 * @throws SecurityException
264 * If a security manager is present and {@link
265 * SecurityManager#checkWrite checkWrite(file.getPath())}
266 * denies write access to the file
270 public PrintStream(File file) throws FileNotFoundException {
272 throw new FileNotFoundException();
276 * Creates a new print stream, without automatic line flushing, with the
277 * specified file and charset. This convenience constructor creates
278 * the necessary intermediate {@link java.io.OutputStreamWriter
279 * OutputStreamWriter}, which will encode characters using the provided
283 * The file to use as the destination of this print stream. If the
284 * file exists, then it will be truncated to zero size; otherwise,
285 * a new file will be created. The output will be written to the
286 * file and is buffered.
289 * The name of a supported {@linkplain java.nio.charset.Charset
292 * @throws FileNotFoundException
293 * If the given file object does not denote an existing, writable
294 * regular file and a new regular file of that name cannot be
295 * created, or if some other error occurs while opening or
298 * @throws SecurityException
299 * If a security manager is presentand {@link
300 * SecurityManager#checkWrite checkWrite(file.getPath())}
301 * denies write access to the file
303 * @throws UnsupportedEncodingException
304 * If the named charset is not supported
308 public PrintStream(File file, String csn)
309 throws FileNotFoundException, UnsupportedEncodingException
312 throw new FileNotFoundException();
315 /** Check to make sure that the stream has not been closed */
316 private void ensureOpen() throws IOException {
318 throw new IOException("Stream closed");
322 * Flushes the stream. This is done by writing any buffered output bytes to
323 * the underlying output stream and then flushing that stream.
325 * @see java.io.OutputStream#flush()
327 public void flush() {
328 synchronized (this) {
333 catch (IOException x) {
339 private boolean closing = false; /* To avoid recursive closing */
342 * Closes the stream. This is done by flushing the stream and then closing
343 * the underlying output stream.
345 * @see java.io.OutputStream#close()
347 public void close() {
348 synchronized (this) {
355 catch (IOException x) {
366 * Flushes the stream and checks its error state. The internal error state
367 * is set to <code>true</code> when the underlying output stream throws an
368 * <code>IOException</code> other than <code>InterruptedIOException</code>,
369 * and when the <code>setError</code> method is invoked. If an operation
370 * on the underlying output stream throws an
371 * <code>InterruptedIOException</code>, then the <code>PrintStream</code>
372 * converts the exception back into an interrupt by doing:
374 * Thread.currentThread().interrupt();
378 * @return <code>true</code> if and only if this stream has encountered an
379 * <code>IOException</code> other than
380 * <code>InterruptedIOException</code>, or the
381 * <code>setError</code> method has been invoked
383 public boolean checkError() {
386 if (out instanceof java.io.PrintStream) {
387 PrintStream ps = (PrintStream) out;
388 return ps.checkError();
394 * Sets the error state of the stream to <code>true</code>.
396 * <p> This method will cause subsequent invocations of {@link
397 * #checkError()} to return <tt>true</tt> until {@link
398 * #clearError()} is invoked.
402 protected void setError() {
407 * Clears the internal error state of this stream.
409 * <p> This method will cause subsequent invocations of {@link
410 * #checkError()} to return <tt>false</tt> until another write
411 * operation fails and invokes {@link #setError()}.
415 protected void clearError() {
420 * Exception-catching, synchronized output operations,
421 * which also implement the write() methods of OutputStream
425 * Writes the specified byte to this stream. If the byte is a newline and
426 * automatic flushing is enabled then the <code>flush</code> method will be
429 * <p> Note that the byte is written as given; to write a character that
430 * will be translated according to the platform's default character
431 * encoding, use the <code>print(char)</code> or <code>println(char)</code>
434 * @param b The byte to be written
436 * @see #println(char)
438 public void write(int b) {
440 synchronized (this) {
443 if ((b == '\n') && autoFlush)
447 catch (InterruptedIOException x) {
448 Thread.currentThread().interrupt();
450 catch (IOException x) {
456 * Writes <code>len</code> bytes from the specified byte array starting at
457 * offset <code>off</code> to this stream. If automatic flushing is
458 * enabled then the <code>flush</code> method will be invoked.
460 * <p> Note that the bytes will be written as given; to write characters
461 * that will be translated according to the platform's default character
462 * encoding, use the <code>print(char)</code> or <code>println(char)</code>
465 * @param buf A byte array
466 * @param off Offset from which to start taking bytes
467 * @param len Number of bytes to write
469 public void write(byte buf[], int off, int len) {
471 synchronized (this) {
473 out.write(buf, off, len);
478 catch (InterruptedIOException x) {
479 Thread.currentThread().interrupt();
481 catch (IOException x) {
487 * The following private methods on the text- and character-output streams
488 * always flush the stream buffers, so that writes to the underlying byte
489 * stream occur as promptly as with the original PrintStream.
492 private void write(char buf[]) {
494 synchronized (this) {
497 textOut.flushBuffer();
498 charOut.flushBuffer();
500 for (int i = 0; i < buf.length; i++)
506 catch (InterruptedIOException x) {
507 Thread.currentThread().interrupt();
509 catch (IOException x) {
514 private void write(String s) {
516 synchronized (this) {
519 textOut.flushBuffer();
520 charOut.flushBuffer();
521 if (autoFlush && (s.indexOf('\n') >= 0))
525 catch (InterruptedIOException x) {
526 Thread.currentThread().interrupt();
528 catch (IOException x) {
533 private void newLine() {
535 synchronized (this) {
538 textOut.flushBuffer();
539 charOut.flushBuffer();
544 catch (InterruptedIOException x) {
545 Thread.currentThread().interrupt();
547 catch (IOException x) {
552 /* Methods that do not terminate lines */
555 * Prints a boolean value. The string produced by <code>{@link
556 * java.lang.String#valueOf(boolean)}</code> is translated into bytes
557 * according to the platform's default character encoding, and these bytes
558 * are written in exactly the manner of the
559 * <code>{@link #write(int)}</code> method.
561 * @param b The <code>boolean</code> to be printed
563 public void print(boolean b) {
564 write(b ? "true" : "false");
568 * Prints a character. The character is translated into one or more bytes
569 * according to the platform's default character encoding, and these bytes
570 * are written in exactly the manner of the
571 * <code>{@link #write(int)}</code> method.
573 * @param c The <code>char</code> to be printed
575 public void print(char c) {
576 write(String.valueOf(c));
580 * Prints an integer. The string produced by <code>{@link
581 * java.lang.String#valueOf(int)}</code> is translated into bytes
582 * according to the platform's default character encoding, and these bytes
583 * are written in exactly the manner of the
584 * <code>{@link #write(int)}</code> method.
586 * @param i The <code>int</code> to be printed
587 * @see java.lang.Integer#toString(int)
589 public void print(int i) {
590 write(String.valueOf(i));
594 * Prints a long integer. The string produced by <code>{@link
595 * java.lang.String#valueOf(long)}</code> is translated into bytes
596 * according to the platform's default character encoding, and these bytes
597 * are written in exactly the manner of the
598 * <code>{@link #write(int)}</code> method.
600 * @param l The <code>long</code> to be printed
601 * @see java.lang.Long#toString(long)
603 public void print(long l) {
604 write(String.valueOf(l));
608 * Prints a floating-point number. The string produced by <code>{@link
609 * java.lang.String#valueOf(float)}</code> is translated into bytes
610 * according to the platform's default character encoding, and these bytes
611 * are written in exactly the manner of the
612 * <code>{@link #write(int)}</code> method.
614 * @param f The <code>float</code> to be printed
615 * @see java.lang.Float#toString(float)
617 public void print(float f) {
618 write(String.valueOf(f));
622 * Prints a double-precision floating-point number. The string produced by
623 * <code>{@link java.lang.String#valueOf(double)}</code> is translated into
624 * bytes according to the platform's default character encoding, and these
625 * bytes are written in exactly the manner of the <code>{@link
626 * #write(int)}</code> method.
628 * @param d The <code>double</code> to be printed
629 * @see java.lang.Double#toString(double)
631 public void print(double d) {
632 write(String.valueOf(d));
636 * Prints an array of characters. The characters are converted into bytes
637 * according to the platform's default character encoding, and these bytes
638 * are written in exactly the manner of the
639 * <code>{@link #write(int)}</code> method.
641 * @param s The array of chars to be printed
643 * @throws NullPointerException If <code>s</code> is <code>null</code>
645 public void print(char s[]) {
650 * Prints a string. If the argument is <code>null</code> then the string
651 * <code>"null"</code> is printed. Otherwise, the string's characters are
652 * converted into bytes according to the platform's default character
653 * encoding, and these bytes are written in exactly the manner of the
654 * <code>{@link #write(int)}</code> method.
656 * @param s The <code>String</code> to be printed
658 public void print(String s) {
666 * Prints an object. The string produced by the <code>{@link
667 * java.lang.String#valueOf(Object)}</code> method is translated into bytes
668 * according to the platform's default character encoding, and these bytes
669 * are written in exactly the manner of the
670 * <code>{@link #write(int)}</code> method.
672 * @param obj The <code>Object</code> to be printed
673 * @see java.lang.Object#toString()
675 public void print(Object obj) {
676 write(String.valueOf(obj));
680 /* Methods that do terminate lines */
683 * Terminates the current line by writing the line separator string. The
684 * line separator string is defined by the system property
685 * <code>line.separator</code>, and is not necessarily a single newline
686 * character (<code>'\n'</code>).
688 public void println() {
693 * Prints a boolean and then terminate the line. This method behaves as
694 * though it invokes <code>{@link #print(boolean)}</code> and then
695 * <code>{@link #println()}</code>.
697 * @param x The <code>boolean</code> to be printed
699 public void println(boolean x) {
700 synchronized (this) {
707 * Prints a character and then terminate the line. This method behaves as
708 * though it invokes <code>{@link #print(char)}</code> and then
709 * <code>{@link #println()}</code>.
711 * @param x The <code>char</code> to be printed.
713 public void println(char x) {
714 synchronized (this) {
721 * Prints an integer and then terminate the line. This method behaves as
722 * though it invokes <code>{@link #print(int)}</code> and then
723 * <code>{@link #println()}</code>.
725 * @param x The <code>int</code> to be printed.
727 public void println(int x) {
728 synchronized (this) {
735 * Prints a long and then terminate the line. This method behaves as
736 * though it invokes <code>{@link #print(long)}</code> and then
737 * <code>{@link #println()}</code>.
739 * @param x a The <code>long</code> to be printed.
741 public void println(long x) {
742 synchronized (this) {
749 * Prints a float and then terminate the line. This method behaves as
750 * though it invokes <code>{@link #print(float)}</code> and then
751 * <code>{@link #println()}</code>.
753 * @param x The <code>float</code> to be printed.
755 public void println(float x) {
756 synchronized (this) {
763 * Prints a double and then terminate the line. This method behaves as
764 * though it invokes <code>{@link #print(double)}</code> and then
765 * <code>{@link #println()}</code>.
767 * @param x The <code>double</code> to be printed.
769 public void println(double x) {
770 synchronized (this) {
777 * Prints an array of characters and then terminate the line. This method
778 * behaves as though it invokes <code>{@link #print(char[])}</code> and
779 * then <code>{@link #println()}</code>.
781 * @param x an array of chars to print.
783 public void println(char x[]) {
784 synchronized (this) {
791 * Prints a String and then terminate the line. This method behaves as
792 * though it invokes <code>{@link #print(String)}</code> and then
793 * <code>{@link #println()}</code>.
795 * @param x The <code>String</code> to be printed.
797 public void println(String x) {
798 synchronized (this) {
805 * Prints an Object and then terminate the line. This method calls
806 * at first String.valueOf(x) to get the printed object's string value,
808 * though it invokes <code>{@link #print(String)}</code> and then
809 * <code>{@link #println()}</code>.
811 * @param x The <code>Object</code> to be printed.
813 public void println(Object x) {
814 String s = String.valueOf(x);
815 synchronized (this) {
823 * A convenience method to write a formatted string to this output stream
824 * using the specified format string and arguments.
826 * <p> An invocation of this method of the form <tt>out.printf(format,
827 * args)</tt> behaves in exactly the same way as the invocation
830 * out.format(format, args) </pre>
833 * A format string as described in <a
834 * href="../util/Formatter.html#syntax">Format string syntax</a>
837 * Arguments referenced by the format specifiers in the format
838 * string. If there are more arguments than format specifiers, the
839 * extra arguments are ignored. The number of arguments is
840 * variable and may be zero. The maximum number of arguments is
841 * limited by the maximum dimension of a Java array as defined by
842 * <cite>The Java™ Virtual Machine Specification</cite>.
844 * <tt>null</tt> argument depends on the <a
845 * href="../util/Formatter.html#syntax">conversion</a>.
847 * @throws IllegalFormatException
848 * If a format string contains an illegal syntax, a format
849 * specifier that is incompatible with the given arguments,
850 * insufficient arguments given the format string, or other
851 * illegal conditions. For specification of all possible
852 * formatting errors, see the <a
853 * href="../util/Formatter.html#detail">Details</a> section of the
854 * formatter class specification.
856 * @throws NullPointerException
857 * If the <tt>format</tt> is <tt>null</tt>
859 * @return This output stream
863 public PrintStream printf(String format, Object ... args) {
864 append(format).append(Arrays.toString(args));
869 * A convenience method to write a formatted string to this output stream
870 * using the specified format string and arguments.
872 * <p> An invocation of this method of the form <tt>out.printf(l, format,
873 * args)</tt> behaves in exactly the same way as the invocation
876 * out.format(l, format, args) </pre>
879 * The {@linkplain java.util.Locale locale} to apply during
880 * formatting. If <tt>l</tt> is <tt>null</tt> then no localization
884 * A format string as described in <a
885 * href="../util/Formatter.html#syntax">Format string syntax</a>
888 * Arguments referenced by the format specifiers in the format
889 * string. If there are more arguments than format specifiers, the
890 * extra arguments are ignored. The number of arguments is
891 * variable and may be zero. The maximum number of arguments is
892 * limited by the maximum dimension of a Java array as defined by
893 * <cite>The Java™ Virtual Machine Specification</cite>.
895 * <tt>null</tt> argument depends on the <a
896 * href="../util/Formatter.html#syntax">conversion</a>.
898 * @throws IllegalFormatException
899 * If a format string contains an illegal syntax, a format
900 * specifier that is incompatible with the given arguments,
901 * insufficient arguments given the format string, or other
902 * illegal conditions. For specification of all possible
903 * formatting errors, see the <a
904 * href="../util/Formatter.html#detail">Details</a> section of the
905 * formatter class specification.
907 * @throws NullPointerException
908 * If the <tt>format</tt> is <tt>null</tt>
910 * @return This output stream
914 // public PrintStream printf(Locale l, String format, Object ... args) {
915 // return format(l, format, args);
919 * Writes a formatted string to this output stream using the specified
920 * format string and arguments.
922 * <p> The locale always used is the one returned by {@link
923 * java.util.Locale#getDefault() Locale.getDefault()}, regardless of any
924 * previous invocations of other formatting methods on this object.
927 * A format string as described in <a
928 * href="../util/Formatter.html#syntax">Format string syntax</a>
931 * Arguments referenced by the format specifiers in the format
932 * string. If there are more arguments than format specifiers, the
933 * extra arguments are ignored. The number of arguments is
934 * variable and may be zero. The maximum number of arguments is
935 * limited by the maximum dimension of a Java array as defined by
936 * <cite>The Java™ Virtual Machine Specification</cite>.
938 * <tt>null</tt> argument depends on the <a
939 * href="../util/Formatter.html#syntax">conversion</a>.
941 * @throws IllegalFormatException
942 * If a format string contains an illegal syntax, a format
943 * specifier that is incompatible with the given arguments,
944 * insufficient arguments given the format string, or other
945 * illegal conditions. For specification of all possible
946 * formatting errors, see the <a
947 * href="../util/Formatter.html#detail">Details</a> section of the
948 * formatter class specification.
950 * @throws NullPointerException
951 * If the <tt>format</tt> is <tt>null</tt>
953 * @return This output stream
957 // public PrintStream format(String format, Object ... args) {
959 // synchronized (this) {
961 // if ((formatter == null)
962 // || (formatter.locale() != Locale.getDefault()))
963 // formatter = new Formatter((Appendable) this);
964 // formatter.format(Locale.getDefault(), format, args);
966 // } catch (InterruptedIOException x) {
967 // Thread.currentThread().interrupt();
968 // } catch (IOException x) {
975 * Writes a formatted string to this output stream using the specified
976 * format string and arguments.
979 * The {@linkplain java.util.Locale locale} to apply during
980 * formatting. If <tt>l</tt> is <tt>null</tt> then no localization
984 * A format string as described in <a
985 * href="../util/Formatter.html#syntax">Format string syntax</a>
988 * Arguments referenced by the format specifiers in the format
989 * string. If there are more arguments than format specifiers, the
990 * extra arguments are ignored. The number of arguments is
991 * variable and may be zero. The maximum number of arguments is
992 * limited by the maximum dimension of a Java array as defined by
993 * <cite>The Java™ Virtual Machine Specification</cite>.
995 * <tt>null</tt> argument depends on the <a
996 * href="../util/Formatter.html#syntax">conversion</a>.
998 * @throws IllegalFormatException
999 * If a format string contains an illegal syntax, a format
1000 * specifier that is incompatible with the given arguments,
1001 * insufficient arguments given the format string, or other
1002 * illegal conditions. For specification of all possible
1003 * formatting errors, see the <a
1004 * href="../util/Formatter.html#detail">Details</a> section of the
1005 * formatter class specification.
1007 * @throws NullPointerException
1008 * If the <tt>format</tt> is <tt>null</tt>
1010 * @return This output stream
1014 //// public PrintStream format(Locale l, String format, Object ... args) {
1016 //// synchronized (this) {
1018 //// if ((formatter == null)
1019 //// || (formatter.locale() != l))
1020 //// formatter = new Formatter(this, l);
1021 //// formatter.format(l, format, args);
1023 //// } catch (InterruptedIOException x) {
1024 //// Thread.currentThread().interrupt();
1025 //// } catch (IOException x) {
1026 //// trouble = true;
1032 * Appends the specified character sequence to this output stream.
1034 * <p> An invocation of this method of the form <tt>out.append(csq)</tt>
1035 * behaves in exactly the same way as the invocation
1038 * out.print(csq.toString()) </pre>
1040 * <p> Depending on the specification of <tt>toString</tt> for the
1041 * character sequence <tt>csq</tt>, the entire sequence may not be
1042 * appended. For instance, invoking then <tt>toString</tt> method of a
1043 * character buffer will return a subsequence whose content depends upon
1044 * the buffer's position and limit.
1047 * The character sequence to append. If <tt>csq</tt> is
1048 * <tt>null</tt>, then the four characters <tt>"null"</tt> are
1049 * appended to this output stream.
1051 * @return This output stream
1055 public PrintStream append(CharSequence csq) {
1059 print(csq.toString());
1064 * Appends a subsequence of the specified character sequence to this output
1067 * <p> An invocation of this method of the form <tt>out.append(csq, start,
1068 * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
1069 * exactly the same way as the invocation
1072 * out.print(csq.subSequence(start, end).toString()) </pre>
1075 * The character sequence from which a subsequence will be
1076 * appended. If <tt>csq</tt> is <tt>null</tt>, then characters
1077 * will be appended as if <tt>csq</tt> contained the four
1078 * characters <tt>"null"</tt>.
1081 * The index of the first character in the subsequence
1084 * The index of the character following the last character in the
1087 * @return This output stream
1089 * @throws IndexOutOfBoundsException
1090 * If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
1091 * is greater than <tt>end</tt>, or <tt>end</tt> is greater than
1092 * <tt>csq.length()</tt>
1096 public PrintStream append(CharSequence csq, int start, int end) {
1097 CharSequence cs = (csq == null ? "null" : csq);
1098 write(cs.subSequence(start, end).toString());
1103 * Appends the specified character to this output stream.
1105 * <p> An invocation of this method of the form <tt>out.append(c)</tt>
1106 * behaves in exactly the same way as the invocation
1109 * out.print(c) </pre>
1112 * The 16-bit character to append
1114 * @return This output stream
1118 public PrintStream append(char c) {