Tuesday, May 10, 2011

The Stream Classes

Most stream classes are part of the java.io package. (There are also a few more in the sun.io and sun.net packages, but those are deliberately hidden from you. There are also a couple in java.util.zip.)

Dividing the hierarchy in CharacterStream and ByteStream

As we saw  how type of stream is reflected in java.io hierarchy. So we have java.io defined in this way.  So we have Character Streams as well as ByteStreams.
From point of view of Character Stream, java.io. Reader and java.io. Writer are two main classes.
The two main classes from point of view of byte stream are java.io.InputStream and java.io.OutputStream.


Reader and Writer are the abstract superclasses for character streams in java.io. Reader provides the API and partial implementation for readers--streams that read 16-bit characters--and Writer provides the API and partial implementation for writers--streams that write 16-bit characters.
Subclasses of Reader and Writer implement specialized streams and are divided into two categories: those that read from or write to data sinks (shown in gray in the following figures) and those that perform some sort of processing (shown in white). The figure shows the class hierarchies for the Reader and Writer classes.

Most programs should use readers and writers to read and write information. This is because they both can handle any character in the Unicode character set (while the byte streams are limited to ISO-Latin-1 8-bit bytes).

Byte Stream

Programs should use the byte streams, descendants of InputStream and OutputStream, to read and write 8-bit bytes. InputStream and OutputStream provide the API and some implementation for input streams (streams that read 8-bit bytes) and output streams (streams that write 8-bit bytes). These streams are typically used to read and write binary data such as images and sounds.

As with Reader and Writer, subclasses of InputStream and OutputStream provide specialized I/O that falls into two categories: data sink streams and processing streams.



No comments:

Post a Comment