IO Streams in Java 1.1
By Bruce Eckel
The Java 1.0 IO streams library may have left you scratching your head, wondering if any IO stream design could be odder or require more typing to create a new stream. If so, prepare yourself: Java 1.1 will take these musings to a higher level. The new version includes significant modifications to the IO stream library, and although some aspects of the original stream library are deprecated (their use generates a compiler warning), the old streams have been left in for backward compatibility. New classes have been put into the old hierarchy, so JavaSoft is obviously not abandoning the old streams, and "bridge" classes have been added to allow the use of classes in the old hierarchy with those in the new hierarchy: InputStreamReader converts an InputStream to a Reader and OutputStreamWriter converts an OutputStream to a Writer. As a result, you sometimes have more layers of wrapping with the new IO stream library than with the old.
The most important reason for adding the Reader and Writer hierarchies in Java 1.1 is internationalization. The old IO stream hierarchy supports only 8-bit byte streams, and doesn't handle the 16-bit Unicode characters very well. Since Unicode is used for internationalization (and Java's native char is 16-bit Unicode), the Reader and Writer hierarchies were added to support Unicode in all IO operations. In addition, the new libraries are designed for faster operations than the old.
This month, I'll examine features new to the IO streams library, including the new compression library and object serialization.