< prev index next >

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

Print this page




 483         }
 484         catch (InterruptedIOException x) {
 485             Thread.currentThread().interrupt();
 486         }
 487         catch (IOException x) {
 488             trouble = true;
 489         }
 490     }
 491 
 492     /**
 493      * Writes A Portion of an array of characters.
 494      * @param buf Array of characters
 495      * @param off Offset from which to start writing characters
 496      * @param len Number of characters to write
 497      *
 498      * @throws  IndexOutOfBoundsException
 499      *          If the values of the {@code off} and {@code len} parameters
 500      *          cause the corresponding method of the underlying {@code Writer}
 501      *          to throw an {@code IndexOutOfBoundsException}
 502      */
 503     public void write(char buf[], int off, int len) {
 504         try {
 505             synchronized (lock) {
 506                 ensureOpen();
 507                 out.write(buf, off, len);
 508             }
 509         }
 510         catch (InterruptedIOException x) {
 511             Thread.currentThread().interrupt();
 512         }
 513         catch (IOException x) {
 514             trouble = true;
 515         }
 516     }
 517 
 518     /**
 519      * Writes an array of characters.  This method cannot be inherited from the
 520      * Writer class because it must suppress I/O exceptions.
 521      * @param buf Array of characters to be written
 522      */
 523     public void write(char buf[]) {
 524         write(buf, 0, buf.length);
 525     }
 526 
 527     /**
 528      * Writes a portion of a string.
 529      * @param s A String
 530      * @param off Offset from which to start writing characters
 531      * @param len Number of characters to write
 532      *
 533      * @throws  IndexOutOfBoundsException
 534      *          If the values of the {@code off} and {@code len} parameters
 535      *          cause the corresponding method of the underlying {@code Writer}
 536      *          to throw an {@code IndexOutOfBoundsException}
 537      */
 538     public void write(String s, int off, int len) {
 539         try {
 540             synchronized (lock) {
 541                 ensureOpen();
 542                 out.write(s, off, len);
 543             }


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


 786      * Prints a double-precision floating-point number and then terminates the
 787      * line.  This method behaves as though it invokes {@link
 788      * #print(double)} and then {@link #println()}.
 789      *
 790      * @param x the {@code double} value to be printed
 791      */
 792     public void println(double x) {
 793         synchronized (lock) {
 794             print(x);
 795             println();
 796         }
 797     }
 798 
 799     /**
 800      * Prints an array of characters and then terminates the line.  This method
 801      * behaves as though it invokes {@link #print(char[])} and then
 802      * {@link #println()}.
 803      *
 804      * @param x the array of {@code char} values to be printed
 805      */
 806     public void println(char x[]) {
 807         synchronized (lock) {
 808             print(x);
 809             println();
 810         }
 811     }
 812 
 813     /**
 814      * Prints a String and then terminates the line.  This method behaves as
 815      * though it invokes {@link #print(String)} and then
 816      * {@link #println()}.
 817      *
 818      * @param x the {@code String} value to be printed
 819      */
 820     public void println(String x) {
 821         synchronized (lock) {
 822             print(x);
 823             println();
 824         }
 825     }
 826 




 483         }
 484         catch (InterruptedIOException x) {
 485             Thread.currentThread().interrupt();
 486         }
 487         catch (IOException x) {
 488             trouble = true;
 489         }
 490     }
 491 
 492     /**
 493      * Writes A Portion of an array of characters.
 494      * @param buf Array of characters
 495      * @param off Offset from which to start writing characters
 496      * @param len Number of characters to write
 497      *
 498      * @throws  IndexOutOfBoundsException
 499      *          If the values of the {@code off} and {@code len} parameters
 500      *          cause the corresponding method of the underlying {@code Writer}
 501      *          to throw an {@code IndexOutOfBoundsException}
 502      */
 503     public void write(char[] buf, int off, int len) {
 504         try {
 505             synchronized (lock) {
 506                 ensureOpen();
 507                 out.write(buf, off, len);
 508             }
 509         }
 510         catch (InterruptedIOException x) {
 511             Thread.currentThread().interrupt();
 512         }
 513         catch (IOException x) {
 514             trouble = true;
 515         }
 516     }
 517 
 518     /**
 519      * Writes an array of characters.  This method cannot be inherited from the
 520      * Writer class because it must suppress I/O exceptions.
 521      * @param buf Array of characters to be written
 522      */
 523     public void write(char[] buf) {
 524         write(buf, 0, buf.length);
 525     }
 526 
 527     /**
 528      * Writes a portion of a string.
 529      * @param s A String
 530      * @param off Offset from which to start writing characters
 531      * @param len Number of characters to write
 532      *
 533      * @throws  IndexOutOfBoundsException
 534      *          If the values of the {@code off} and {@code len} parameters
 535      *          cause the corresponding method of the underlying {@code Writer}
 536      *          to throw an {@code IndexOutOfBoundsException}
 537      */
 538     public void write(String s, int off, int len) {
 539         try {
 540             synchronized (lock) {
 541                 ensureOpen();
 542                 out.write(s, off, len);
 543             }


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


 786      * Prints a double-precision floating-point number and then terminates the
 787      * line.  This method behaves as though it invokes {@link
 788      * #print(double)} and then {@link #println()}.
 789      *
 790      * @param x the {@code double} value to be printed
 791      */
 792     public void println(double x) {
 793         synchronized (lock) {
 794             print(x);
 795             println();
 796         }
 797     }
 798 
 799     /**
 800      * Prints an array of characters and then terminates the line.  This method
 801      * behaves as though it invokes {@link #print(char[])} and then
 802      * {@link #println()}.
 803      *
 804      * @param x the array of {@code char} values to be printed
 805      */
 806     public void println(char[] x) {
 807         synchronized (lock) {
 808             print(x);
 809             println();
 810         }
 811     }
 812 
 813     /**
 814      * Prints a String and then terminates the line.  This method behaves as
 815      * though it invokes {@link #print(String)} and then
 816      * {@link #println()}.
 817      *
 818      * @param x the {@code String} value to be printed
 819      */
 820     public void println(String x) {
 821         synchronized (lock) {
 822             print(x);
 823             println();
 824         }
 825     }
 826 


< prev index next >