4.2. How Streams Work

As mentioned earlier, streams provide communication of data at the byte level, and are used for either reading or writing. Streams for reading inherit from a common superclass, the java.io.InputStream class, shown in Figure 4-3. Likewise, streams used for writing data inherit from the superclass java.io. OutputStream, shown in Figure 4-4. These are abstract classes; they cannot be instantiated. Instead, an appropriate subclass for the task at hand is created. Several streams inherit directly from either InputStream or OutputStream, but most inherit from a filter stream.

Figure 4-3. Input streams inherit from InputStream, although not always directly.
Figure 4-4. Output streams inherit from OutputStream, although not always ...

Get Java™ Network Programming and Distributed Computing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.