< prev index next >
src/java.base/share/classes/java/io/PrintStream.java
Print this page
@@ -413,10 +413,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();
@@ -433,10 +434,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 {
@@ -524,10 +526,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);
@@ -555,10 +558,11 @@
*
* @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);
@@ -572,10 +576,65 @@
catch (IOException x) {
trouble = true;
}
}
+ /**
+ * Writes all bytes from the specified byte array to this stream.
+ * The automatic flushing setting is ignored. The internal flag
+ * tested by {@link #checkError()} will <i>not</i> be set if an
+ * {@code IOException} is thrown.
+ *
+ * <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.
+ *
+ * @apiNote
+ * Unlike other overridden methods in this class, this method may throw
+ * an {@code IOException}. To write an array of bytes without being
+ * required to handle an {@code IOException}, use either
+ * {@link #writeBytes(byte[] buf) writeBytes(buf)} or
+ * {@link #write(byte[],int,int) write(buf,0,buf.length)}.
+ *
+ * @implSpec
+ * The default implementation is equivalent to
+ * {@link java.io.FilterOutputStream#write(byte[],int,int)
+ * super.write(buf,0,buf.length)}.
+ *
+ * @param buf A byte array
+ *
+ * @see #writeBytes(byte[])
+ * @see #write(byte[],int,int)
+ */
+ @Override
+ public void write(byte buf[]) throws IOException {
+ super.write(buf, 0, buf.length);
+ }
+
+ /**
+ * 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.
+ *
+ * @implSpec
+ * The default implementation is equivalent to
+ * {@link #write(byte[],int,int) this.write(buf, 0, buf.length)}.
+ *
+ * @param buf A byte array
+ *
+ * @since 14
+ */
+ public void writeBytes(byte buf[]) {
+ this.write(buf, 0, buf.length);
+ }
+
/*
* 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 >