title: BufferedInputStream.read() not reliably returning data to my app - data bunches up
body: <p>My app receives data through a serial port... they're typically small chunks of data. For example, sometimes it 40 bytes, sometimes 60 bytes. All the chunks of data are separated by a second, or possibly even a minute.</p>
  
  <p>I read that using BufferedInputStream is good for reading chunks of data so that the app doesn't create a lot of CPU overhead by reading data byte by byte.</p>
  
  <p>So that's what I did - just like this example: <a href="http://www.roseindia.net/java/example/java/io/ReadFilterFile.shtml" rel="nofollow">http://www.roseindia.net/java/example/java/io/ReadFilterFile.shtml</a></p>
  
  <p><strong>When it works, it works great!</strong>
  My app gets a complete chunk of data - I was worried that I would receive incomplete chunks, but no, to my amazement it's complete chunks.</p>
  
  <p><strong>However, sometimes it doesn't work so well</strong>
  What seems to happen is that a small chunk of data doesn't cause the read() method to complete. When a little bit larger chunk comes along later then finally the read() will return. This is undesirable !</p>
  
  <p>I do not want my app to be denied a chunk of data until another chunk arrives.</p>
  
  <p><strong>Question:</strong>
  How do I ensure that BufferedInputStream.read() returns shortly after a small chunk of data was received ? Is byte-by-byte read the only way ?</p>