InputStream.bytesRemaining is less than should be
<p>I have bunch of images from dozen or so sources and I am downloading them in background thread. Most of images are downloaded without problems but there are 2 sources that are causing problems. All images from them fail to load.</p>

<p>I am using following code to download (and store) images:</p>

<pre><code>File f=new File(cacheDir, urlHash);
Bitmap bitmap=null;
InputStream is=new URL(url).openStream();
OutputStream os = new FileOutputStream(f);
Utils.CopyStream(is, os);
os.close();
bitmap = BitmapFactory.decodeStream(new FileInputStream(f), null, null);
</code></pre>

<p>Utils.CopyStream : </p>

<pre><code>public static void CopyStream(InputStream is, OutputStream os)
{
    int counter = 0;
    final int buffer_size=1024;
    try
    {
        byte[] bytes=new byte[buffer_size];
        for(;;)
        {
          int count=is.read(bytes, 0, buffer_size);
          if(count==-1) {
              Log.d("tag", counter + " bytes copied");
              break;
          }
          os.write(bytes, 0, count);
          counter += count;
        }
    }
    catch(Exception ex) {
        ex.printStackTrace();
    }
}
</code></pre>

<p>when I try to download this image <a href="http://www.zapakatel.cz/static/deal/7193-1057b.jpg" rel="nofollow">http://www.zapakatel.cz/static/deal/7193-1057b.jpg</a> than it fails. BitmapFactory.decodeStream returns NULL. All I could find out about this that could cause a problem is that is.bytesRemaining is missing few thousands bytes: 162721 vs 179845 according to downloaded file size. When I manually download image from that url and upload it somewhere else, than everything works just fine. </p>

<p>Any idea what could cause problems? Is it possible that server hosting this image cuts me out before download is finished? This image load fine on any PC and even in my iphone app (I know that this is completely different platform and that it probably isn't important, I just find it weird)</p>
