Re: What is the purpose of all these Streams?
From: Anthony Borla (ajborla_at_bigpond.com)
Date: 11/27/03
- Previous message: Vangelis Natsios: "Converting greek string to uppercase"
- In reply to: Alligator: "What is the purpose of all these Streams?"
- Next in thread: FISH: "Re: What is the purpose of all these Streams?"
- Reply: FISH: "Re: What is the purpose of all these Streams?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 27 Nov 2003 13:21:59 GMT
"Alligator" <pandelis@postmaster.co.uk> wrote in message
news:ee8940b4.0311270042.3e282b80@posting.google.com...
>
> And more specifically what is the difference between an
> InputStream and a BufferedInputStream?
>
An 'InputStream' is both a class, and a placeholder when used as a method
parameter, which means that you can pass any object created from a class
derived from this class.
A 'BufferedInputStream' is a class that extends the capabilities of of the
'InputStream' class to implement, among other things, I/O buffering.
>
> When should I use one and when should I use the other?
>
When you also want an input stream to be buffered wrap it up in a
'BufferedInputStream' object.
>
> And why is there besides a BufferedInputStream also
> a Buffered Reader?
>
'InputStream'-based classes read 8 bit bytes, while 'Reader'-based classes
read 16 bit characters.
> *** (1) ***
> Should one use ?? :
> InputStreamReader r =
> new InputStreamReader( blabla.getInputStream());
>
> or
>
> *** (2) ***
>
> InputStreamReader r =
> new InputStreamReader(
> new BufferedInputStream(blabla.getInputStream()));
>
> or
>
> *** (3) ***
>
> BufferedReader br =
> new BufferedReader(
> new InputStreamReader(blabla.getInputStream()));
>
> or
>
> *** (4) ***
>
> BufferedReader br =
> new BufferedReader(
> new InputStreamReader(
> new BufferedInputStream( blabla.getInputStream())));
>
Number *** (3) *** if buffering is required, and number *** (1) *** if it is
not required. In general, a stream is buffered by wrapping it up inside an
object that performs this task.
>
> Does the BufferedInputStream offer some advantage
> over a simple InputStream?
>
It buffers it, meaning that it uses an internal storage area to hold more
data that is requested, so helping to reduce the number of low-level I/O
operations performed. The end result is faster, more efficient I/O.
>
> Any enlightment upon these subjects would be
> very welcome ...
>
I strongly urge you to check out the Sun tutorials on streams, located at:
http://java.sun.com/docs/books/tutorial/essential/io/index.html
This describes the streams concept is some depth, as well as discussing all
the Java stream classes in detail, together with much sample code.
I hope this helps.
Anthony Borla
P.S.
I apologise for the brevity of my answers - I realise they are not enough to
adequately convey the ideas behind streams and stream use. I believe,
though, that you can obtain this understanding by completing the recommended
tutorial.
- Previous message: Vangelis Natsios: "Converting greek string to uppercase"
- In reply to: Alligator: "What is the purpose of all these Streams?"
- Next in thread: FISH: "Re: What is the purpose of all these Streams?"
- Reply: FISH: "Re: What is the purpose of all these Streams?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|