Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Flushing a stream  RSS feed

 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Just wondering if flushing a stream makes sense like a FileWriter for example..
there is an example on Kathy Sierra and Bert book in which they say:

Before we go any further let's talk about flush() and close(). When you write
data out to a stream, some amount of buffering will occur, and you never know for
sure exactly when the last of the data will actually be sent. You might perform many
write operations on a stream before closing it, and invoking the flush() method
guarantees that the last of the data you thought you had already written actually
gets out to the file


However I knew that only BufferedReader or anyway Buffered things makes sense using flush().

What do you thing about that?

Thanks in advance.





 
Ivan Jozsef Balazs
Rancher
Posts: 992
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many kinds out OutputStreams: bufferring, data- (outputting more-byte types), object-, compressing etc. ones. Flushing can make sense with many of them.

 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear in mind that you might not know whether an output stream uses buffering or not. (Does SocketOutputStream use buffering, for example?) Or you might have some code which assigns an output stream of unknown type to your OutputStream variable. So since calling flush() can't do any harm if the stream isn't buffering, it might be a good idea to call flush() to clear out any buffered data which might or might not be there, when necessary.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!