title: java urlconnection doesnt throw sockettimeoutexception
body: <p>I consistently encounter java httpurlconnections, which, even with a <code>setReadTimeOut()</code>, will not throw a sockettimeoutexception when they should, and it is consistently associated with an eventual (after hanging for 2-3 minutes) Premature EOF Exception. I read in a few blogs that this may have to do with reading in using BufferedReader's readLine method, 
      String x = ""; while((x=bufferedReader.readLine())!=null){}</p>
  
  <p>at the end of a file if there is no new line character at the end of an inputstream. This does not make sense, why doesn't java's setTimeOut function correctly?</p>
  
  <pre><code>       URL url=new URL("");
        c=(HttpURLConnection)url.openConnection();
        c.setReadTimeout(17000);
        BufferedReader b = new BufferedReader(new InputStreamReader(c.getInputStream()));
        String s;
  
        while((s=b.readLine())!=null)
        {     
            } ect.
  
  
  
  
  
  
      java.io.IOException: Premature EOF
  at sun.net.www.http.ChunkedInputStream.readAheadBlocking(Unknown Source)
  at sun.net.www.http.ChunkedInputStream.readAhead(Unknown Source)
  at sun.net.www.http.ChunkedInputStream.read(Unknown Source)
  at java.io.FilterInputStream.read(Unknown Source)
  at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source)
  at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
  at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
  at sun.nio.cs.StreamDecoder.read(Unknown Source)
  at java.io.InputStreamReader.read(Unknown Source)
  at java.io.BufferedReader.fill(Unknown Source)
  at java.io.BufferedReader.readLine(Unknown Source)
  at java.io.BufferedReader.readLine(Unknown Source)
  </code></pre>
  
  <p>Here are the Response Headers (with exact cookie info truncated):</p>
  
  <pre><code>     [HTTP/1.1 200 OK]
       p3p ["",""]
       x-frame-options [SAMEORIGIN]
       Date [Tue, 08 May 2012 15:01:40 GMT]
       Vary [Accept-Encoding,User-Agent]
       Transfer-Encoding [chunked]
       Set-cookie [""=""; path=/; domain=""; expires=Tue, 01-Jan-2036 08:00:01 GMT]
       Content-Type [text/html; charset=ISO-8859-1]
       Server [Server]
  </code></pre>