title: How to get number of elements in byte array?
body: <p>As everyone already knows, Java allocates the size of array upon declaration. meaning that if I define array like this:</p>
  
  <pre><code>byte[] buffer = new byte[10];
  </code></pre>
  
  <p>the <code>buffer.length</code> will return 10. However, my question is, how can I find out how many elements are populated. I am populating elements from an <code>InputStream</code> so I never know how many elements will be there.</p>
  
  <p>I know that allocated array positions which are empty will be <code>0</code> but what if I am getting zero values from the <code>InputStream</code> as well, mixed together with normal values?</p>