title: How to kill a BufferedInputStream .read() call
body: <p>I'm working on writing a program to download very large files (~2GB) from a server. I've written the program to be able to resume partially finished downloads,</p>
  
  <p>In order to simulate a bad internet connection, I've been pulling my ethernet cord out of my router while mid-download. Unfortunately, this causes my program to hang on the following call:
  <code>while((bytesRead = in.read(data)) &gt; 0)</code></p>
  
  <p>(Where bytesRead is an int, in is a BufferedInputStream built from an HttpURLConnection, and data is a byte array).</p>
  
  <p>I've tried to "interrupt" the call by calling in.close() on another thread, but it has no effect until the internet connection is restored (at which time an exception is thrown).</p>
  
  <p>Is there any way I can prevent a severed internet connection from freezing my program?</p>