commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Cooper <>
Subject Re: [io] some criticism
Date Sat, 29 May 2004 04:39:30 GMT
On Thu, 27 May 2004, Henri Yandell wrote:

> some input for further io development.
> 4 points I think:
> 1) Writer doesn't like true/false filters. basically the Null pattern.
> Nothing bad here I reckon.
> 2) Writer doesn't like the And/Or lego style of filters. I like this lego
> style for comparators, but admit I don't do enough filter-ing to use them
> in Filters. Still, he mainly is against the lego style I think, so again,
> nothing to worry about.
> 3) DeferredOutputStream is pointless. Would be interesting to hear
> Martin's view on his statement here.

Well, that got my attention. ;-)

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

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

> 4) IOUtils.toByteArray. Couple of things here, one that it's a method
> created for symmetry which is better served by the JDK; two that IO lacks
> encoding consideration.
> Hen
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message