Contents | Prev | Next | Index

22.15 The Class java.io.OutputStream

An output stream accepts output bytes and sends them to some sink.

public abstract class OutputStream {
	public abstract void write(int b) throws IOException;
	public void write(byte[] b)
		throws IOException, NullPointerException;
	public void write(byte[] b, int off, int len)
		throws IOException, NullPointerException,
			IndexOutOfBoundsException;
	public void flush() throws IOException;
	public void close() throws IOException;
}

22.15.1 public abstract void write(int b) throws IOException

The general contract for write is that one byte is written to the output stream. The byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

If the byte cannot be written for any reason, an IOException is thrown. In particular, an IOException may be thrown if the output stream has been closed (§22.15.5).

22.15.2 public void write(byte[] b)
throws IOException, NullPointerException

The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length) (§22.15.3).

The write(b) method for class OutputStream in fact makes such a call.

22.15.3 public void write(byte[] b, int off, int len)
throws IOException, NullPointerException, IndexOutOfBoundsException

The general contract for write(b, off, len) is that some of the bytes in the array b are written to the output stream as if one at a time, in order; element b[off] is the first byte written and b[off+len-1] is the last byte written by this operation.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

If the byte cannot be written for any reason, an IOException is thrown. In particular, an IOException is thrown if the output stream has been closed (§22.15.5).

The write(b, off, len) method for class OutputStream simply calls the method write (§22.15.1) repeatedly, once for each byte in b to be written.

22.15.4 public void flush() throws IOException

The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

The flush method for class OutputStream does nothing and simply returns.

22.15.5 public void close() throws IOException

The general contract of close is that it closes the output stream. A closed stream cannot perform output operations and cannot be reopened.

The close method for class OutputStream does nothing and simply returns.


Contents | Prev | Next | Index

Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com