Re: What is the purpose of all these Streams?
From: DaiIchi (daiichi_at_agentnews.test.xhome.us)
Date: 11/27/03
- Next message: Herman Timmermans: "Re: Tomcat configuration question"
- Previous message: SC: "messaging based alert system architecture"
- In reply to: Alligator: "What is the purpose of all these Streams?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 27 Nov 2003 07:13:22 -0800
On 27 Nov 2003 00:42:29 -0800, pandelis@postmaster.co.uk (Alligator)
wrote:
>And more specifically what is the difference between an InputStream
>and a BufferedInputStream?
>When should I use one and when should I use the other?
One is buffered a buffered input stream, the other one isn't. But the
BufferedInputStream is a subclass of InputStream... so anywhere that
can use an InputStream can use a BufferedInputStream.
If you think about it, a buffered stream will read a whole buffer of
information from a socket, file, serial port, etc. Then a program can
read this information from the buffer... and the buffer will
automagically refill itself as needed from the source. This is really
useful if you're trying to suck data from a source as fast as
possible... but there will be instances where you want to keep the
data in the stream, so you may not want to use a buffer to read it.
>
>And why is there besides a BufferedInputStream also a Buffered Reader?
>
Basically Readers are designed for text I/O--they know how to do
things like localization (i.e., translating character sets).
BufferedInputStream is much older than the BufferedReader (having been
in Java since 1.0).
>Should one use ?? :
>InputStreamReader r = new InputStreamReader( blabla.getInputStream());
>
>or
>InputStreamReader r = new InputStreamReader( new BufferedInputStream(
>blabla.getInputStream()));
>
Again, if you're looking for performance and don't care that the data
all gets read from (for example) a socket, then use the
BufferedInputStream.
>or
>BufferedReader br = new BufferedReader( new InputStreamReader(
>blabla.getInputStream()) );
>
>or
>BufferedReader br = new BufferedReader( new InputStreamReader( new
>BufferedInputStream( blabla.getInputStream())));
>
Hehe, good question. My answer is try and use what makes you most
comfortable. I'm not sure which one is actually more efficient. To
me, it's sort of like, which is better:
i = i + 37;
or
i += 37; ?
(answer is that efficiency-wise, it makes no difference (since the
compiler optimizes the code), but I prefer the former rather than the
latter because non-C/++/Java programmers have a better understanding
of the logic).
>Does the BufferedInputStream offer some advantage over a simple
>InputStream?
>Any enlightment upon these subjects would be very welcome ...
- Next message: Herman Timmermans: "Re: Tomcat configuration question"
- Previous message: SC: "messaging based alert system architecture"
- In reply to: Alligator: "What is the purpose of all these Streams?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|