• 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

Buffering streams and writers...

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I wondering if there is an advantage to wrapping streams with BufferedOutputStream before passing it to OutputStreamWriter over simply wrapping the OutputStreamWriter with a BufferedWriter? Or is it better to do both?

For example, whats the best practice...

1)


2)


3)



Thanks,
Spencer
[ December 06, 2005: Message edited by: Spencer Lee ]
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Spencer Lee:
Hello,
I wondering if there is an advantage to wrapping streams with BufferedOutputStream before passing it to OutputStreamWriter over simply wrapping the OutputStreamWriter with a BufferedWriter?



There is probably no difference because the buffer sizes for BufferedWriter and BufferedOutputStream are the same (8k in JDK 1.5.0). Wrapping a buffered stream with a buffered writer would not get you any positive benefit for the same reason.
Since tweaking IO throughput is very application-dependent, you should look at Java Platform Performance - IO for the details on IO performance and how to measure and test it.
 
Spencer Lee
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Joe. I'll check out your link.
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

There is probably no difference because the buffer sizes for BufferedWriter and BufferedOutputStream are the same...

However if you are using a charset where more than one byte is frequently converted to a single char, then the boundaries of the two buffers aren't going to match up so nicely any more. Whether this matters I have no idea, though.

Personally I would expect that a buffer between disk and memory would produce more benefits than a buffer between memory and memory. But then I distrust that kind of "explanation", so I would produce the "It depends, try it and see" sort of answer too.
 
reply
    Bookmark Topic Watch Topic
  • New Topic