Download of files takes to much time
<pre><code> URL url = new URL(myurl);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setReadTimeout(10000 /* milliseconds */);
            conn.setConnectTimeout(15000 /* milliseconds */);
            conn.setRequestMethod("GET");
            conn.setDoInput(true);
            // Starts the query
            conn.connect();
            int response = conn.getResponseCode();
            Log.d("1", "The response is: " + response);


            in = new BufferedInputStream(conn.getInputStream());

            out = new FileOutputStream(file);

            int bufferLength = 0;
            byte[] buffer = new byte[1024];

            while ((bufferLength = in.read(buffer)) &gt; 0) {
                out.write(buffer, 0, bufferLength);
            } 
</code></pre>

<p>I am download small xml file, and then parsing it and creating objects from this file.</p>

<p>File size 3,8 kB. But it's take several second to show me some data after download start.
When I parse already downloaded file without internet connection it takes less then one second to show me data.
From that I concluded that problem is in this method.
PS I forgot to say, that it's downloading some small thumbnail pictures after that.</p>

<p>I've measured time</p>

<pre><code>@Override
protected ArrayList&lt;?&gt; parseData(File dataFile) {
    // TODO Auto-generated method stub
    long startTime = System.currentTimeMillis();




    ArrayList&lt;Training&gt; list = new ArrayList&lt;Training&gt;();
    MyParser parser = new MyParser();
    MyFileDownloader downloader = new MyFileDownloader();
    try {
        list = parser.parseTrainings(dataFile);
        boolean networkAvaible = fragment.isNetworkAvailable();
        for (int i = 0; i &lt; list.size(); i++) {
            if (networkAvaible)
                downloader.downloadFile(list.get(i).getImageURL(), new File(fragment.getDataFolder(), "image"+i));
            String path = fragment.getDataFolder().getPath() + "/image"+i;
            Drawable im = Drawable.createFromPath(path);
            list.get(i).setImage(im);
        }

    } catch (XPathExpressionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    long stopTime = System.currentTimeMillis();
    long elapsedTime = stopTime - startTime;
    Log.d("******TIME PASSED******", String.valueOf(elapsedTime));
    return list;
</code></pre>

<p>When there is internet connection and I need to download files it taking about 9-11 sec.
And when there is no need to download them it's taking about 0.5 sec. How can I decrease time of downloading this files?
The sum of file sizes is 5236 Mbits. It should be downloaded for less then 1 sec with my 20Mbps wi-fi. One or two seconds would be fine. But 9 or even 16 seconds? That's bad user experience.</p>
