jdk/src/java.base/share/classes/java/io/PrintStream.java
changeset 32033 bf24e33c7919
parent 25859 3317bb8137f4
child 38786 8e7b0ac05815
equal deleted inserted replaced
32032:22badc53802f 32033:bf24e33c7919
    30 import java.nio.charset.Charset;
    30 import java.nio.charset.Charset;
    31 import java.nio.charset.IllegalCharsetNameException;
    31 import java.nio.charset.IllegalCharsetNameException;
    32 import java.nio.charset.UnsupportedCharsetException;
    32 import java.nio.charset.UnsupportedCharsetException;
    33 
    33 
    34 /**
    34 /**
    35  * A <code>PrintStream</code> adds functionality to another output stream,
    35  * A {@code PrintStream} adds functionality to another output stream,
    36  * namely the ability to print representations of various data values
    36  * namely the ability to print representations of various data values
    37  * conveniently.  Two other features are provided as well.  Unlike other output
    37  * conveniently.  Two other features are provided as well.  Unlike other output
    38  * streams, a <code>PrintStream</code> never throws an
    38  * streams, a {@code PrintStream} never throws an
    39  * <code>IOException</code>; instead, exceptional situations merely set an
    39  * {@code IOException}; instead, exceptional situations merely set an
    40  * internal flag that can be tested via the <code>checkError</code> method.
    40  * internal flag that can be tested via the {@code checkError} method.
    41  * Optionally, a <code>PrintStream</code> can be created so as to flush
    41  * Optionally, a {@code PrintStream} can be created so as to flush
    42  * automatically; this means that the <code>flush</code> method is
    42  * automatically; this means that the {@code flush} method is
    43  * automatically invoked after a byte array is written, one of the
    43  * automatically invoked after a byte array is written, one of the
    44  * <code>println</code> methods is invoked, or a newline character or byte
    44  * {@code println} methods is invoked, or a newline character or byte
    45  * (<code>'\n'</code>) is written.
    45  * ({@code '\n'}) is written.
    46  *
    46  *
    47  * <p> All characters printed by a <code>PrintStream</code> are converted into
    47  * <p> All characters printed by a {@code PrintStream} are converted into
    48  * bytes using the platform's default character encoding.  The <code>{@link
    48  * bytes using the platform's default character encoding.
    49  * PrintWriter}</code> class should be used in situations that require writing
    49  * The {@link PrintWriter} class should be used in situations that require
    50  * characters rather than bytes.
    50  *  writing characters rather than bytes.
    51  *
    51  *
    52  * @author     Frank Yellin
    52  * @author     Frank Yellin
    53  * @author     Mark Reinhold
    53  * @author     Mark Reinhold
    54  * @since      1.0
    54  * @since      1.0
    55  */
    55  */
   140      *
   140      *
   141      * @param  out        The output stream to which values and objects will be
   141      * @param  out        The output stream to which values and objects will be
   142      *                    printed
   142      *                    printed
   143      * @param  autoFlush  A boolean; if true, the output buffer will be flushed
   143      * @param  autoFlush  A boolean; if true, the output buffer will be flushed
   144      *                    whenever a byte array is written, one of the
   144      *                    whenever a byte array is written, one of the
   145      *                    <code>println</code> methods is invoked, or a newline
   145      *                    {@code println} methods is invoked, or a newline
   146      *                    character or byte (<code>'\n'</code>) is written
   146      *                    character or byte ({@code '\n'}) is written
   147      *
   147      *
   148      * @see java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean)
   148      * @see java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean)
   149      */
   149      */
   150     public PrintStream(OutputStream out, boolean autoFlush) {
   150     public PrintStream(OutputStream out, boolean autoFlush) {
   151         this(autoFlush, requireNonNull(out, "Null output stream"));
   151         this(autoFlush, requireNonNull(out, "Null output stream"));
   156      *
   156      *
   157      * @param  out        The output stream to which values and objects will be
   157      * @param  out        The output stream to which values and objects will be
   158      *                    printed
   158      *                    printed
   159      * @param  autoFlush  A boolean; if true, the output buffer will be flushed
   159      * @param  autoFlush  A boolean; if true, the output buffer will be flushed
   160      *                    whenever a byte array is written, one of the
   160      *                    whenever a byte array is written, one of the
   161      *                    <code>println</code> methods is invoked, or a newline
   161      *                    {@code println} methods is invoked, or a newline
   162      *                    character or byte (<code>'\n'</code>) is written
   162      *                    character or byte ({@code '\n'}) is written
   163      * @param  encoding   The name of a supported
   163      * @param  encoding   The name of a supported
   164      *                    <a href="../lang/package-summary.html#charenc">
   164      *                    <a href="../lang/package-summary.html#charenc">
   165      *                    character encoding</a>
   165      *                    character encoding</a>
   166      *
   166      *
   167      * @throws  UnsupportedEncodingException
   167      * @throws  UnsupportedEncodingException
   369         }
   369         }
   370     }
   370     }
   371 
   371 
   372     /**
   372     /**
   373      * Flushes the stream and checks its error state. The internal error state
   373      * Flushes the stream and checks its error state. The internal error state
   374      * is set to <code>true</code> when the underlying output stream throws an
   374      * is set to {@code true} when the underlying output stream throws an
   375      * <code>IOException</code> other than <code>InterruptedIOException</code>,
   375      * {@code IOException} other than {@code InterruptedIOException},
   376      * and when the <code>setError</code> method is invoked.  If an operation
   376      * and when the {@code setError} method is invoked.  If an operation
   377      * on the underlying output stream throws an
   377      * on the underlying output stream throws an
   378      * <code>InterruptedIOException</code>, then the <code>PrintStream</code>
   378      * {@code InterruptedIOException}, then the {@code PrintStream}
   379      * converts the exception back into an interrupt by doing:
   379      * converts the exception back into an interrupt by doing:
   380      * <pre>
   380      * <pre>{@code
   381      *     Thread.currentThread().interrupt();
   381      *     Thread.currentThread().interrupt();
   382      * </pre>
   382      * }</pre>
   383      * or the equivalent.
   383      * or the equivalent.
   384      *
   384      *
   385      * @return <code>true</code> if and only if this stream has encountered an
   385      * @return {@code true} if and only if this stream has encountered an
   386      *         <code>IOException</code> other than
   386      *         {@code IOException} other than
   387      *         <code>InterruptedIOException</code>, or the
   387      *         {@code InterruptedIOException}, or the
   388      *         <code>setError</code> method has been invoked
   388      *         {@code setError} method has been invoked
   389      */
   389      */
   390     public boolean checkError() {
   390     public boolean checkError() {
   391         if (out != null)
   391         if (out != null)
   392             flush();
   392             flush();
   393         if (out instanceof java.io.PrintStream) {
   393         if (out instanceof java.io.PrintStream) {
   396         }
   396         }
   397         return trouble;
   397         return trouble;
   398     }
   398     }
   399 
   399 
   400     /**
   400     /**
   401      * Sets the error state of the stream to <code>true</code>.
   401      * Sets the error state of the stream to {@code true}.
   402      *
   402      *
   403      * <p> This method will cause subsequent invocations of {@link
   403      * <p> This method will cause subsequent invocations of {@link
   404      * #checkError()} to return <tt>true</tt> until {@link
   404      * #checkError()} to return {@code true} until
   405      * #clearError()} is invoked.
   405      * {@link #clearError()} is invoked.
   406      *
   406      *
   407      * @since 1.1
   407      * @since 1.1
   408      */
   408      */
   409     protected void setError() {
   409     protected void setError() {
   410         trouble = true;
   410         trouble = true;
   412 
   412 
   413     /**
   413     /**
   414      * Clears the internal error state of this stream.
   414      * Clears the internal error state of this stream.
   415      *
   415      *
   416      * <p> This method will cause subsequent invocations of {@link
   416      * <p> This method will cause subsequent invocations of {@link
   417      * #checkError()} to return <tt>false</tt> until another write
   417      * #checkError()} to return {@code false} until another write
   418      * operation fails and invokes {@link #setError()}.
   418      * operation fails and invokes {@link #setError()}.
   419      *
   419      *
   420      * @since 1.6
   420      * @since 1.6
   421      */
   421      */
   422     protected void clearError() {
   422     protected void clearError() {
   428      * which also implement the write() methods of OutputStream
   428      * which also implement the write() methods of OutputStream
   429      */
   429      */
   430 
   430 
   431     /**
   431     /**
   432      * Writes the specified byte to this stream.  If the byte is a newline and
   432      * Writes the specified byte to this stream.  If the byte is a newline and
   433      * automatic flushing is enabled then the <code>flush</code> method will be
   433      * automatic flushing is enabled then the {@code flush} method will be
   434      * invoked.
   434      * invoked.
   435      *
   435      *
   436      * <p> Note that the byte is written as given; to write a character that
   436      * <p> Note that the byte is written as given; to write a character that
   437      * will be translated according to the platform's default character
   437      * will be translated according to the platform's default character
   438      * encoding, use the <code>print(char)</code> or <code>println(char)</code>
   438      * encoding, use the {@code print(char)} or {@code println(char)}
   439      * methods.
   439      * methods.
   440      *
   440      *
   441      * @param  b  The byte to be written
   441      * @param  b  The byte to be written
   442      * @see #print(char)
   442      * @see #print(char)
   443      * @see #println(char)
   443      * @see #println(char)
   458             trouble = true;
   458             trouble = true;
   459         }
   459         }
   460     }
   460     }
   461 
   461 
   462     /**
   462     /**
   463      * Writes <code>len</code> bytes from the specified byte array starting at
   463      * Writes {@code len} bytes from the specified byte array starting at
   464      * offset <code>off</code> to this stream.  If automatic flushing is
   464      * offset {@code off} to this stream.  If automatic flushing is
   465      * enabled then the <code>flush</code> method will be invoked.
   465      * enabled then the {@code flush} method will be invoked.
   466      *
   466      *
   467      * <p> Note that the bytes will be written as given; to write characters
   467      * <p> Note that the bytes will be written as given; to write characters
   468      * that will be translated according to the platform's default character
   468      * that will be translated according to the platform's default character
   469      * encoding, use the <code>print(char)</code> or <code>println(char)</code>
   469      * encoding, use the {@code print(char)} or {@code println(char)}
   470      * methods.
   470      * methods.
   471      *
   471      *
   472      * @param  buf   A byte array
   472      * @param  buf   A byte array
   473      * @param  off   Offset from which to start taking bytes
   473      * @param  off   Offset from which to start taking bytes
   474      * @param  len   Number of bytes to write
   474      * @param  len   Number of bytes to write
   557     }
   557     }
   558 
   558 
   559     /* Methods that do not terminate lines */
   559     /* Methods that do not terminate lines */
   560 
   560 
   561     /**
   561     /**
   562      * Prints a boolean value.  The string produced by <code>{@link
   562      * Prints a boolean value.  The string produced by {@link
   563      * java.lang.String#valueOf(boolean)}</code> is translated into bytes
   563      * java.lang.String#valueOf(boolean)} is translated into bytes
   564      * according to the platform's default character encoding, and these bytes
   564      * according to the platform's default character encoding, and these bytes
   565      * are written in exactly the manner of the
   565      * are written in exactly the manner of the
   566      * <code>{@link #write(int)}</code> method.
   566      * {@link #write(int)} method.
   567      *
   567      *
   568      * @param      b   The <code>boolean</code> to be printed
   568      * @param      b   The {@code boolean} to be printed
   569      */
   569      */
   570     public void print(boolean b) {
   570     public void print(boolean b) {
   571         write(b ? "true" : "false");
   571         write(b ? "true" : "false");
   572     }
   572     }
   573 
   573 
   574     /**
   574     /**
   575      * Prints a character.  The character is translated into one or more bytes
   575      * Prints a character.  The character is translated into one or more bytes
   576      * according to the platform's default character encoding, and these bytes
   576      * according to the platform's default character encoding, and these bytes
   577      * are written in exactly the manner of the
   577      * are written in exactly the manner of the
   578      * <code>{@link #write(int)}</code> method.
   578      * {@link #write(int)} method.
   579      *
   579      *
   580      * @param      c   The <code>char</code> to be printed
   580      * @param      c   The {@code char} to be printed
   581      */
   581      */
   582     public void print(char c) {
   582     public void print(char c) {
   583         write(String.valueOf(c));
   583         write(String.valueOf(c));
   584     }
   584     }
   585 
   585 
   586     /**
   586     /**
   587      * Prints an integer.  The string produced by <code>{@link
   587      * Prints an integer.  The string produced by {@link
   588      * java.lang.String#valueOf(int)}</code> is translated into bytes
   588      * java.lang.String#valueOf(int)} is translated into bytes
   589      * according to the platform's default character encoding, and these bytes
   589      * according to the platform's default character encoding, and these bytes
   590      * are written in exactly the manner of the
   590      * are written in exactly the manner of the
   591      * <code>{@link #write(int)}</code> method.
   591      * {@link #write(int)} method.
   592      *
   592      *
   593      * @param      i   The <code>int</code> to be printed
   593      * @param      i   The {@code int} to be printed
   594      * @see        java.lang.Integer#toString(int)
   594      * @see        java.lang.Integer#toString(int)
   595      */
   595      */
   596     public void print(int i) {
   596     public void print(int i) {
   597         write(String.valueOf(i));
   597         write(String.valueOf(i));
   598     }
   598     }
   599 
   599 
   600     /**
   600     /**
   601      * Prints a long integer.  The string produced by <code>{@link
   601      * Prints a long integer.  The string produced by {@link
   602      * java.lang.String#valueOf(long)}</code> is translated into bytes
   602      * java.lang.String#valueOf(long)} is translated into bytes
   603      * according to the platform's default character encoding, and these bytes
   603      * according to the platform's default character encoding, and these bytes
   604      * are written in exactly the manner of the
   604      * are written in exactly the manner of the
   605      * <code>{@link #write(int)}</code> method.
   605      * {@link #write(int)} method.
   606      *
   606      *
   607      * @param      l   The <code>long</code> to be printed
   607      * @param      l   The {@code long} to be printed
   608      * @see        java.lang.Long#toString(long)
   608      * @see        java.lang.Long#toString(long)
   609      */
   609      */
   610     public void print(long l) {
   610     public void print(long l) {
   611         write(String.valueOf(l));
   611         write(String.valueOf(l));
   612     }
   612     }
   613 
   613 
   614     /**
   614     /**
   615      * Prints a floating-point number.  The string produced by <code>{@link
   615      * Prints a floating-point number.  The string produced by {@link
   616      * java.lang.String#valueOf(float)}</code> is translated into bytes
   616      * java.lang.String#valueOf(float)} is translated into bytes
   617      * according to the platform's default character encoding, and these bytes
   617      * according to the platform's default character encoding, and these bytes
   618      * are written in exactly the manner of the
   618      * are written in exactly the manner of the
   619      * <code>{@link #write(int)}</code> method.
   619      * {@link #write(int)} method.
   620      *
   620      *
   621      * @param      f   The <code>float</code> to be printed
   621      * @param      f   The {@code float} to be printed
   622      * @see        java.lang.Float#toString(float)
   622      * @see        java.lang.Float#toString(float)
   623      */
   623      */
   624     public void print(float f) {
   624     public void print(float f) {
   625         write(String.valueOf(f));
   625         write(String.valueOf(f));
   626     }
   626     }
   627 
   627 
   628     /**
   628     /**
   629      * Prints a double-precision floating-point number.  The string produced by
   629      * Prints a double-precision floating-point number.  The string produced by
   630      * <code>{@link java.lang.String#valueOf(double)}</code> is translated into
   630      * {@link java.lang.String#valueOf(double)} is translated into
   631      * bytes according to the platform's default character encoding, and these
   631      * bytes according to the platform's default character encoding, and these
   632      * bytes are written in exactly the manner of the <code>{@link
   632      * bytes are written in exactly the manner of the {@link
   633      * #write(int)}</code> method.
   633      * #write(int)} method.
   634      *
   634      *
   635      * @param      d   The <code>double</code> to be printed
   635      * @param      d   The {@code double} to be printed
   636      * @see        java.lang.Double#toString(double)
   636      * @see        java.lang.Double#toString(double)
   637      */
   637      */
   638     public void print(double d) {
   638     public void print(double d) {
   639         write(String.valueOf(d));
   639         write(String.valueOf(d));
   640     }
   640     }
   641 
   641 
   642     /**
   642     /**
   643      * Prints an array of characters.  The characters are converted into bytes
   643      * Prints an array of characters.  The characters are converted into bytes
   644      * according to the platform's default character encoding, and these bytes
   644      * according to the platform's default character encoding, and these bytes
   645      * are written in exactly the manner of the
   645      * are written in exactly the manner of the
   646      * <code>{@link #write(int)}</code> method.
   646      * {@link #write(int)} method.
   647      *
   647      *
   648      * @param      s   The array of chars to be printed
   648      * @param      s   The array of chars to be printed
   649      *
   649      *
   650      * @throws  NullPointerException  If <code>s</code> is <code>null</code>
   650      * @throws  NullPointerException  If {@code s} is {@code null}
   651      */
   651      */
   652     public void print(char s[]) {
   652     public void print(char s[]) {
   653         write(s);
   653         write(s);
   654     }
   654     }
   655 
   655 
   656     /**
   656     /**
   657      * Prints a string.  If the argument is <code>null</code> then the string
   657      * Prints a string.  If the argument is {@code null} then the string
   658      * <code>"null"</code> is printed.  Otherwise, the string's characters are
   658      * {@code "null"} is printed.  Otherwise, the string's characters are
   659      * converted into bytes according to the platform's default character
   659      * converted into bytes according to the platform's default character
   660      * encoding, and these bytes are written in exactly the manner of the
   660      * encoding, and these bytes are written in exactly the manner of the
   661      * <code>{@link #write(int)}</code> method.
   661      * {@link #write(int)} method.
   662      *
   662      *
   663      * @param      s   The <code>String</code> to be printed
   663      * @param      s   The {@code String} to be printed
   664      */
   664      */
   665     public void print(String s) {
   665     public void print(String s) {
   666         if (s == null) {
   666         if (s == null) {
   667             s = "null";
   667             s = "null";
   668         }
   668         }
   669         write(s);
   669         write(s);
   670     }
   670     }
   671 
   671 
   672     /**
   672     /**
   673      * Prints an object.  The string produced by the <code>{@link
   673      * Prints an object.  The string produced by the {@link
   674      * java.lang.String#valueOf(Object)}</code> method is translated into bytes
   674      * java.lang.String#valueOf(Object)} method is translated into bytes
   675      * according to the platform's default character encoding, and these bytes
   675      * according to the platform's default character encoding, and these bytes
   676      * are written in exactly the manner of the
   676      * are written in exactly the manner of the
   677      * <code>{@link #write(int)}</code> method.
   677      * {@link #write(int)} method.
   678      *
   678      *
   679      * @param      obj   The <code>Object</code> to be printed
   679      * @param      obj   The {@code Object} to be printed
   680      * @see        java.lang.Object#toString()
   680      * @see        java.lang.Object#toString()
   681      */
   681      */
   682     public void print(Object obj) {
   682     public void print(Object obj) {
   683         write(String.valueOf(obj));
   683         write(String.valueOf(obj));
   684     }
   684     }
   687     /* Methods that do terminate lines */
   687     /* Methods that do terminate lines */
   688 
   688 
   689     /**
   689     /**
   690      * Terminates the current line by writing the line separator string.  The
   690      * Terminates the current line by writing the line separator string.  The
   691      * line separator string is defined by the system property
   691      * line separator string is defined by the system property
   692      * <code>line.separator</code>, and is not necessarily a single newline
   692      * {@code line.separator}, and is not necessarily a single newline
   693      * character (<code>'\n'</code>).
   693      * character ({@code '\n'}).
   694      */
   694      */
   695     public void println() {
   695     public void println() {
   696         newLine();
   696         newLine();
   697     }
   697     }
   698 
   698 
   699     /**
   699     /**
   700      * Prints a boolean and then terminate the line.  This method behaves as
   700      * Prints a boolean and then terminate the line.  This method behaves as
   701      * though it invokes <code>{@link #print(boolean)}</code> and then
   701      * though it invokes {@link #print(boolean)} and then
   702      * <code>{@link #println()}</code>.
   702      * {@link #println()}.
   703      *
   703      *
   704      * @param x  The <code>boolean</code> to be printed
   704      * @param x  The {@code boolean} to be printed
   705      */
   705      */
   706     public void println(boolean x) {
   706     public void println(boolean x) {
   707         synchronized (this) {
   707         synchronized (this) {
   708             print(x);
   708             print(x);
   709             newLine();
   709             newLine();
   710         }
   710         }
   711     }
   711     }
   712 
   712 
   713     /**
   713     /**
   714      * Prints a character and then terminate the line.  This method behaves as
   714      * Prints a character and then terminate the line.  This method behaves as
   715      * though it invokes <code>{@link #print(char)}</code> and then
   715      * though it invokes {@link #print(char)} and then
   716      * <code>{@link #println()}</code>.
   716      * {@link #println()}.
   717      *
   717      *
   718      * @param x  The <code>char</code> to be printed.
   718      * @param x  The {@code char} to be printed.
   719      */
   719      */
   720     public void println(char x) {
   720     public void println(char x) {
   721         synchronized (this) {
   721         synchronized (this) {
   722             print(x);
   722             print(x);
   723             newLine();
   723             newLine();
   724         }
   724         }
   725     }
   725     }
   726 
   726 
   727     /**
   727     /**
   728      * Prints an integer and then terminate the line.  This method behaves as
   728      * Prints an integer and then terminate the line.  This method behaves as
   729      * though it invokes <code>{@link #print(int)}</code> and then
   729      * though it invokes {@link #print(int)} and then
   730      * <code>{@link #println()}</code>.
   730      * {@link #println()}.
   731      *
   731      *
   732      * @param x  The <code>int</code> to be printed.
   732      * @param x  The {@code int} to be printed.
   733      */
   733      */
   734     public void println(int x) {
   734     public void println(int x) {
   735         synchronized (this) {
   735         synchronized (this) {
   736             print(x);
   736             print(x);
   737             newLine();
   737             newLine();
   738         }
   738         }
   739     }
   739     }
   740 
   740 
   741     /**
   741     /**
   742      * Prints a long and then terminate the line.  This method behaves as
   742      * Prints a long and then terminate the line.  This method behaves as
   743      * though it invokes <code>{@link #print(long)}</code> and then
   743      * though it invokes {@link #print(long)} and then
   744      * <code>{@link #println()}</code>.
   744      * {@link #println()}.
   745      *
   745      *
   746      * @param x  a The <code>long</code> to be printed.
   746      * @param x  a The {@code long} to be printed.
   747      */
   747      */
   748     public void println(long x) {
   748     public void println(long x) {
   749         synchronized (this) {
   749         synchronized (this) {
   750             print(x);
   750             print(x);
   751             newLine();
   751             newLine();
   752         }
   752         }
   753     }
   753     }
   754 
   754 
   755     /**
   755     /**
   756      * Prints a float and then terminate the line.  This method behaves as
   756      * Prints a float and then terminate the line.  This method behaves as
   757      * though it invokes <code>{@link #print(float)}</code> and then
   757      * though it invokes {@link #print(float)} and then
   758      * <code>{@link #println()}</code>.
   758      * {@link #println()}.
   759      *
   759      *
   760      * @param x  The <code>float</code> to be printed.
   760      * @param x  The {@code float} to be printed.
   761      */
   761      */
   762     public void println(float x) {
   762     public void println(float x) {
   763         synchronized (this) {
   763         synchronized (this) {
   764             print(x);
   764             print(x);
   765             newLine();
   765             newLine();
   766         }
   766         }
   767     }
   767     }
   768 
   768 
   769     /**
   769     /**
   770      * Prints a double and then terminate the line.  This method behaves as
   770      * Prints a double and then terminate the line.  This method behaves as
   771      * though it invokes <code>{@link #print(double)}</code> and then
   771      * though it invokes {@link #print(double)} and then
   772      * <code>{@link #println()}</code>.
   772      * {@link #println()}.
   773      *
   773      *
   774      * @param x  The <code>double</code> to be printed.
   774      * @param x  The {@code double} to be printed.
   775      */
   775      */
   776     public void println(double x) {
   776     public void println(double x) {
   777         synchronized (this) {
   777         synchronized (this) {
   778             print(x);
   778             print(x);
   779             newLine();
   779             newLine();
   780         }
   780         }
   781     }
   781     }
   782 
   782 
   783     /**
   783     /**
   784      * Prints an array of characters and then terminate the line.  This method
   784      * Prints an array of characters and then terminate the line.  This method
   785      * behaves as though it invokes <code>{@link #print(char[])}</code> and
   785      * behaves as though it invokes {@link #print(char[])} and
   786      * then <code>{@link #println()}</code>.
   786      * then {@link #println()}.
   787      *
   787      *
   788      * @param x  an array of chars to print.
   788      * @param x  an array of chars to print.
   789      */
   789      */
   790     public void println(char x[]) {
   790     public void println(char x[]) {
   791         synchronized (this) {
   791         synchronized (this) {
   794         }
   794         }
   795     }
   795     }
   796 
   796 
   797     /**
   797     /**
   798      * Prints a String and then terminate the line.  This method behaves as
   798      * Prints a String and then terminate the line.  This method behaves as
   799      * though it invokes <code>{@link #print(String)}</code> and then
   799      * though it invokes {@link #print(String)} and then
   800      * <code>{@link #println()}</code>.
   800      * {@link #println()}.
   801      *
   801      *
   802      * @param x  The <code>String</code> to be printed.
   802      * @param x  The {@code String} to be printed.
   803      */
   803      */
   804     public void println(String x) {
   804     public void println(String x) {
   805         synchronized (this) {
   805         synchronized (this) {
   806             print(x);
   806             print(x);
   807             newLine();
   807             newLine();
   810 
   810 
   811     /**
   811     /**
   812      * Prints an Object and then terminate the line.  This method calls
   812      * Prints an Object and then terminate the line.  This method calls
   813      * at first String.valueOf(x) to get the printed object's string value,
   813      * at first String.valueOf(x) to get the printed object's string value,
   814      * then behaves as
   814      * then behaves as
   815      * though it invokes <code>{@link #print(String)}</code> and then
   815      * though it invokes {@link #print(String)} and then
   816      * <code>{@link #println()}</code>.
   816      * {@link #println()}.
   817      *
   817      *
   818      * @param x  The <code>Object</code> to be printed.
   818      * @param x  The {@code Object} to be printed.
   819      */
   819      */
   820     public void println(Object x) {
   820     public void println(Object x) {
   821         String s = String.valueOf(x);
   821         String s = String.valueOf(x);
   822         synchronized (this) {
   822         synchronized (this) {
   823             print(s);
   823             print(s);
   828 
   828 
   829     /**
   829     /**
   830      * A convenience method to write a formatted string to this output stream
   830      * A convenience method to write a formatted string to this output stream
   831      * using the specified format string and arguments.
   831      * using the specified format string and arguments.
   832      *
   832      *
   833      * <p> An invocation of this method of the form <tt>out.printf(format,
   833      * <p> An invocation of this method of the form
   834      * args)</tt> behaves in exactly the same way as the invocation
   834      * {@code out.printf(format, args)} behaves
   835      *
   835      * in exactly the same way as the invocation
   836      * <pre>
   836      *
   837      *     out.format(format, args) </pre>
   837      * <pre>{@code
       
   838      *     out.format(format, args)
       
   839      * }</pre>
   838      *
   840      *
   839      * @param  format
   841      * @param  format
   840      *         A format string as described in <a
   842      *         A format string as described in <a
   841      *         href="../util/Formatter.html#syntax">Format string syntax</a>
   843      *         href="../util/Formatter.html#syntax">Format string syntax</a>
   842      *
   844      *
   846      *         extra arguments are ignored.  The number of arguments is
   848      *         extra arguments are ignored.  The number of arguments is
   847      *         variable and may be zero.  The maximum number of arguments is
   849      *         variable and may be zero.  The maximum number of arguments is
   848      *         limited by the maximum dimension of a Java array as defined by
   850      *         limited by the maximum dimension of a Java array as defined by
   849      *         <cite>The Java&trade; Virtual Machine Specification</cite>.
   851      *         <cite>The Java&trade; Virtual Machine Specification</cite>.
   850      *         The behaviour on a
   852      *         The behaviour on a
   851      *         <tt>null</tt> argument depends on the <a
   853      *         {@code null} argument depends on the <a
   852      *         href="../util/Formatter.html#syntax">conversion</a>.
   854      *         href="../util/Formatter.html#syntax">conversion</a>.
   853      *
   855      *
   854      * @throws  java.util.IllegalFormatException
   856      * @throws  java.util.IllegalFormatException
   855      *          If a format string contains an illegal syntax, a format
   857      *          If a format string contains an illegal syntax, a format
   856      *          specifier that is incompatible with the given arguments,
   858      *          specifier that is incompatible with the given arguments,
   859      *          formatting errors, see the <a
   861      *          formatting errors, see the <a
   860      *          href="../util/Formatter.html#detail">Details</a> section of the
   862      *          href="../util/Formatter.html#detail">Details</a> section of the
   861      *          formatter class specification.
   863      *          formatter class specification.
   862      *
   864      *
   863      * @throws  NullPointerException
   865      * @throws  NullPointerException
   864      *          If the <tt>format</tt> is <tt>null</tt>
   866      *          If the {@code format} is {@code null}
   865      *
   867      *
   866      * @return  This output stream
   868      * @return  This output stream
   867      *
   869      *
   868      * @since  1.5
   870      * @since  1.5
   869      */
   871      */
   873 
   875 
   874     /**
   876     /**
   875      * A convenience method to write a formatted string to this output stream
   877      * A convenience method to write a formatted string to this output stream
   876      * using the specified format string and arguments.
   878      * using the specified format string and arguments.
   877      *
   879      *
   878      * <p> An invocation of this method of the form <tt>out.printf(l, format,
   880      * <p> An invocation of this method of the form
   879      * args)</tt> behaves in exactly the same way as the invocation
   881      * {@code out.printf(l, format, args)} behaves
   880      *
   882      * in exactly the same way as the invocation
   881      * <pre>
   883      *
   882      *     out.format(l, format, args) </pre>
   884      * <pre>{@code
       
   885      *     out.format(l, format, args)
       
   886      * }</pre>
   883      *
   887      *
   884      * @param  l
   888      * @param  l
   885      *         The {@linkplain java.util.Locale locale} to apply during
   889      *         The {@linkplain java.util.Locale locale} to apply during
   886      *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
   890      *         formatting.  If {@code l} is {@code null} then no localization
   887      *         is applied.
   891      *         is applied.
   888      *
   892      *
   889      * @param  format
   893      * @param  format
   890      *         A format string as described in <a
   894      *         A format string as described in <a
   891      *         href="../util/Formatter.html#syntax">Format string syntax</a>
   895      *         href="../util/Formatter.html#syntax">Format string syntax</a>
   896      *         extra arguments are ignored.  The number of arguments is
   900      *         extra arguments are ignored.  The number of arguments is
   897      *         variable and may be zero.  The maximum number of arguments is
   901      *         variable and may be zero.  The maximum number of arguments is
   898      *         limited by the maximum dimension of a Java array as defined by
   902      *         limited by the maximum dimension of a Java array as defined by
   899      *         <cite>The Java&trade; Virtual Machine Specification</cite>.
   903      *         <cite>The Java&trade; Virtual Machine Specification</cite>.
   900      *         The behaviour on a
   904      *         The behaviour on a
   901      *         <tt>null</tt> argument depends on the <a
   905      *         {@code null} argument depends on the <a
   902      *         href="../util/Formatter.html#syntax">conversion</a>.
   906      *         href="../util/Formatter.html#syntax">conversion</a>.
   903      *
   907      *
   904      * @throws  java.util.IllegalFormatException
   908      * @throws  java.util.IllegalFormatException
   905      *          If a format string contains an illegal syntax, a format
   909      *          If a format string contains an illegal syntax, a format
   906      *          specifier that is incompatible with the given arguments,
   910      *          specifier that is incompatible with the given arguments,
   909      *          formatting errors, see the <a
   913      *          formatting errors, see the <a
   910      *          href="../util/Formatter.html#detail">Details</a> section of the
   914      *          href="../util/Formatter.html#detail">Details</a> section of the
   911      *          formatter class specification.
   915      *          formatter class specification.
   912      *
   916      *
   913      * @throws  NullPointerException
   917      * @throws  NullPointerException
   914      *          If the <tt>format</tt> is <tt>null</tt>
   918      *          If the {@code format} is {@code null}
   915      *
   919      *
   916      * @return  This output stream
   920      * @return  This output stream
   917      *
   921      *
   918      * @since  1.5
   922      * @since  1.5
   919      */
   923      */
   939      *         extra arguments are ignored.  The number of arguments is
   943      *         extra arguments are ignored.  The number of arguments is
   940      *         variable and may be zero.  The maximum number of arguments is
   944      *         variable and may be zero.  The maximum number of arguments is
   941      *         limited by the maximum dimension of a Java array as defined by
   945      *         limited by the maximum dimension of a Java array as defined by
   942      *         <cite>The Java&trade; Virtual Machine Specification</cite>.
   946      *         <cite>The Java&trade; Virtual Machine Specification</cite>.
   943      *         The behaviour on a
   947      *         The behaviour on a
   944      *         <tt>null</tt> argument depends on the <a
   948      *         {@code null} argument depends on the <a
   945      *         href="../util/Formatter.html#syntax">conversion</a>.
   949      *         href="../util/Formatter.html#syntax">conversion</a>.
   946      *
   950      *
   947      * @throws  java.util.IllegalFormatException
   951      * @throws  java.util.IllegalFormatException
   948      *          If a format string contains an illegal syntax, a format
   952      *          If a format string contains an illegal syntax, a format
   949      *          specifier that is incompatible with the given arguments,
   953      *          specifier that is incompatible with the given arguments,
   952      *          formatting errors, see the <a
   956      *          formatting errors, see the <a
   953      *          href="../util/Formatter.html#detail">Details</a> section of the
   957      *          href="../util/Formatter.html#detail">Details</a> section of the
   954      *          formatter class specification.
   958      *          formatter class specification.
   955      *
   959      *
   956      * @throws  NullPointerException
   960      * @throws  NullPointerException
   957      *          If the <tt>format</tt> is <tt>null</tt>
   961      *          If the {@code format} is {@code null}
   958      *
   962      *
   959      * @return  This output stream
   963      * @return  This output stream
   960      *
   964      *
   961      * @since  1.5
   965      * @since  1.5
   962      */
   966      */
   981      * Writes a formatted string to this output stream using the specified
   985      * Writes a formatted string to this output stream using the specified
   982      * format string and arguments.
   986      * format string and arguments.
   983      *
   987      *
   984      * @param  l
   988      * @param  l
   985      *         The {@linkplain java.util.Locale locale} to apply during
   989      *         The {@linkplain java.util.Locale locale} to apply during
   986      *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
   990      *         formatting.  If {@code l} is {@code null} then no localization
   987      *         is applied.
   991      *         is applied.
   988      *
   992      *
   989      * @param  format
   993      * @param  format
   990      *         A format string as described in <a
   994      *         A format string as described in <a
   991      *         href="../util/Formatter.html#syntax">Format string syntax</a>
   995      *         href="../util/Formatter.html#syntax">Format string syntax</a>
   996      *         extra arguments are ignored.  The number of arguments is
  1000      *         extra arguments are ignored.  The number of arguments is
   997      *         variable and may be zero.  The maximum number of arguments is
  1001      *         variable and may be zero.  The maximum number of arguments is
   998      *         limited by the maximum dimension of a Java array as defined by
  1002      *         limited by the maximum dimension of a Java array as defined by
   999      *         <cite>The Java&trade; Virtual Machine Specification</cite>.
  1003      *         <cite>The Java&trade; Virtual Machine Specification</cite>.
  1000      *         The behaviour on a
  1004      *         The behaviour on a
  1001      *         <tt>null</tt> argument depends on the <a
  1005      *         {@code null} argument depends on the <a
  1002      *         href="../util/Formatter.html#syntax">conversion</a>.
  1006      *         href="../util/Formatter.html#syntax">conversion</a>.
  1003      *
  1007      *
  1004      * @throws  java.util.IllegalFormatException
  1008      * @throws  java.util.IllegalFormatException
  1005      *          If a format string contains an illegal syntax, a format
  1009      *          If a format string contains an illegal syntax, a format
  1006      *          specifier that is incompatible with the given arguments,
  1010      *          specifier that is incompatible with the given arguments,
  1009      *          formatting errors, see the <a
  1013      *          formatting errors, see the <a
  1010      *          href="../util/Formatter.html#detail">Details</a> section of the
  1014      *          href="../util/Formatter.html#detail">Details</a> section of the
  1011      *          formatter class specification.
  1015      *          formatter class specification.
  1012      *
  1016      *
  1013      * @throws  NullPointerException
  1017      * @throws  NullPointerException
  1014      *          If the <tt>format</tt> is <tt>null</tt>
  1018      *          If the {@code format} is {@code null}
  1015      *
  1019      *
  1016      * @return  This output stream
  1020      * @return  This output stream
  1017      *
  1021      *
  1018      * @since  1.5
  1022      * @since  1.5
  1019      */
  1023      */
  1035     }
  1039     }
  1036 
  1040 
  1037     /**
  1041     /**
  1038      * Appends the specified character sequence to this output stream.
  1042      * Appends the specified character sequence to this output stream.
  1039      *
  1043      *
  1040      * <p> An invocation of this method of the form <tt>out.append(csq)</tt>
  1044      * <p> An invocation of this method of the form {@code out.append(csq)}
  1041      * behaves in exactly the same way as the invocation
  1045      * behaves in exactly the same way as the invocation
  1042      *
  1046      *
  1043      * <pre>
  1047      * <pre>{@code
  1044      *     out.print(csq.toString()) </pre>
  1048      *     out.print(csq.toString())
  1045      *
  1049      * }</pre>
  1046      * <p> Depending on the specification of <tt>toString</tt> for the
  1050      *
  1047      * character sequence <tt>csq</tt>, the entire sequence may not be
  1051      * <p> Depending on the specification of {@code toString} for the
  1048      * appended.  For instance, invoking then <tt>toString</tt> method of a
  1052      * character sequence {@code csq}, the entire sequence may not be
       
  1053      * appended.  For instance, invoking then {@code toString} method of a
  1049      * character buffer will return a subsequence whose content depends upon
  1054      * character buffer will return a subsequence whose content depends upon
  1050      * the buffer's position and limit.
  1055      * the buffer's position and limit.
  1051      *
  1056      *
  1052      * @param  csq
  1057      * @param  csq
  1053      *         The character sequence to append.  If <tt>csq</tt> is
  1058      *         The character sequence to append.  If {@code csq} is
  1054      *         <tt>null</tt>, then the four characters <tt>"null"</tt> are
  1059      *         {@code null}, then the four characters {@code "null"} are
  1055      *         appended to this output stream.
  1060      *         appended to this output stream.
  1056      *
  1061      *
  1057      * @return  This output stream
  1062      * @return  This output stream
  1058      *
  1063      *
  1059      * @since  1.5
  1064      * @since  1.5
  1068 
  1073 
  1069     /**
  1074     /**
  1070      * Appends a subsequence of the specified character sequence to this output
  1075      * Appends a subsequence of the specified character sequence to this output
  1071      * stream.
  1076      * stream.
  1072      *
  1077      *
  1073      * <p> An invocation of this method of the form <tt>out.append(csq, start,
  1078      * <p> An invocation of this method of the form
  1074      * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
  1079      * {@code out.append(csq, start, end)} when
       
  1080      * {@code csq} is not {@code null}, behaves in
  1075      * exactly the same way as the invocation
  1081      * exactly the same way as the invocation
  1076      *
  1082      *
  1077      * <pre>
  1083      * <pre>{@code
  1078      *     out.print(csq.subSequence(start, end).toString()) </pre>
  1084      *     out.print(csq.subSequence(start, end).toString())
       
  1085      * }</pre>
  1079      *
  1086      *
  1080      * @param  csq
  1087      * @param  csq
  1081      *         The character sequence from which a subsequence will be
  1088      *         The character sequence from which a subsequence will be
  1082      *         appended.  If <tt>csq</tt> is <tt>null</tt>, then characters
  1089      *         appended.  If {@code csq} is {@code null}, then characters
  1083      *         will be appended as if <tt>csq</tt> contained the four
  1090      *         will be appended as if {@code csq} contained the four
  1084      *         characters <tt>"null"</tt>.
  1091      *         characters {@code "null"}.
  1085      *
  1092      *
  1086      * @param  start
  1093      * @param  start
  1087      *         The index of the first character in the subsequence
  1094      *         The index of the first character in the subsequence
  1088      *
  1095      *
  1089      * @param  end
  1096      * @param  end
  1091      *         subsequence
  1098      *         subsequence
  1092      *
  1099      *
  1093      * @return  This output stream
  1100      * @return  This output stream
  1094      *
  1101      *
  1095      * @throws  IndexOutOfBoundsException
  1102      * @throws  IndexOutOfBoundsException
  1096      *          If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
  1103      *          If {@code start} or {@code end} are negative, {@code start}
  1097      *          is greater than <tt>end</tt>, or <tt>end</tt> is greater than
  1104      *          is greater than {@code end}, or {@code end} is greater than
  1098      *          <tt>csq.length()</tt>
  1105      *          {@code csq.length()}
  1099      *
  1106      *
  1100      * @since  1.5
  1107      * @since  1.5
  1101      */
  1108      */
  1102     public PrintStream append(CharSequence csq, int start, int end) {
  1109     public PrintStream append(CharSequence csq, int start, int end) {
  1103         CharSequence cs = (csq == null ? "null" : csq);
  1110         CharSequence cs = (csq == null ? "null" : csq);
  1106     }
  1113     }
  1107 
  1114 
  1108     /**
  1115     /**
  1109      * Appends the specified character to this output stream.
  1116      * Appends the specified character to this output stream.
  1110      *
  1117      *
  1111      * <p> An invocation of this method of the form <tt>out.append(c)</tt>
  1118      * <p> An invocation of this method of the form {@code out.append(c)}
  1112      * behaves in exactly the same way as the invocation
  1119      * behaves in exactly the same way as the invocation
  1113      *
  1120      *
  1114      * <pre>
  1121      * <pre>{@code
  1115      *     out.print(c) </pre>
  1122      *     out.print(c)
       
  1123      * }</pre>
  1116      *
  1124      *
  1117      * @param  c
  1125      * @param  c
  1118      *         The 16-bit character to append
  1126      *         The 16-bit character to append
  1119      *
  1127      *
  1120      * @return  This output stream
  1128      * @return  This output stream