Java Reference
In-Depth Information
BufferedReader don't extend FilterWriter and FilterReader , whereas
BufferedOutputStream and BufferedInputStream extend FilterOut-
putStream and FilterInputStream .
The output stream and input stream classes were introduced in JDK 1.0. After their
release,designissuesemerged.Forexample, FilterOutputStream and Filter-
InputStream should have been abstract. However, it was too late to make these
changesbecausetheclasseswerealreadybeingused;makingthesechangeswouldhave
resultedinbrokencode.ThedesignersofJDK1.1'swriterandreaderclassestookthe
time to correct these mistakes.
Note Regarding BufferedWriter and BufferedReader directlysubclassing
Writer and Reader instead of FilterWriter and FilterReader , I believe
that this change has to do with performance. Calls to BufferedOutputStream 's
write() methodsand BufferedInputStream 's read() methodsresultincalls
to FilterOutputStream 's write() methods and FilterInputStream 's
read() methods.BecauseafileI/Oactivity suchascopyingonefiletoanothercan
involve many write() / read() method calls, you want the best performance pos-
sible.Bynotsubclassing FileWriter and FileReader , BufferedWriter and
BufferedReader achieve better performance.
For brevity, I focus only on the Writer , Reader , OutputStreamWriter ,
OutputStreamReader , FileWriter , and FileReader classes in this chapter.
Writer and Reader
Javaprovidesthe Writer and Reader classesforperformingcharacterI/O. Writer
is the superclass of all writer subclasses. The following list identifies differences
between Writer and OutputStream :
Writer declares several append() methods for appending characters to
this writer. These methods exist because Writer implements the
java.lang.Appendable interface, which is used in partnership with the
Formatter class (see Appendix C) to output formatted strings.
Writer declaresadditional write() methods,includingaconvenient void
write(String str) methodforwritinga String object'scharactersto
this writer.
Reader isthesuperclassofallreadersubclasses.Thefollowinglistidentifiesdiffer-
ences between Reader and InputStream :
Search WWH ::




Custom Search