title: Java networking: evented Socket/InputStream
body: <p>I'm implementing an event-oriented layer over Java's Sockets, and I was wondering if there was a way to determine if there is data pending to read.</p>
  
  <p>My normal approach would be to read from the socket into a buffer, and call the provided callbacks when the buffer is filled over a given amount of bytes (which could be 0, if the callback needs to be fired every time anything arrives), but I suspect Java is already doing the buffering for me.</p>
  
  <p>Is the <code>available()</code> method of InputStream reliable for this? Should I just <code>read()</code> and do my own buffering on top of the Socket? Or is there another way?</p>