android


Android Download large amount of small files takes long


in my android app I have to download a large amount of about 500 files with a small file size (about 50 Kilobytes per file). I don't want to zip them.
This takes very long compared to downloading a single file same size.
(approx. 60 seconds vs. 15 seconds)
I know that downloading many little files taking longer is normal,
but is it in a normal range here? Maybe my code can be improved?
Thank you in advance!
private static void downloadsinglefile(String urlstring, String filename, final Activity a)
{
try {
URL fileurl = new URL(urlstring);
URLConnection urlConnection = fileurl.openConnection();
urlConnection.connect();
InputStream inputStream = new BufferedInputStream(urlConnection.getInputStream(), 8192);
File downloadedFile = new File(getmylocalappfolder(), filename);
OutputStream outputStream = new FileOutputStream(downloadedFile);
byte[] buffer = new byte[1024];
int read;
while ((read = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, read);
}
outputStream.flush();
outputStream.close();
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
downloadstate = 4; //4 is my error code
}
}
private static void downloadAllfiles(Arraylist<Downloadobject> downloadfilelist, Activity a)
{
new Thread(new Runnable()
{
public void run()
{
for (int j = 0; j < downloadfilelist.size(); j++)
{
Downloadobject obj = downloadfilelist.get(j);
File downloadfile = new File(obj.getlocalpath());
if (!downloadfile.exists())
{
try {
downloadsinglefile(obj.getonlinepath(), URLEncoder.encode(obj.filename(), "UTF-8"), a);
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
}
}).start();
}

Related Links

How to use a pdf document in an android app?
All icons of ActionMode Bar are not showing in Android?
Android Bending View canvas to give curl effect
Facebook Android SDK 4.1+
Android Studio, Sample Code - Not working
Android: setting an alarm clock from a broadcast receiver only works once
Intent for signal reception lost
I want to close my default camera activity(started using MediaStore.ACTION_IMAGE_CAPTURE) on some event from my activity. How can I achieve this?
AudioRecord using bluetooth headset
Design a Quiz activity which refreshes every 20 seconds (Reworked)
How to make a InboxStyle Notification small again after expanding it?
OnBackPressed only called on the second press
Share via Facebook Messenger App - ionic framework / Cordova apache
RecycleView Select multiples
Landscape imageview overlap toolbar and statusbar
Should I replace ActionBarActivity with AppCompatActivity?

Categories

HOME
algorithm
httparty
azure-stream-analytics
microsoftgraph
fuelux
codenvy
merge
google-spreadsheet
socket.io
devise
edge
zip
code-coverage
crystal-lang
endeca
mxgraph
redis-sentinel
opengl-es-3.0
ipmitool
zerobrane
modbus-tcp
entitymanager
searchview
vuejs
sigma.js
asp.net-core-webapi
symbols
googlebot
squashfs
angular-routing
zxing
slidetoggle
fable-f#
android-things
mql
boost-asio
recurring-events
papaparse
xv6
softmax
movilizer
microsoft-metro
outputcache
http-request
knime
importerror
dynamic-linq
builder
twilio-click-to-call
tf
java-bytecode-asm
pdf-conversion
payload
baidu
javafx-css
atlas
autosar
parfor
delta
cifilter
turbo-prolog
ikiwiki
database-relations
invoke-sqlcmd
false-sharing
file-move
extjs-grid
viola-jones
openbabel
packet-sniffers
filesplitting
lambda-architecture
dct
radiant
koala
epiceditor
traceability
insert-id
cardreader
swfobject
robotlegs
faye
agility.js
landscape-portrait
rmdir
creole
http-daemon
unattended-processing
cac
object-database
burndowncharts
mathematical-notation
scrubyt

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile