< prev index next >

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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -408,10 +408,11 @@
      * Flushes the stream.  This is done by writing any buffered output bytes to
      * the underlying output stream and then flushing that stream.
      *
      * @see        java.io.OutputStream#flush()
      */
+    @Override
     public void flush() {
         synchronized (this) {
             try {
                 ensureOpen();
                 out.flush();

@@ -428,10 +429,11 @@
      * Closes the stream.  This is done by flushing the stream and then closing
      * the underlying output stream.
      *
      * @see        java.io.OutputStream#close()
      */
+    @Override
     public void close() {
         synchronized (this) {
             if (! closing) {
                 closing = true;
                 try {

@@ -519,10 +521,11 @@
      *
      * @param  b  The byte to be written
      * @see #print(char)
      * @see #println(char)
      */
+    @Override
     public void write(int b) {
         try {
             synchronized (this) {
                 ensureOpen();
                 out.write(b);

@@ -543,17 +546,18 @@
      * offset {@code off} to this stream.  If automatic flushing is
      * enabled then the {@code flush} method will be invoked.
      *
      * <p> Note that the bytes will be written as given; to write characters
      * that will be translated according to the platform's default character
-     * encoding, use the {@code print(char)} or {@code println(char)}
+     * encoding, use the {@code print(char[])} or {@code println(char[])}
      * methods.
      *
      * @param  buf   A byte array
      * @param  off   Offset from which to start taking bytes
      * @param  len   Number of bytes to write
      */
+    @Override
     public void write(byte buf[], int off, int len) {
         try {
             synchronized (this) {
                 ensureOpen();
                 out.write(buf, off, len);

@@ -567,10 +571,40 @@
         catch (IOException x) {
             trouble = true;
         }
     }
 
+    /**
+     * Writes all bytes from the specified byte array to this stream.
+     * If automatic flushing is enabled then the {@code flush} method
+     * will be invoked.
+     *
+     * <p> Note that the bytes will be written as given; to write characters
+     * that will be translated according to the platform's default character
+     * encoding, use the {@code print(char[])} or {@code println(char[])}
+     * methods.
+     *
+     * @param  buf   A byte array
+     */
+    @Override
+    public void write(byte buf[]) {
+        try {
+            synchronized (this) {
+                ensureOpen();
+                out.write(buf, 0, buf.length);
+                if (autoFlush)
+                    out.flush();
+            }
+        }
+        catch (InterruptedIOException x) {
+            Thread.currentThread().interrupt();
+        }
+        catch (IOException x) {
+            trouble = true;
+        }
+    }
+
     /*
      * The following private methods on the text- and character-output streams
      * always flush the stream buffers, so that writes to the underlying byte
      * stream occur as promptly as with the original PrintStream.
      */
< prev index next >