hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: How i can get information about the downloading process?
Date Tue, 16 Nov 2004 15:01:45 GMT
On Tue, Nov 16, 2004 at 09:37:21AM -0800, Gaspar wrote:
> Hi Oleg,
> 
> Yes i know that i can get the Response body with getResponseBodyAsStream,
> but i need that this line
> 
> statusCode = client.executeMethod(method);
> 
> finish the download process, for example if the file is 3MB over a 28Kb/s it
> can took 20mintutes, then 20minutes later i can do this:

Gaspar,
The whole point is that HttpClient#executeMethod method does NOT
retrieve the response content. This method executes the request, reads
the status line and response headers, makes sure that the response looks
sane and then terminates. At this point it is up to you what you do with
the response body. You can get it as one big chunk with
HttpMethod#getResponseBody or HttpMethod#getResponseBodyAsString, or as
a stream with HttpMethod#getResponseBodyAsStream and read the content out in
smaller chunks as you see fit

Hope this clarifies things a little

Oleg

> 
> responseBody = method.getResponseBodyAsStream();
>
> but i don't need this, i must read the amount of bytes on the buffer each 1
> second that let me calculate that Chris describe,
> 
> * the total number of bytes so far read (must be do each second to update
> the info)
> * determine the average speed so far by dividing the number of bytes
> downloaded by the time taken so far (must be do each second to update the
> info)
> 
> resuming: that i need is take control over the download process each 1
> seconds or less accessing the buffer that hold the bytes doanload so far to
> see how many bytes is download each 1seconds to update this info in the GUI,
> etc... maybe some code can help me.
> 
> do you understand me?, please maybe i don't get the point, sorry be patience
> :-), and very thanks! for the attention of the all community!
> 
> Thanks,
> Gaspar
> 
> ----- Original Message -----
> From: "Oleg Kalnichevski" <olegk@apache.org>
> To: "HttpClient Project" <httpclient-dev@jakarta.apache.org>
> Sent: Tuesday, November 16, 2004 1:00 AM
> Subject: Re: How i can get information about the downloading process?
> 
> 
> > On Mon, 2004-11-15 at 23:30 -0800, Gaspar wrote:
> > > Hi Mike,
> > >
> > > Yes but i think that with the Response body only i can't know "How
> > > many
> > > bytes is downloaded already?".
> > >
> >
> > Gaspar,
> > This is actually quite trivial. Just use
> > HttpMethod#getResponseBodyAsStream and you'll have a complete control
> > over the response retrieval process.
> >
> >
> > > My question, Is possible to built-in this
> > > feature in the future? or is imposible due to HttpClient use only Java
> > > Sync
> > > IO?.
> > >
> >
> > There's already a request for this feature. I'll be addressed in the
> > next major release of HttpClient (that is, 4.0):
> >
> > http://issues.apache.org/bugzilla/show_bug.cgi?id=10815
> >
> > Hope this helps
> >
> > Oleg
> >
> > >
> > > ----- Original Message -----
> > > From: "Michael Becke" <becke@u.washington.edu>
> > > To: "HttpClient Project" <httpclient-dev@jakarta.apache.org>
> > > Sent: Monday, November 15, 2004 8:06 PM
> > > Subject: Re: How i can get information about the downloading process?
> > >
> > >
> > > Hi Gaspar,
> > >
> > > HttpClient does not support timing directly.  There is no built-in way
> > > to get status on the request progress.  As Chris has described the only
> > > real timing that can be done is with the response body.
> > >
> > > Mike
> > >
> > > On Nov 15, 2004, at 11:14 PM, Gaspar wrote:
> > >
> > > > Hi Chris,
> > > >
> > > > First of all, thanks for your explanation, but maybe i don't explain
> > > > very
> > > > well what is my problem. Yes i know that this is the way to obtain
> this
> > > > information, but how you can did the algorithm that you describe if
> > > > the code
> > > > line (see below the number 1) don't return until it finish the
> download
> > > > process completely. do you understand now my doubt?. Maybe using
> > > > multithreading i can resolve this problem, but can i only resolve it
> > > > using
> > > > multithreading only?
> > > >
> > > > thanks in advance,
> > > > Gaspar
> > > >
> > > > Here is the code, see the line 1), is what i use to download the file.
> > > > ...
> > > >
> > > > HttpMethod method = new GetMethod(getURL().toString());
> > > >
> > > > ...
> > > >
> > > > // start the download process
> > > > line 1) statusCode = client.executeMethod(method);
> > > > ----- Original Message -----
> > > > From: "Chris Brown" <chris92250@hotmail.com>
> > > > To: <httpclient-dev@jakarta.apache.org>
> > > > Sent: Sunday, November 07, 2004 1:00 AM
> > > > Subject: RE: How i can get information about the downloading process?
> > > >
> > > >
> > > >> Hi Gaspar,
> > > >>
> > > >> If you use some of the approaches that let HTTPClient do all the hard
> > > >> work
> > > >> for you, you'll not have this feedback as far as I'm aware.
> > > >>
> > > >> But it's quite simple to get this information yourself.  If you open
> > > >> the
> > > >> connection and read data as a stream, you need to remember :
> > > >>
> > > >> * the time (e.g. System.currentTimeMillis()) you started as a "long"
> > > >> variable
> > > >>
> > > >> * the total number of bytes so far read as a "long" variable, updated
> > > >> each
> > > >> time you read some bytes from the stream
> > > >>
> > > >> * you can determine the average speed so far by dividing the number
> of
> > > > bytes
> > > >> downloaded by the time taken so far (see both points above); that's
> > > >> not
> > > >> necessarily your current speed
> > > >>
> > > >> * for the percentage remaining, you'll need to know in advance the
> > > >> size of
> > > >> what you're going to download (the HTTP response header
> > > >> "Content-Length"
> > > >> should help here, but you're not always going to get this
> > > >> information, and
> > > >> it's not always provided correctly by the server).
> > > >>
> > > >> You'll want multithreading no doubt, so make your "download" object
> > > >> expose
> > > >
> > > >> this information through "getter" methods.  You can then display this
> > > >> on
> > > > the
> > > >> command line, in a progress bar, or whatever.
> > > >>
> > > >> - Chris
> > > >>
> > > >>
> > > >>> From: "Gaspar" <gaspar@borderlessgroup.com>
> > > >>> Reply-To: "HttpClient Project" <httpclient-dev@jakarta.apache.org>
> > > >>> To: <httpclient-dev@jakarta.apache.org>
> > > >>> Subject: How i can get information about the downloading process?
> > > >>> Date: Sat, 6 Nov 2004 16:08:35 -0800
> > > >>>
> > > >>> Hi,
> > > >>>
> > > >>> My question is about how i can do with HttpClient, something that
i
> > > >>> see
> > > > on
> > > >>> many download manager software.
> > > >>>
> > > >>> About the file that i'm downloading using HttpClient i want to
get
> > > >>> this
> > > >>> information:
> > > >>>
> > > >>> - % of the file that is downloaded already.
> > > >>> - the size of what is downloaded already.
> > > >>> - the speed rate(b/s) of what is downloading.
> > > >>> - the time left to finish the download process.
> > > >>>
> > > >>> the downlaod manager that i use is ReGet Deluxe 3.3 and i want
do
> > > > something
> > > >>> similar with HttpClient.
> > > >>>
> > > >>> Thanks in advance,
> > > >>> Gaspar
> > > >>>
> > > >>>
> > > >>>
> > > >>>
> > >
> >>> ---------------------------------------------------------------------
> > > >>> To unsubscribe, e-mail:
> httpclient-dev-unsubscribe@jakarta.apache.org
> > > >>> For additional commands, e-mail:
> > > >>> httpclient-dev-help@jakarta.apache.org
> > > >>>
> > > >>
> > > >> _________________________________________________________________
> > > >> MSN Actions Solidaires : volontaire ? l'?tranger
> > > >> http://www.msn.fr/actionssolidaires/Default.asp?Ath=f
> > > >>
> > > >>
> > > >> ---------------------------------------------------------------------
> > > >> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> > > >> For additional commands, e-mail:
> > > >> httpclient-dev-help@jakarta.apache.org
> > > >>
> > > >
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
> httpclient-dev-help@jakarta.apache.org
> > > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
> >
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
> 

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


Mime
View raw message