472,803 Members | 881 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,803 software developers and data experts.

What is the purpose of all these Streams?

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?

And why is there besides a BufferedInputStream also a Buffered Reader?

Should one use ?? :
InputStreamReader r = new InputStreamReader( blabla.getInputStream());

or
InputStreamReader r = new InputStreamReader( new BufferedInputStream(
blabla.getInputStream()));

or
BufferedReader br = new BufferedReader( new InputStreamReader(
blabla.getInputStream()) );

or
BufferedReader br = new BufferedReader( new InputStreamReader( new
BufferedInputStream( blabla.getInputStream())));

Does the BufferedInputStream offer some advantage over a simple
InputStream?
Any enlightment upon these subjects would be very welcome ...
Jul 17 '05 #1
5 10118

"Alligator" <pa******@postmaster.co.uk> wrote in message
news:ee**************************@posting.google.c om...

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/tutor.../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.
Jul 17 '05 #2


On 27 Nov 2003 00:42:29 -0800, pa******@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 ...

Jul 17 '05 #3
"Anthony Borla" <aj*****@bigpond.com> wrote in message news:<XT*****************@news-server.bigpond.net.au>...
'InputStream'-based classes read 8 bit bytes, while 'Reader'-based classes
read 16 bit characters.

At the risk of nit-picking, I think this needs a bit of clarification:
The old 1.02 'stream' classes used to have methods which returned
strings of 16 bit chars - but the way they translated the bytes in
the source data to Unicode characters was too primitive. The new
'reader' classes actually know how to process Utf type data, meaning
that they can cope when they encounter chars which are outside the
usual one byte (seven bit) ASCII range.

So actually it is more accurate to say the 'reader'-based classes
read 8-or-more bit characters, translating them into 16 bit Unicode.

I strongly urge you to check out the Sun tutorials on streams, located at:

http://java.sun.com/docs/books/tutor.../io/index.html

That's good advice. I second that... :-)
-FISH- ><>
Jul 17 '05 #4
"FISH" <jo*****@merseymail.com> wrote in message
news:db*************************@posting.google.co m...
"Anthony Borla" <aj*****@bigpond.com> wrote in message news:<XT*****************@news-server.bigpond.net.au>...
'InputStream'-based classes read 8 bit bytes, while 'Reader'-based
classes read 16 bit characters.
At the risk of nit-picking, I think this needs a bit of
clarification: The old 1.02 'stream' classes used to
have methods which returned strings of 16 bit chars
- but the way they translated the bytes in the source
data to Unicode characters was too primitive. The
new 'reader' classes actually know how to process Utf
type data, meaning that they can cope when they
encounter chars which are outside the usual one byte
(seven bit) ASCII range.

So actually it is more accurate to say the 'reader'-based
classes read 8-or-more bit characters, translating them
into 16 bit Unicode.


Nit-pick all you want as long as it's constructive - such as in the interest
of ensuring accuracy, or perhaps just to help us all something new :) !
I strongly urge you to check out the Sun tutorials on
streams, located at:

http://java.sun.com/docs/books/tutor.../io/index.html

That's good advice. I second that... :-)


Yes, a pretty safe bet :) !

Cheers,

Anthony Borla

Jul 17 '05 #5
Thank you all very much for your answers ...

The thing that conserns me most, is the possibility that I may lose
some information if I use e.g InputStream over BufferedInputStream.

As for performance, your answers made it all very clear that
BufferedInputStream is better.
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: bonj | last post by:
hello I hope somebody can help me get my head around this area of 'stream' programming... I know that streams are very fashionable nowadays so hopefully there'll be lots of replies. ;-) ...
2
by: Steven T. Hatton | last post by:
I'm still not completely sure what's going on with C++ I/O regarding the extractors and inserters. The following document seems a bit inconsistent:...
16
by: Robert Wierschke | last post by:
hi I'm learning python since 3 days. I' ve some programming experience in BASIC, Pascal, C, C++ and Java. Actually I want to add a scripting language to this repertoire (I have virtually no...
11
by: Kobu | last post by:
I have a question about C's abstract "streams" (that I can't seem to FULLY understand from reading several tutorials). Streams seems to suggest that input can be treated continously if needed....
2
by: Peter Rilling | last post by:
One nice thing about collections and arrays is that they implement the IEnumerator and IEnumerable interfaces which allow for more then one iterator to walk the list of items without affecting the...
2
by: Abhishek | last post by:
what are the STDUPDATE, STDERR, STDOUT and STDIN streams and how does one access these streams in C language. I am aware of the function fprintf(FILE *fp, char * format, char *s) which puts the...
5
by: Michael Goldshteyn | last post by:
Consider the following two lines of code, the first intended to print "Hello world\n" and the second intended to print the character 'P' to stdout. --- std::cout <<...
12
by: blangela | last post by:
Someone has asked me what the relationship is, if any, between iostream and the STL. My suspicion is that iostream uses some of the functionality provided by the STL, but I have no actual kowledge...
4
by: Virtual_X | last post by:
it's only language confusion i am non-english speaker so i heard about stream in alot of c++ tutorials ie: in iostream and in sstream headers in sstream we use the class stringstream to...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.