title: Reading what's available from Socket without blocking
body: <p>I am working on a server which reads data sent by the client, but the size is not known neither can I change the client to send the size.</p>
  
  <p>I want to read the data from client till it blocks and waits for server's response. I tried using <code>available()</code>, it works sometimes but sometimes it just returns zero even when there's some data in stream. </p>
  
  <pre><code>while((len = in.available()) != 0)
      in.read(b,0,len);
  </code></pre>
  
  <p>Is there any way to do this in Java? I'm aware of asynchronous methods, but have never tried that, so if someone can provide a short example.</p>