Re: [computing the] size of a downloaded resource => Lessons learned

Yves Lafon wrote:

> On Wed, 25 Feb 1998, Paul Pazandak wrote:
>
> >
> >  Lessons learned:
> >
> > We've found that there is a lot to determining the size of a downloaded resource
> > when Jigsaw acts as a proxy. First, if the resource is cached in the proxy or
> > on the client, then no resource is downloaded and there is no input stream (assuming
> > that the resource has not been modified and therefore the HTTP response is
> > "304 Not Modified").
> >
> > Second, if there is a valid reply, the input stream associated with the reply may or
> > may not support marking. If it does, then simply mark it, read it (and count the
> > length), and the reset it.  If it doesn't supporting marking, one can read it only
> > once. Therefore, (as far as I know) you must read it into a (string)buffer while
> > counting the bytes, then do a reply.setContent(new String(buffer)), then close
> > the stream. (Is there a better way?)
>
> When you use the cache, the stream is divided in two streams, using a tee
> (see w3c.www.protocol.http.cache.ActiveStream), this stream is used to
> dump the stream in one file (ie: create a resource) and send the stream
> directly to the client. Then just counting the bytes on the dumped stream
> is enough (it can be just a "StreamEater" for example, faster than using
> a stringbuffer... as we are using bytes (you must use readers and
> writers for strings).
> If the resource is already in the cache, the lenght info is already there.

I certainly like this solution better...Are you suggesting that I use something similar toCachedResource.tryActiveCacheContent() to generate my own
tee? If so, it looks like I'd have to write a class which implements
the TeeMonitor interface unless I can get a handle to a CachedResource
instance (which implements TeeMonitor).

When will creating a tee on a reply (which has an input stream) fail? Ever?

If the resource has already been cached, how do I get a ref to it so I can
acquire its length?

Regards,

Paul.






>
>
> > This should apply as well to any outgoing filter that wants to modify a reply
> > (i.e., it will need to be extracted from the input stream before it can be modified).
> >
> > Paul.
> >
> > p.s. a code snip is available if anyone is interested.
>
>       /\          - Yves Lafon - World Wide Web Consortium -
>   /\ /  \                Architecture Domain - Jigsaw
>  /  \    \/\
> /    \   /  \   http://www.w3.org/People/Lafon - ylafon@w3.org

   --

********************************************************************
Paul Pazandak                                      pazandak@objs.com
Object Services and Consulting, Inc.             http://www.objs.com
Minneapolis, Minnesota 55420-5409                       612-881-6498
********************************************************************

Received on Friday, 27 February 1998 11:24:54 UTC