hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From umpirsky <umpir...@gmail.com>
Subject Re: visualizing upload/download status in a statusbar
Date Tue, 21 Oct 2008 11:08:53 GMT

Excelent, but, how do you use this class?

olegk wrote:
> 
> On Thu, 2008-10-09 at 07:41 -0700, Marcel Schiffel wrote:
>> Hi,
>> hope you had a relaxing vacation. I'm still facing the problems described
>> two weeks ago and would be very grateful for some additional hints.
>> Here's
>> an extract of the client code: 
>> 
> 
> ...
> 
>> 
>> Many Thanks
>> Marcel
>> 
> 
> 
> import java.io.FilterOutputStream;
> import java.io.IOException;
> import java.io.OutputStream;
> 
> import org.apache.commons.httpclient.methods.RequestEntity;
> 
> public class CoutingRequestEntity implements RequestEntity {
>   
>     private final RequestEntity entity;
>     private final ProgressListener listener;
>     
>     public CoutingRequestEntity(
>             final RequestEntity entity, 
>             final ProgressListener listener) {
>         super();
>         this.entity = entity;
>         this.listener = listener;
>     }
> 
>     public long getContentLength() {
>         return this.entity.getContentLength();
>     }
> 
>     public String getContentType() {
>         return this.entity.getContentType();
>     }
> 
>     public boolean isRepeatable() {
>         return this.entity.isRepeatable();
>     }
> 
>     public void writeRequest(final OutputStream out) throws IOException
> {
>         this.entity.writeRequest(
>                 new CountingOutputStream(out, this.listener));
>     }
>     
>     public static interface ProgressListener {
>         
>         void transferred(long num);
>         
>     }
> 
>     public static class CountingOutputStream extends FilterOutputStream
> {
> 
>         private final ProgressListener listener;
>         private long transferred;
>         
>         public CountingOutputStream(
>                 final OutputStream out, 
>                 final ProgressListener listener) {
>             super(out);
>             this.listener = listener;
>             this.transferred = 0;
>         }
> 
>         public void write(byte[] b, int off, int len) throws IOException
> {
>             super.write(b, off, len);
>             this.transferred += len;
>             this.listener.transferred(this.transferred);
>         }
> 
>         public void write(int b) throws IOException {
>             super.write(b);
>             this.transferred++;
>             this.listener.transferred(this.transferred);
>         }
>         
>     }
> }
> 
> Hope this helps
> 
> Oleg
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/visualizing-upload-download-status-in-a-statusbar-tp19685137p20087978.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message