You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by co...@jakarta.apache.org on 2004/05/29 10:20:34 UTC

[Jakarta Commons Wiki] New: IO/FrequentlyAskedQuestions

   Date: 2004-05-29T01:20:34
   Editor: RobertBurrellDonkin <rd...@apache.org>
   Wiki: Jakarta Commons Wiki
   Page: IO/FrequentlyAskedQuestions
   URL: http://wiki.apache.org/jakarta-commons/IO/FrequentlyAskedQuestions

   Added martin's explaination of DeferredOutputStream

New Page:

= Commons IO FrequentlyAskedQuestions =

 * What Use is DeferredOutputStream?

Details below:

== What Use is DeferredOutputStream? ==

''What use is DeferredOutputStream when the JDK already contains buffered output streams and writers?''

{{{
Here's the scenario it serves. Suppose you have some data that you'd
prefer to keep in memory, but you don't know ahead of time how much data
there is going to be. If there's too much, you want to write it to disk
instead of hogging memory, but you don't want to write to disk until you
need to, because disk is slow and is a resource that needs tracking for
cleanup.

So you create a temporary buffer and start writing to that. If / when you
reach the threshold for what you want to keep in memory, you'll need to
create a file, write out what's in the buffer to that file, and write all
subsequent data to the file instead of the buffer.

That's what DeferredOutputStream does for you. It hides all the messing
around at the point of switch-over. All you need to do is create the
deferred stream in the first place, configure the threshold, and then just
write away to your heart's content.

To be very specific, this is something that I needed for FileUpload, along
with its base class (ThresholdingOutputStream). After I created both of
these, I realised that there is nothing FileUpload-specific about them, so
I offerred, and subsequently added, them to IO.

If there is a straightforward way to accomplish the same task without a
class like this, then I'd be happy to be educated. This just seemed like a
good general purpose solution to the specific problem I had at the time.
;-)

}}}

'''Martin Cooper''' ([http://nagoya.apache.org/eyebrowse/ReadMsg?listName=commons-dev@jakarta.apache.org&msgNo=50446 on list])

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org