Reputation: 313
I'm developing an Android app which communicates with a web service. The webservice gets me some geometry files and because of that those files can get really really large.
Because you can't wait 1-3 minutes until you got the response I need to lower the loading time.
So here is some Code:
long startTime = System.currentTimeMillis(); InputStream is = httpResponse.getEntity().getContent(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; byte[] data = new byte[1000000]; while ((nRead = is.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } long endTime = System.currentTimeMillis(); Log.d("ARks", (endTime - startTime) / 1000 + " seconds");
The time it takes to do this is always between 50 and 75 seconds (and this with rather small files).
Is there a way to speed this thing up? Maybe some Android specific stuff to allow the app more bandwidth?
Upvotes: 1
Views: 145
Reputation: 206
If you know that bandwidth is your problem, compress your stream: http://docs.oracle.com/javase/6/docs/api/java/util/zip/GZIPInputStream.html
And if you don't need all the data before you can process it, reduce the size of your buffer. This will allow you to process some objects while others are coming across the wire.
Upvotes: 2