The java.io.OutputStream class is an abstract class in Java that provides a basic framework for writing data to an output destination. Some of the functions that the OutputStream class fulfills include:
- Writing binary data: The OutputStream class provides methods for writing primitive data types, such as bytes, ints, and floats, to an output destination.
- Buffering: The OutputStream class provides a default implementation of buffering, which can improve performance by reducing the number of I/O operations required to write data to the output destination.
- Flushing: The OutputStream class provides a method for flushing the output buffer, which can be useful when it is important to ensure that data is written to the output destination as soon as possible.
- Closing: The OutputStream class provides a method for closing the output stream, which can be useful when it is necessary to release any resources that may be associated with the output stream, such as file handles or network connections.
Overall, the OutputStream class in Java provides a simple and flexible way to write data to an output destination, and is the foundation for many of the more specialized output stream classes in the Java I/O framework.
Java supports
buffered I/O, which means that data is written to a temporary buffer instead of to the stream.
When the buffer is full, all of the data in the buffer is written to the stream.
Buffered I/O is more efficient than non-buffered I/O since data is transferred to and from a physical device in large blocks.
- The
flush()
method in the OutputStream
class is used to force a buffer to be written to an output device.
DataOutput
is the counterpart to the DataInput
interface, and is used to output data in a primitive Java data format.
- The
DataOutput
interface provides methods such as writeBoolean()
, writeInt()
, and writeFloat()
. The DataOutputStream
class implements the DataOutput
interface.
- The
Writer
class is the counterpart to Reader
, and provides an internationalized alternative to the OutputStream
class.
- The
Writer
class is designed similarly to OutputStream
and supports a similar set of methods.
Note: Although they are named differently from the Java 1.0 stream classes, the
Reader
and
Writer
classes are still considered streams. So, the term "stream" applies to both sets of classes.