title: How to unblock InputStream.read() on Android?
body: <p>I have a thread in which the <code>read()</code> method of an <code>InputStream</code> is called in a loop. When there are no more bytes to read, the stream will block until new data arrives.</p>
  
  <p>If I call <code>close()</code> on the <code>InputStream</code> from a different thread, the stream gets closed, but the blocked <code>read()</code> call still remains blocked. I would assume that the <code>read()</code> method should now return with a value of <code>-1</code> to indicate the end of the stream, but it does not. Instead, it stays blocked for several more minutes until a tcp timeout occurs.</p>
  
  <p>How do I unblock the <code>close()</code> call?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Apparently, the regular JRE will throw a <code>SocketException</code> immediately when the stream or socket the blocking <code>read()</code> call corresponds to is <code>close()</code>'d. The Android Java runtime which I am using, however, will not.</p>
  
  <p>Any hints on a solution for the Android environment would be greatly appreciated.</p>