title: java how does readObject in objectinputstream knows how many bytes to read?
body: <p>In socket I/O, may I know how does a <code>objectinputstream</code> <code>readObject</code> knows how many bytes to read? Is the content length encapsulated inside the bytes itself or does it simply reads all the available bytes in the buffer itself?</p>
  
  <p>I am asking this because I was referring to the Python socket how-to and it says</p>
  
  <blockquote>
    <p>Now if you think about that a bit, you’ll come to realize a
    fundamental truth of sockets: messages must either be fixed length
    (yuck), or be delimited (shrug), or indicate how long they are (much
    better), or end by shutting down the connection. The choice is
    entirely yours, (but some ways are righter than others).</p>
  </blockquote>
  
  <p>However in another SO <a href="https://stackoverflow.com/questions/1501378/java-serialization-objectinputstream-readobject-check-if-will-block">answer</a>, @DavidCrawshaw mentioned that `</p>
  
  <blockquote>
    <p>So readObject() does not know how much data it will read, so it does
    not know how many objects are available.</p>
  </blockquote>
  
  <p>I am interested to know how it works...</p>