title: Java NIO read() End Of Stream
body: <p>I'm using Java NIO in to accept, read and write in my server.</p>
  
  <p>In the <a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/nio/channels/SocketChannel.html#read%28java.nio.ByteBuffer%29" rel="nofollow">documentation</a> it said that the <code>SocketChannel.read()</code> function will return the number of bytes read from socket, and -1 if it reach end of stream.</p>
  
  <p>Now - i don't really understand what does <code>"End Of Stream"</code> mean? is it as same as <code>borken pipe</code> error ?</p>
  
  <p>Does it mean that the connection is lost for both side and i should close the SocketChannel ?</p>
  
  <p>I would be really great full if someone can explain more about it - and give some example of using and behaving correctly according to it..</p>