title: Java - How to check if BufferedReader contains line break before running readLine command
body: <p>I am trying to parse HTML from a website to get very specific data. The following method reads the source and outputs it as a string to be processed by other methods.</p>
  
  <pre><code>    StringBuilder source = new StringBuilder();
      URL url = new URL(urlIn);
      URLConnection spoof;
      spoof = url.openConnection();
      spoof.setRequestProperty( "User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)" );
  
      BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
      String strLine = "";
  
      while ((strLine = in.readLine()) != null){
          source.append(strLine);
      }
  
      return source.toString();
  </code></pre>
  
  <p>The problem that I'm having is that since I call this method multiple times with a different urlIn argument each time, sometimes the method gets stuck at the readLine command. I read that this is because readLine looks for a line break and if the BufferedReader object does not contain one for whatever reason, it will be stuck indefinitely. </p>
  
  <p>Is there a way to check whether my BufferedReader object contains a line break before I run the readLine command. I tried using an <code>if (in.toString().contains("\n"))</code> but that always returns false. Alternatively, could I add a "\n" at the end of my Buffered Reader "in" object every time just so that the while loop would break and not hang up indefinitely?</p>
  
  <p>Any help would be appreciated.</p>