title: Byte array with padding of null bytes at the end: how to efficiently copy to smaller byte array
body: <p>Have:</p>
  
  <pre><code>[46][111][36][11][101][55][87][30][122][75][66][32][49][55][67][77][88][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0]
  </code></pre>
  
  <p>Want:</p>
  
  <pre><code>[46][111][36][11][101][55][87][30][122][75][66][32][49][55][67][77][88]
  </code></pre>
  
  <p>I have an array of bytes size 8192 to start, and starting at some index in that first array until the end of the array the bytes are all null bytes. So there might be 6000 bytes with values and 2196 null bytes at the end in the array. How do I efficiently create a new array of size (6000) and copy those bytes over? Note: I do not know how many null bytes, or bytes with values there will be.</p>