Stormtap Studios wrote:
> Thanks for the suggestion Mark,
> 
> I tried the following:
> 
>               HttpClient httpclient = new DefaultHttpClient();
>               HttpGet httpget = new HttpGet(<my URL>);
>               HttpResponse response = httpclient.execute(httpget);
>               HttpEntity entity = response.getEntity();
>               if (entity != null)
>               {
>                       InputStream stream = entity.getContent();
>                       byte buf[] = new byte[1024 * 1024];
>                       int numBytesRead;
>                       BufferedOutputStream fos = new BufferedOutputStream(new
> FileOutputStream(<my output file>));
>                       do
>                       {
>                               numBytesRead = stream.read(buf);
>                               if (numBytesRead > 0)
>                               {
>                                       fos.write(buf, 0, numBytesRead);
>                               }
>                       } while (numBytesRead > 0);
>                       fos.flush();
>                       fos.close();
>                       stream.close();
>                       buf = null;
>                       httpclient.getConnectionManager().shutdown();
>               }
> 
> I timed it with GregorianCalendar objects instantiated before and
> after the process.  It came in at 10.91 minutes (655 seconds).
> 
> I then tried the same code, but using a 1KB buffer instead of a 1MB
> buffer, this code came in at 713 seconds, 11.89 minutes.
> 
> I then timed my old code (in the first post) which clocked in at 15.43
> minutes (925 seconds).
> 
> All of these times were running through the debugger on my dev phone
> 2.
> 
> Do you think I would get any speed improvement if I tried to figure
> out how to implement the BinaryResponseHandler?  I found this
> HttpClient tutorial (http://hc.apache.org/httpcomponents-client/
> tutorial/pdf/httpclient-tutorial.pdf) but I'm still not clear on how
> the response handler would fit my needs.  From the example in the
> tutorial it seems like it returns a byte array, but that's not
> practical in my situation as the entity content would be ~6.5MB,
> better to write that to my file as I receive it.

I just tried your code on a Nexus One, over WiFi, and it downloaded a
5.9MB file in around 14 seconds.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

_The Busy Coder's Guide to *Advanced* Android Development_
Version 1.3 Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

To unsubscribe from this group, send email to 
android-beginners+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.

Reply via email to