aspose file tools*
The moose likes Beginning Java and the fly likes difference between BufferedInputStream(or output) and other i/ostreams,regarding buffers. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "difference between BufferedInputStream(or output) and other i/ostreams,regarding buffers." Watch "difference between BufferedInputStream(or output) and other i/ostreams,regarding buffers." New topic
Author

difference between BufferedInputStream(or output) and other i/ostreams,regarding buffers.

nagarjuna borra
Ranch Hand

Joined: Jan 14, 2012
Posts: 41
i want to know the difference between the buffer associated with BufferedInputStream and the bytearray used in read(byte []) of InputStream.

to me both look the same,both are located in random access memory,so how does BufferedInputStream improve performance ??

(I remember usage of buffers in C with read() system call,and read(byte []) of java(InputStream class) looks the same).
Stas Melnychenko
Greenhorn

Joined: Feb 20, 2012
Posts: 14

InputStream is abstract.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Basically, BOS is guaranteed to buffer when it makes sense, whereas plain old OS makes no such guarantee. It is allowed to simply loop over the array, calling lower-level I/O writes for each byte, incurring, for example, network or file system overhead for each byte. Same thing on the input side.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Stas Melnychenko wrote:InputStream is abstract.


That doesn't really answer the question at all.

And note that, for instance, OutputStream.write(byte b[]) is not abstract.
Stas Melnychenko
Greenhorn

Joined: Feb 20, 2012
Posts: 14

Jeff Verdegan wrote:
Stas Melnychenko wrote:InputStream is abstract.


That doesn't really answer the question at all.

And note that, for instance, OutputStream.write(byte b[]) is not abstract.


Tnx, I understood.
nagarjuna borra
Ranch Hand

Joined: Jan 14, 2012
Posts: 41
Jeff Verdegan wrote:Basically, BOS is guaranteed to buffer when it makes sense, whereas plain old OS makes no such guarantee. It is allowed to simply loop over the array, calling lower-level I/O writes for each byte, incurring, for example, network or file system overhead for each byte. Same thing on the input side.


I didnt get that,i was thinking lower level I/O is faster..

did you mean lower level I/O is done in case of buffers & overhead is associated with byte arrays??
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

nagarjuna borra wrote:
Jeff Verdegan wrote:Basically, BOS is guaranteed to buffer when it makes sense, whereas plain old OS makes no such guarantee. It is allowed to simply loop over the array, calling lower-level I/O writes for each byte, incurring, for example, network or file system overhead for each byte. Same thing on the input side.


I didnt get that,i was thinking lower level I/O is faster..


Every time we physically put bytes onto a disk or network, there is an overhead. For instance, if I send 1 single byte of data over a TCP socket, I will be sending at least something like 15 bytes--14 bytes of TCP segment overhead for stuff like source port, dest port, sequence number, etc., plus our 1 data byte. And that doesn't even count overhead for the IP packet, which I think is at least 16 bytes.

So, which would you prefer?


nagarjuna borra
Ranch Hand

Joined: Jan 14, 2012
Posts: 41
byte to byte&chunks of bytes-got that,thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between BufferedInputStream(or output) and other i/ostreams,regarding buffers.