487 catch (InterruptedIOException x) {
488 Thread.currentThread().interrupt();
489 }
490 catch (IOException x) {
491 trouble = true;
492 }
493 }
494
495 /* Methods that do not terminate lines */
496
497 /**
498 * Prints a boolean value. The string produced by {@link
499 * java.lang.String#valueOf(boolean)} is translated into bytes
500 * according to the platform's default character encoding, and these bytes
501 * are written in exactly the manner of the {@link
502 * #write(int)} method.
503 *
504 * @param b The {@code boolean} to be printed
505 */
506 public void print(boolean b) {
507 write(b ? "true" : "false");
508 }
509
510 /**
511 * Prints a character. The character is translated into one or more bytes
512 * according to the platform's default character encoding, and these bytes
513 * are written in exactly the manner of the {@link
514 * #write(int)} method.
515 *
516 * @param c The {@code char} to be printed
517 */
518 public void print(char c) {
519 write(c);
520 }
521
522 /**
523 * Prints an integer. The string produced by {@link
524 * java.lang.String#valueOf(int)} is translated into bytes according
525 * to the platform's default character encoding, and these bytes are
526 * written in exactly the manner of the {@link #write(int)}
527 * method.
582 * method.
583 *
584 * @param s The array of chars to be printed
585 *
586 * @throws NullPointerException If {@code s} is {@code null}
587 */
588 public void print(char s[]) {
589 write(s);
590 }
591
592 /**
593 * Prints a string. If the argument is {@code null} then the string
594 * {@code "null"} is printed. Otherwise, the string's characters are
595 * converted into bytes according to the platform's default character
596 * encoding, and these bytes are written in exactly the manner of the
597 * {@link #write(int)} method.
598 *
599 * @param s The {@code String} to be printed
600 */
601 public void print(String s) {
602 if (s == null) {
603 s = "null";
604 }
605 write(s);
606 }
607
608 /**
609 * Prints an object. The string produced by the {@link
610 * java.lang.String#valueOf(Object)} method is translated into bytes
611 * according to the platform's default character encoding, and these bytes
612 * are written in exactly the manner of the {@link #write(int)}
613 * method.
614 *
615 * @param obj The {@code Object} to be printed
616 * @see java.lang.Object#toString()
617 */
618 public void print(Object obj) {
619 write(String.valueOf(obj));
620 }
621
622 /* Methods that do terminate lines */
623
624 /**
625 * Terminates the current line by writing the line separator string. The
988 * <pre>{@code
989 * out.write(csq.toString())
990 * }</pre>
991 *
992 * <p> Depending on the specification of {@code toString} for the
993 * character sequence {@code csq}, the entire sequence may not be
994 * appended. For instance, invoking the {@code toString} method of a
995 * character buffer will return a subsequence whose content depends upon
996 * the buffer's position and limit.
997 *
998 * @param csq
999 * The character sequence to append. If {@code csq} is
1000 * {@code null}, then the four characters {@code "null"} are
1001 * appended to this writer.
1002 *
1003 * @return This writer
1004 *
1005 * @since 1.5
1006 */
1007 public PrintWriter append(CharSequence csq) {
1008 if (csq == null)
1009 write("null");
1010 else
1011 write(csq.toString());
1012 return this;
1013 }
1014
1015 /**
1016 * Appends a subsequence of the specified character sequence to this writer.
1017 *
1018 * <p> An invocation of this method of the form
1019 * {@code out.append(csq, start, end)}
1020 * when {@code csq} is not {@code null}, behaves in
1021 * exactly the same way as the invocation
1022 *
1023 * <pre>{@code
1024 * out.write(csq.subSequence(start, end).toString())
1025 * }</pre>
1026 *
1027 * @param csq
1028 * The character sequence from which a subsequence will be
1029 * appended. If {@code csq} is {@code null}, then characters
1030 * will be appended as if {@code csq} contained the four
1031 * characters {@code "null"}.
1032 *
1033 * @param start
1034 * The index of the first character in the subsequence
1035 *
1036 * @param end
1037 * The index of the character following the last character in the
1038 * subsequence
1039 *
1040 * @return This writer
1041 *
1042 * @throws IndexOutOfBoundsException
1043 * If {@code start} or {@code end} are negative, {@code start}
1044 * is greater than {@code end}, or {@code end} is greater than
1045 * {@code csq.length()}
1046 *
1047 * @since 1.5
1048 */
1049 public PrintWriter append(CharSequence csq, int start, int end) {
1050 CharSequence cs = (csq == null ? "null" : csq);
1051 write(cs.subSequence(start, end).toString());
1052 return this;
1053 }
1054
1055 /**
1056 * Appends the specified character to this writer.
1057 *
1058 * <p> An invocation of this method of the form {@code out.append(c)}
1059 * behaves in exactly the same way as the invocation
1060 *
1061 * <pre>{@code
1062 * out.write(c)
1063 * }</pre>
1064 *
1065 * @param c
1066 * The 16-bit character to append
1067 *
1068 * @return This writer
1069 *
1070 * @since 1.5
1071 */
1072 public PrintWriter append(char c) {
|
487 catch (InterruptedIOException x) {
488 Thread.currentThread().interrupt();
489 }
490 catch (IOException x) {
491 trouble = true;
492 }
493 }
494
495 /* Methods that do not terminate lines */
496
497 /**
498 * Prints a boolean value. The string produced by {@link
499 * java.lang.String#valueOf(boolean)} is translated into bytes
500 * according to the platform's default character encoding, and these bytes
501 * are written in exactly the manner of the {@link
502 * #write(int)} method.
503 *
504 * @param b The {@code boolean} to be printed
505 */
506 public void print(boolean b) {
507 write(String.valueOf(b));
508 }
509
510 /**
511 * Prints a character. The character is translated into one or more bytes
512 * according to the platform's default character encoding, and these bytes
513 * are written in exactly the manner of the {@link
514 * #write(int)} method.
515 *
516 * @param c The {@code char} to be printed
517 */
518 public void print(char c) {
519 write(c);
520 }
521
522 /**
523 * Prints an integer. The string produced by {@link
524 * java.lang.String#valueOf(int)} is translated into bytes according
525 * to the platform's default character encoding, and these bytes are
526 * written in exactly the manner of the {@link #write(int)}
527 * method.
582 * method.
583 *
584 * @param s The array of chars to be printed
585 *
586 * @throws NullPointerException If {@code s} is {@code null}
587 */
588 public void print(char s[]) {
589 write(s);
590 }
591
592 /**
593 * Prints a string. If the argument is {@code null} then the string
594 * {@code "null"} is printed. Otherwise, the string's characters are
595 * converted into bytes according to the platform's default character
596 * encoding, and these bytes are written in exactly the manner of the
597 * {@link #write(int)} method.
598 *
599 * @param s The {@code String} to be printed
600 */
601 public void print(String s) {
602 write(String.valueOf(s));
603 }
604
605 /**
606 * Prints an object. The string produced by the {@link
607 * java.lang.String#valueOf(Object)} method is translated into bytes
608 * according to the platform's default character encoding, and these bytes
609 * are written in exactly the manner of the {@link #write(int)}
610 * method.
611 *
612 * @param obj The {@code Object} to be printed
613 * @see java.lang.Object#toString()
614 */
615 public void print(Object obj) {
616 write(String.valueOf(obj));
617 }
618
619 /* Methods that do terminate lines */
620
621 /**
622 * Terminates the current line by writing the line separator string. The
985 * <pre>{@code
986 * out.write(csq.toString())
987 * }</pre>
988 *
989 * <p> Depending on the specification of {@code toString} for the
990 * character sequence {@code csq}, the entire sequence may not be
991 * appended. For instance, invoking the {@code toString} method of a
992 * character buffer will return a subsequence whose content depends upon
993 * the buffer's position and limit.
994 *
995 * @param csq
996 * The character sequence to append. If {@code csq} is
997 * {@code null}, then the four characters {@code "null"} are
998 * appended to this writer.
999 *
1000 * @return This writer
1001 *
1002 * @since 1.5
1003 */
1004 public PrintWriter append(CharSequence csq) {
1005 write(String.valueOf(csq));
1006 return this;
1007 }
1008
1009 /**
1010 * Appends a subsequence of the specified character sequence to this writer.
1011 *
1012 * <p> An invocation of this method of the form
1013 * {@code out.append(csq, start, end)}
1014 * when {@code csq} is not {@code null}, behaves in
1015 * exactly the same way as the invocation
1016 *
1017 * <pre>{@code
1018 * out.write(csq.subSequence(start, end).toString())
1019 * }</pre>
1020 *
1021 * @param csq
1022 * The character sequence from which a subsequence will be
1023 * appended. If {@code csq} is {@code null}, then characters
1024 * will be appended as if {@code csq} contained the four
1025 * characters {@code "null"}.
1026 *
1027 * @param start
1028 * The index of the first character in the subsequence
1029 *
1030 * @param end
1031 * The index of the character following the last character in the
1032 * subsequence
1033 *
1034 * @return This writer
1035 *
1036 * @throws IndexOutOfBoundsException
1037 * If {@code start} or {@code end} are negative, {@code start}
1038 * is greater than {@code end}, or {@code end} is greater than
1039 * {@code csq.length()}
1040 *
1041 * @since 1.5
1042 */
1043 public PrintWriter append(CharSequence csq, int start, int end) {
1044 if (csq == null) csq = "null";
1045 return append(csq.subSequence(start, end));
1046 }
1047
1048 /**
1049 * Appends the specified character to this writer.
1050 *
1051 * <p> An invocation of this method of the form {@code out.append(c)}
1052 * behaves in exactly the same way as the invocation
1053 *
1054 * <pre>{@code
1055 * out.write(c)
1056 * }</pre>
1057 *
1058 * @param c
1059 * The 16-bit character to append
1060 *
1061 * @return This writer
1062 *
1063 * @since 1.5
1064 */
1065 public PrintWriter append(char c) {
|