title: Java: How to test for EOF on an InputStream without blocking?
body: <p>I want to do something like this:</p>
  
  <pre><code>// Implement an interruptible read
  for(;;) {
    if (input.available() &gt; 0)
      buffer.append(input.read());
    else if (input.eof())
      return buffer;
    else
      Thread.sleep(250);
  }
  </code></pre>
  
  <p>If I didn't care about blocking, I would have done this:</p>
  
  <pre><code>for(;;) {
    c = input.read();
    if (c != -1)
      buffer.append(c);
    return buffer;
  }
  </code></pre>
  
  <p>But I do care, so I need to use available(), so how can I determine EOF?</p>