The BufferedReader is probably just decorating the InputReader being passed in. It makes no sense for a BufferedReader to accept a class it can't decorate, like an InputStream.
views:
38answers:
3There isn't any inconsistency... you should be comparing BufferedReader
and BufferedWriter
. They exist to wrap other Reader
s and Writer
s respectively.
The basic reason for that is that different types of Reader
s and Writer
s may have different ways of being initialized and different ways of functioning, not necessarily wrapping an InputStream
or OutputStream
at all. In your example of a BufferedReader
wrapping an InputStreamReader
, InputStreamReader
can (and generally should) be initialized with both an InputStream
and a Charset
. Should BufferedReader
have an overload for that, when its only job is to provide buffering?
Java introduced Reader and Writer hierarchy (java 1.1 I think) when Input and output stream classes were already in use. Therefore using a bridge pattern they allow you to have stream classes passed into reader classes. Further for writer also PritnerWriter is directly the bridge class which is equivalent to InputStreamReader. You will see the same thing for BufferedWriter too For more info read up http://www.codeguru.com/java/tij/tij0114.shtml