< prev index next >

src/java.base/share/classes/java/io/PrintStream.java

Print this page
rev 15365 : imported patch 8163517-Various-cleanup-in-java-io-code


 551         catch (InterruptedIOException x) {
 552             Thread.currentThread().interrupt();
 553         }
 554         catch (IOException x) {
 555             trouble = true;
 556         }
 557     }
 558 
 559     /* Methods that do not terminate lines */
 560 
 561     /**
 562      * Prints a boolean value.  The string produced by {@link
 563      * java.lang.String#valueOf(boolean)} is translated into bytes
 564      * according to the platform's default character encoding, and these bytes
 565      * are written in exactly the manner of the
 566      * {@link #write(int)} method.
 567      *
 568      * @param      b   The {@code boolean} to be printed
 569      */
 570     public void print(boolean b) {
 571         write(b ? "true" : "false");
 572     }
 573 
 574     /**
 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
 577      * are written in exactly the manner of the
 578      * {@link #write(int)} method.
 579      *
 580      * @param      c   The {@code char} to be printed
 581      */
 582     public void print(char c) {
 583         write(String.valueOf(c));
 584     }
 585 
 586     /**
 587      * Prints an integer.  The string produced by {@link
 588      * java.lang.String#valueOf(int)} is translated into bytes
 589      * according to the platform's default character encoding, and these bytes
 590      * are written in exactly the manner of the
 591      * {@link #write(int)} method.


 646      * {@link #write(int)} method.
 647      *
 648      * @param      s   The array of chars to be printed
 649      *
 650      * @throws  NullPointerException  If {@code s} is {@code null}
 651      */
 652     public void print(char s[]) {
 653         write(s);
 654     }
 655 
 656     /**
 657      * Prints a string.  If the argument is {@code null} then the string
 658      * {@code "null"} is printed.  Otherwise, the string's characters are
 659      * converted into bytes according to the platform's default character
 660      * encoding, and these bytes are written in exactly the manner of the
 661      * {@link #write(int)} method.
 662      *
 663      * @param      s   The {@code String} to be printed
 664      */
 665     public void print(String s) {
 666         if (s == null) {
 667             s = "null";
 668         }
 669         write(s);
 670     }
 671 
 672     /**
 673      * Prints an object.  The string produced by the {@link
 674      * java.lang.String#valueOf(Object)} method is translated into bytes
 675      * according to the platform's default character encoding, and these bytes
 676      * are written in exactly the manner of the
 677      * {@link #write(int)} method.
 678      *
 679      * @param      obj   The {@code Object} to be printed
 680      * @see        java.lang.Object#toString()
 681      */
 682     public void print(Object obj) {
 683         write(String.valueOf(obj));
 684     }
 685 
 686 
 687     /* Methods that do terminate lines */
 688 
 689     /**


1051      * <pre>{@code
1052      *     out.print(csq.toString())
1053      * }</pre>
1054      *
1055      * <p> Depending on the specification of {@code toString} for the
1056      * character sequence {@code csq}, the entire sequence may not be
1057      * appended.  For instance, invoking then {@code toString} method of a
1058      * character buffer will return a subsequence whose content depends upon
1059      * the buffer's position and limit.
1060      *
1061      * @param  csq
1062      *         The character sequence to append.  If {@code csq} is
1063      *         {@code null}, then the four characters {@code "null"} are
1064      *         appended to this output stream.
1065      *
1066      * @return  This output stream
1067      *
1068      * @since  1.5
1069      */
1070     public PrintStream append(CharSequence csq) {
1071         if (csq == null)
1072             print("null");
1073         else
1074             print(csq.toString());
1075         return this;
1076     }
1077 
1078     /**
1079      * Appends a subsequence of the specified character sequence to this output
1080      * stream.
1081      *
1082      * <p> An invocation of this method of the form
1083      * {@code out.append(csq, start, end)} when
1084      * {@code csq} is not {@code null}, behaves in
1085      * exactly the same way as the invocation
1086      *
1087      * <pre>{@code
1088      *     out.print(csq.subSequence(start, end).toString())
1089      * }</pre>
1090      *
1091      * @param  csq
1092      *         The character sequence from which a subsequence will be
1093      *         appended.  If {@code csq} is {@code null}, then characters
1094      *         will be appended as if {@code csq} contained the four
1095      *         characters {@code "null"}.
1096      *
1097      * @param  start
1098      *         The index of the first character in the subsequence
1099      *
1100      * @param  end
1101      *         The index of the character following the last character in the
1102      *         subsequence
1103      *
1104      * @return  This output stream
1105      *
1106      * @throws  IndexOutOfBoundsException
1107      *          If {@code start} or {@code end} are negative, {@code start}
1108      *          is greater than {@code end}, or {@code end} is greater than
1109      *          {@code csq.length()}
1110      *
1111      * @since  1.5
1112      */
1113     public PrintStream append(CharSequence csq, int start, int end) {
1114         CharSequence cs = (csq == null ? "null" : csq);
1115         write(cs.subSequence(start, end).toString());
1116         return this;
1117     }
1118 
1119     /**
1120      * Appends the specified character to this output stream.
1121      *
1122      * <p> An invocation of this method of the form {@code out.append(c)}
1123      * behaves in exactly the same way as the invocation
1124      *
1125      * <pre>{@code
1126      *     out.print(c)
1127      * }</pre>
1128      *
1129      * @param  c
1130      *         The 16-bit character to append
1131      *
1132      * @return  This output stream
1133      *
1134      * @since  1.5
1135      */
1136     public PrintStream append(char c) {


 551         catch (InterruptedIOException x) {
 552             Thread.currentThread().interrupt();
 553         }
 554         catch (IOException x) {
 555             trouble = true;
 556         }
 557     }
 558 
 559     /* Methods that do not terminate lines */
 560 
 561     /**
 562      * Prints a boolean value.  The string produced by {@link
 563      * java.lang.String#valueOf(boolean)} is translated into bytes
 564      * according to the platform's default character encoding, and these bytes
 565      * are written in exactly the manner of the
 566      * {@link #write(int)} method.
 567      *
 568      * @param      b   The {@code boolean} to be printed
 569      */
 570     public void print(boolean b) {
 571         write(String.valueOf(b));
 572     }
 573 
 574     /**
 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
 577      * are written in exactly the manner of the
 578      * {@link #write(int)} method.
 579      *
 580      * @param      c   The {@code char} to be printed
 581      */
 582     public void print(char c) {
 583         write(String.valueOf(c));
 584     }
 585 
 586     /**
 587      * Prints an integer.  The string produced by {@link
 588      * java.lang.String#valueOf(int)} is translated into bytes
 589      * according to the platform's default character encoding, and these bytes
 590      * are written in exactly the manner of the
 591      * {@link #write(int)} method.


 646      * {@link #write(int)} method.
 647      *
 648      * @param      s   The array of chars to be printed
 649      *
 650      * @throws  NullPointerException  If {@code s} is {@code null}
 651      */
 652     public void print(char s[]) {
 653         write(s);
 654     }
 655 
 656     /**
 657      * Prints a string.  If the argument is {@code null} then the string
 658      * {@code "null"} is printed.  Otherwise, the string's characters are
 659      * converted into bytes according to the platform's default character
 660      * encoding, and these bytes are written in exactly the manner of the
 661      * {@link #write(int)} method.
 662      *
 663      * @param      s   The {@code String} to be printed
 664      */
 665     public void print(String s) {
 666         write(String.valueOf(s));



 667     }
 668 
 669     /**
 670      * Prints an object.  The string produced by the {@link
 671      * java.lang.String#valueOf(Object)} method is translated into bytes
 672      * according to the platform's default character encoding, and these bytes
 673      * are written in exactly the manner of the
 674      * {@link #write(int)} method.
 675      *
 676      * @param      obj   The {@code Object} to be printed
 677      * @see        java.lang.Object#toString()
 678      */
 679     public void print(Object obj) {
 680         write(String.valueOf(obj));
 681     }
 682 
 683 
 684     /* Methods that do terminate lines */
 685 
 686     /**


1048      * <pre>{@code
1049      *     out.print(csq.toString())
1050      * }</pre>
1051      *
1052      * <p> Depending on the specification of {@code toString} for the
1053      * character sequence {@code csq}, the entire sequence may not be
1054      * appended.  For instance, invoking then {@code toString} method of a
1055      * character buffer will return a subsequence whose content depends upon
1056      * the buffer's position and limit.
1057      *
1058      * @param  csq
1059      *         The character sequence to append.  If {@code csq} is
1060      *         {@code null}, then the four characters {@code "null"} are
1061      *         appended to this output stream.
1062      *
1063      * @return  This output stream
1064      *
1065      * @since  1.5
1066      */
1067     public PrintStream append(CharSequence csq) {
1068         print(String.valueOf(csq));



1069         return this;
1070     }
1071 
1072     /**
1073      * Appends a subsequence of the specified character sequence to this output
1074      * stream.
1075      *
1076      * <p> An invocation of this method of the form
1077      * {@code out.append(csq, start, end)} when
1078      * {@code csq} is not {@code null}, behaves in
1079      * exactly the same way as the invocation
1080      *
1081      * <pre>{@code
1082      *     out.print(csq.subSequence(start, end).toString())
1083      * }</pre>
1084      *
1085      * @param  csq
1086      *         The character sequence from which a subsequence will be
1087      *         appended.  If {@code csq} is {@code null}, then characters
1088      *         will be appended as if {@code csq} contained the four
1089      *         characters {@code "null"}.
1090      *
1091      * @param  start
1092      *         The index of the first character in the subsequence
1093      *
1094      * @param  end
1095      *         The index of the character following the last character in the
1096      *         subsequence
1097      *
1098      * @return  This output stream
1099      *
1100      * @throws  IndexOutOfBoundsException
1101      *          If {@code start} or {@code end} are negative, {@code start}
1102      *          is greater than {@code end}, or {@code end} is greater than
1103      *          {@code csq.length()}
1104      *
1105      * @since  1.5
1106      */
1107     public PrintStream append(CharSequence csq, int start, int end) {
1108         if (csq == null) csq = "null";
1109         return append(csq.subSequence(start, end));

1110     }
1111 
1112     /**
1113      * Appends the specified character to this output stream.
1114      *
1115      * <p> An invocation of this method of the form {@code out.append(c)}
1116      * behaves in exactly the same way as the invocation
1117      *
1118      * <pre>{@code
1119      *     out.print(c)
1120      * }</pre>
1121      *
1122      * @param  c
1123      *         The 16-bit character to append
1124      *
1125      * @return  This output stream
1126      *
1127      * @since  1.5
1128      */
1129     public PrintStream append(char c) {
< prev index next >