Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2006

Tip: Looking for answers? Try searching our database.

Can someone explain what out.flush() does?

Thread view: 
computerkaitee@yahoo.com - 16 Feb 2006 20:39 GMT
Can someone explain what out.flush() does?  Or if you could direct me
to some documentation on it.  I can't seem to find it anywhere.
Oliver Wong - 16 Feb 2006 21:01 GMT
> Can someone explain what out.flush() does?  Or if you could direct me
> to some documentation on it.  I can't seem to find it anywhere.

   "out" is some object, and the "flush()" method is being called on that
object. To be pedantic, out could theoretically be any object, as long as
that object implements the "flush" method, and the "flush" method could do
anything.

   To be more helpful though, I'm guessing "out" here refers to
"System.out" or some sort of OutputStream. The API documentation for
OutputStream is at
http://java.sun.com/j2se/1.5.0/docs/api/java/io/OutputStream.html and the
documentation for its flush() method says:

<quote>
Flushes this output stream and forces any buffered output bytes to be
written out.
</quote>

   What this means is that when you tell an OutputStream to write
something, it might not actually write that data right away. There are
several reasons why it might delay writing. One might be that it's expensive
to set-up the environment in such a way so that writing becomes possible, so
the OutputStream will wait until it has a big chunk of data before actually
doing the writing.

   This is like when you go grocery shopping. You don't wanna leave your
house, buy eggs, come back, find out you're missing milk, leave your house,
buy milk, come back, find out you're missing bread, leave your house, etc.
You'd rather get a shopping list established first, so that you can buy
everything in one trip.

   The OutputStream has to store the data it's delaying somewhere, and the
place where it stores it is called the "buffer". To "flush the buffer" means
to actually write out the data in the buffer. OutputStreams will
automatically flush themselves every now and then, but there may be
situations where you really need them to flush at a particular point in
time. To accomplish this, you call the flush() method.

   - Oliver
computerkaitee@yahoo.com - 16 Feb 2006 22:04 GMT
Thanks, this is what I needed.
-Kaitee
Eric Sosman - 16 Feb 2006 21:02 GMT
computerkaitee@yahoo.com wrote On 02/16/06 15:39,:
> Can someone explain what out.flush() does?  Or if you could direct me
> to some documentation on it.  I can't seem to find it anywhere.

   What is `out'?  If you're referring to `System.out',
you should be able to find what you need in the Javadoc:

   - Look up the documentation for the System class, and
     you'll learn that `out' is a PrintStream.

   - Hyperlink to the PrintStream class, and you'll find a
     description of its flush() method.  The description
     is brief, but mentions that PrintStream's flush()
     is an override of FilterOutputStream's flush().
     Overriding methods are usually specializations or
     refinements of the overridden methods, so it makes
     sense to

   - ... hyperlink to the FilterOutputStream class, and
     you'll learn that its flush() method is also an
     override of the still higher OutputStream class. So

   - ... hyperlink to OutputStream, and you'll come to a
     more comprehensive description of what flush() does.

   If things still don't make sense after you've read this
stuff, come back and ask again.  But take a hint: If you're
going to get anywhere with Java, you'll need to develop some
skill in how to use the Javadoc.

Signature

Eric.Sosman@sun.com

Roedy Green - 17 Feb 2006 04:55 GMT
>Can someone explain what out.flush() does?  Or if you could direct me
>to some documentation on it.  I can't seem to find it anywhere.
see http://mindprod.com/jgloss/flush.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.