Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speed Up download time

I have 40 MB file in server and i am downloading my file using

HttpURLConnection c = (HttpURLConnection) u.openConnection();
 c.setRequestMethod("GET");
 c.setDoOutput(true);
 c.connect();
 FileOutputStream f = new FileOutputStream(new File("trips.xml"));


 InputStream in = c.getInputStream();

 byte[] buffer = new byte[1024];
 int len1 = 0;
 while ( (len1 = in.read(buffer)) != -1 ) {
  f.write(buffer,0, len1);

this code seems working fine but it is taking too long. is their any way I can make this process faster.

/minhaz

like image 993
minhaz Avatar asked Jul 21 '10 19:07

minhaz


1 Answers

Use larger input buffer than 1 KB. The faster you empty buffer, the faster network stack can continue downloading. This should help:

byte[] buffer = new byte[50*1024];
like image 76
tomash Avatar answered Oct 12 '22 13:10

tomash