java - Why an InputStream obj cannot be nested into a BufferedReader obj directly? -
an outputstream obj can connected printwriter obj directly, e.g.,
in case of inputstream obj, must connected bufferedreader obj through inputstreamreader obj, is, //either ok new printwriter(socket.getoutputstream()); new printwriter(new outputstreamwriter(socket.getoutputstream()));
there reason inconsistency of api design? new bufferedreader(new inputstreamreader(socket.getinputstream())); //ok new bufferedreader(socket.getinputstream()); //doesnt work
java introduced reader , writer hierarchy (java 1.1 think) when input , output stream classes in use. therefore using bridge pattern allow have stream classes passed reader classes. further writer pritnerwriter directly bridge class equivalent inputstreamreader. see same thing bufferedwriter more info read http://www.codeguru.com/java/tij/tij0114.shtml
Comments
Post a Comment