commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thoralf Rickert <thor...@m84.de>
Subject HTTPClient Feature Patch
Date Fri, 21 Feb 2003 08:15:30 GMT
Hi!

I'm not subribed to the list, so please make a CC to my address...

I'm working on a small WebDAV application based on the org.apache.webdav 
library. For user feedback it is necessary to know how many bytes a Put 
request has already finished (0%...25%...50%...75%...100%) (especially 
for big files). Because the WebDAV PutMethod extends the httpclient 
PutMethod which extends the
     org.apache.commons.httpclient.methods.EntityEnclosingMethod,
I would like to "submit" a small patch, which makes it possible to get 
the number of already sent bytes in a "controlling thread"....Here is 
the code:

package org.apache.commons.httpclient.methods;
[...]
public abstract class EntityEnclosingMethod extends GetMethod {
[...]
   private long writtenBytes = 0;
[...]
   protected boolean writeRequestBody(HttpState state,
                                      HttpConnection conn)
       throws IOException, HttpException {

     [....]
     writtenBytes = 0;
     byte[] tmp = new byte[4096];
     //int total = 0;
     int i = 0;
     while ((i = instream.read(tmp)) >= 0) {
       outstream.write(tmp, 0, i);
       //total += i;
       writtenBytes += i;
     }
     [....]
   }

   /**
    * Returns the Number of Request Body Bytes send to the server
    */
   public long getWrittenRequestBodyBytes() {
     return this.writtenBytes;
   }
}

If I would start the HttpConnection in a subthread I could call the 
getWrittenRequestBodyBytes() method (or however you call it) during 
upload to get the number of transfered bytes. So I can show the user, 
that the application still works...

Do you think, that this small patch is useful for you too or do you know 
another way?

Thanks,
Thoralf Rickert



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


Mime
View raw message