title: Java: Download always stalls
body: <p>Some days ago I run into a severe problem that gives me a headache:</p>
  
  <p>All Java based tools (Eclipse, Maven, Android SDK loader...) have problems downloading certain files: the download just stops at random. </p>
  
  <p>I already described my problem at <a href="https://superuser.com/questions/410883/downloads-stops-tcp-window-full">Superuser</a> but nobody was able to help me with my problem. Therefore started to perform some tests myself and ended up with the sample code at the end of this question.</p>
  
  <p>The interesting part is that the buffer size has an small influence on the problem. If I reduce the buffer size to 1024 the download completes in most cases.</p>
  
  <p>Does this code only make problems on my Windows system?</p>
  
  <p>To make it clear: I don't want to develop a download program with Java - therefore fixing the sample code does not help me - the code is only for demonstrating the problem.</p>
  
  <pre><code>public static void main(String[] args) {
      try {
          URL url = new URL("http://mirror.netcologne.de/maven2/com/google/android/android/2.3.3/android-2.3.3.jar");
  
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();
          InputStream in = conn.getInputStream();
          byte[] buffer = new byte[10485760]; // 10MiB
          long read = 0;
          while (true) {
              int bytes = in.read(buffer, 0, buffer.length);
              if (bytes &lt; 0)
                  break;
              read += bytes;
              System.out.println("Bytes read: " + read);
          }
          conn.disconnect();
          System.out.println("Finished");
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>