Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DataInputStream vs BufferedInputStream

532 views
Skip to first unread message

sara

unread,
Apr 3, 2003, 7:23:58 PM4/3/03
to
I am trying to find out what is the different between DataInputStream, and
BufferedInputStream classes of java.io, well what I understood after reading
java.io doc is that BufferedInputStream helps to read data easier by
obviously "buffering" it so the user will not lose any data due to the speed
different? is that true? is this the main advantage of BufferedInputStream
?? how about BufferedOutStream? why do I need it.


Masha Kizub

unread,
Apr 7, 2003, 10:48:57 PM4/7/03
to

sara wrote:
>
> I am trying to find out what is the different between DataInputStream, and
> BufferedInputStream classes of java.io, well what I understood after reading
> java.io doc is that BufferedInputStream helps to read data easier by
> obviously "buffering" it so the user will not lose any data due to the speed
> different? is that true?

Almoust. You will not loose data anyway (if your program is correct :)

Buffer helps in many ways. For example, data from disk can come in 1024
bytes. So, buffer will read 1024 in one time and then give for you 1024
times before next "physical" read.

> is this the main advantage of BufferedInputStream
> ?? how about BufferedOutStream? why do I need it.

For the same reason - speed.

BufferedInputstream is a middleware stream. Usually low level like
keyboard, or file, or URL connection (socket) exist as InputStream. Then
it is used for creating BufferedInputStream and then for something more
specific Reader (to translate and read charecters/unicode) or
DataInputStream (particular data like int, double, String...).

In logic it looks like
InputStream => BufferedInputStream => DataInputStream

In Java code it looks like
DataInputSteam DIS= new DataInputStream(new BufferedInputStream(
System.in )));
String input=DIS.readLine(); // Depricated
String input1=DIS.readUTF();

or

BufferedReader d = new BufferedReader(new BufferedInputStream((new
Socket("www.yahoo.com", 80)).getInputStream()));
String yahoo=d.readLine();

Last one is double buffering. It's for fun only. Try to understand that
you can construct any streams what you want! Everything will be good if
you understand concepts.

Masha Kizub.

0 new messages