title: HttpURLConnection setReadTimeout not working
body: <p>I am developing an application which requires downloading data from the server.<br>
  I use the following code, which works except that it got stuck sometimes at the midst of a file download.<br></p>
  
  <pre><code>try{
      URL url = new URL( dlUrl );
  
      con = (HttpURLConnection) url.openConnection();
      con.setConnectTimeout(1000); // timeout 1 sec
      con.setReadTimeout(1000); // timeout 1 sec
  
      // get file length
      int lenghtOfFile = con.getContentLength();
  
      is = url.openStream();
      String dir =  Environment.getExternalStorageDirectory() + "myvideos";
  
      File file = new File( dir );
      if( !file.exists() ){
          if( file.mkdir()){
              // directory succesfully created
          }
      }
  
      fos = new FileOutputStream(file + "/" +  "video.mp4");
      byte data[] = new byte[1024];
  
      long total = 0;
      while( (count = is.read(data)) != -1 ){
          total += count;
          publishProgress((int)((total*100)/lenghtOfFile));
          fos.write(data, 0, count);
      }
  } catch (Exception e) {
      Log.e(TAG, "DOWNLOAD ERROR = " + e.toString() );
  }
  finally{
   // close streams
  }
  </code></pre>
  
  <p>The problem could be that the WIFI connection I am using is unstable, or something missing with my code.<br>
  Now I want to add a work around when the download stops, but unfortunately <code>setReadTimeout</code> seems to have no effect!<br>
  I tried the solutions suggested in Stackoverflow but none did the job for me.<br>
  Am I missing some kind of settings? <br>
  Any ideas why setReadTimeout has no effect?</p>