java - Why an InputStream obj cannot be nested into a BufferedReader obj directly? -


an outputstream obj can connected printwriter obj directly, e.g.,

 //either ok new printwriter(socket.getoutputstream()); new printwriter(new outputstreamwriter(socket.getoutputstream())); 
in case of inputstream obj, must connected bufferedreader obj through inputstreamreader obj, is,
 new bufferedreader(new inputstreamreader(socket.getinputstream())); //ok new bufferedreader(socket.getinputstream()); //doesnt work 
there reason inconsistency of api design?

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

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -