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).
Who-hoo! 29% speed improvement!
:-)
> All of these times were running through the debugger on my dev phone
> 2.
You might try running outside the debugger.
> 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.
Agreed. Still, something seems strange.
Let me know if droppin' the debuggah helps.
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy
_Android Programming Tutorials_ Version 2.0 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
[email protected]
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.