title: Java: Premature EOF error when reading lines from webpage
body: <p>I am iterating through webpages line-by-line and sometimes get <code>java.io.IOException: Premature EOF</code>. I have seen reports of people getting this error from reading characters, but not whole lines, so I'm not sure what to do to get rid of this.</p>
  
  <p>The stack trace is:</p>
  
  <pre><code>Exception in thread "main" java.io.IOException: Premature EOF
      at sun.net.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:565)
      at sun.net.www.http.ChunkedInputStream.readAhead(ChunkedInputStream.java:609)
      at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:696)
      at java.io.FilterInputStream.read(FilterInputStream.java:133)
      at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3336)
      at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
      at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
      at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
      at java.io.InputStreamReader.read(InputStreamReader.java:184)
      at java.io.BufferedReader.fill(BufferedReader.java:161)
      at java.io.BufferedReader.readLine(BufferedReader.java:324)
      at java.io.BufferedReader.readLine(BufferedReader.java:389)
      at crawler.Crawler.crawl(SEC_Crawler.java:63)
  </code></pre>
  
  <p>And the code that causes it is:</p>
  
  <pre><code> for (String webpage_address : Webpages) {
          URL filing = new URL(webpage_address);
          BufferedReader read_filing = new BufferedReader(new InputStreamReader(filing.openStream()));
  
          for (String line = read_filing.readLine(); line != null; line = read_filing.readLine()) {
              // Process line
          }
  }
  </code></pre>