• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Greenhorn
Posts: 14
Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
InputStream is abstract.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 14
Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
byte to byte&chunks of bytes-got that,thanks.
reply
    Bookmark Topic Watch Topic
  • New Topic