1 /*
2 * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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.
10 *
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).
16 *
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.
20 *
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
528 out.write(b);
529 if ((b == '\n') && autoFlush)
530 out.flush();
531 }
532 }
533 catch (InterruptedIOException x) {
534 Thread.currentThread().interrupt();
535 }
536 catch (IOException x) {
537 trouble = true;
538 }
539 }
540
541 /**
542 * Writes {@code len} bytes from the specified byte array starting at
543 * offset {@code off} to this stream. If automatic flushing is
544 * enabled then the {@code flush} method will be invoked.
545 *
546 * <p> Note that the bytes will be written as given; to write characters
547 * that will be translated according to the platform's default character
548 * encoding, use the {@code print(char)} or {@code println(char)}
549 * methods.
550 *
551 * @param buf A byte array
552 * @param off Offset from which to start taking bytes
553 * @param len Number of bytes to write
554 */
555 public void write(byte buf[], int off, int len) {
556 try {
557 synchronized (this) {
558 ensureOpen();
559 out.write(buf, off, len);
560 if (autoFlush)
561 out.flush();
562 }
563 }
564 catch (InterruptedIOException x) {
565 Thread.currentThread().interrupt();
566 }
567 catch (IOException x) {
568 trouble = true;
569 }
570 }
571
572 /*
573 * The following private methods on the text- and character-output streams
574 * always flush the stream buffers, so that writes to the underlying byte
575 * stream occur as promptly as with the original PrintStream.
576 */
577
578 private void write(char[] buf) {
579 try {
580 synchronized (this) {
581 ensureOpen();
582 textOut.write(buf);
583 textOut.flushBuffer();
584 charOut.flushBuffer();
585 if (autoFlush) {
586 for (int i = 0; i < buf.length; i++)
587 if (buf[i] == '\n') {
588 out.flush();
589 break;
590 }
591 }
|
1 /*
2 * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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.
10 *
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).
16 *
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.
20 *
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
528 out.write(b);
529 if ((b == '\n') && autoFlush)
530 out.flush();
531 }
532 }
533 catch (InterruptedIOException x) {
534 Thread.currentThread().interrupt();
535 }
536 catch (IOException x) {
537 trouble = true;
538 }
539 }
540
541 /**
542 * Writes {@code len} bytes from the specified byte array starting at
543 * offset {@code off} to this stream. If automatic flushing is
544 * enabled then the {@code flush} method will be invoked.
545 *
546 * <p> Note that the bytes will be written as given; to write characters
547 * that will be translated according to the platform's default character
548 * encoding, use the {@code print(char[])} or {@code println(char[])}
549 * methods.
550 *
551 * @param buf A byte array
552 * @param off Offset from which to start taking bytes
553 * @param len Number of bytes to write
554 */
555 public void write(byte buf[], int off, int len) {
556 try {
557 synchronized (this) {
558 ensureOpen();
559 out.write(buf, off, len);
560 if (autoFlush)
561 out.flush();
562 }
563 }
564 catch (InterruptedIOException x) {
565 Thread.currentThread().interrupt();
566 }
567 catch (IOException x) {
568 trouble = true;
569 }
570 }
571
572 /**
573 * Writes all bytes from the specified byte array to this stream.
574 * If automatic flushing is enabled then the {@code flush} method
575 * will be invoked.
576 *
577 * <p> Note that the bytes will be written as given; to write characters
578 * that will be translated according to the platform's default character
579 * encoding, use the {@code print(char[])} or {@code println(char[])}
580 * methods.
581 *
582 * @param buf A byte array
583 */
584 public void write(byte buf[]) {
585 try {
586 synchronized (this) {
587 ensureOpen();
588 out.write(buf);
589 if (autoFlush)
590 out.flush();
591 }
592 }
593 catch (InterruptedIOException x) {
594 Thread.currentThread().interrupt();
595 }
596 catch (IOException x) {
597 trouble = true;
598 }
599 }
600
601 /*
602 * The following private methods on the text- and character-output streams
603 * always flush the stream buffers, so that writes to the underlying byte
604 * stream occur as promptly as with the original PrintStream.
605 */
606
607 private void write(char[] buf) {
608 try {
609 synchronized (this) {
610 ensureOpen();
611 textOut.write(buf);
612 textOut.flushBuffer();
613 charOut.flushBuffer();
614 if (autoFlush) {
615 for (int i = 0; i < buf.length; i++)
616 if (buf[i] == '\n') {
617 out.flush();
618 break;
619 }
620 }
|