W3C home > Mailing lists > Public > www-jigsaw@w3.org > January to February 1998

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

From: Yves Lafon <ylafon@w3.org>
Date: Fri, 27 Feb 1998 09:58:17 +0100 (MET)
To: Paul Pazandak <pazandak@OBJS.com>
cc: www-jigsaw@w3.org
Message-ID: <Pine.GSO.3.96.980226162037.5486A-100000@tarantula.inria.fr>
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.

> 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    
Received on Friday, 27 February 1998 03:58:42 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:27 GMT