title: Reading a byte array from Socket
body: <p>I have already read the sun guide and different similar questions. I want to read some unknown number of bytes into an array from Socket. </p>
  
  <p>I have two options either I can use the <code>read(byte)</code> in a loop and add the bytes to byte array or I can use DataInputStream <code>readFully(byte[])</code> to read all the bytes into byte array. Which one is better and how do I find the size of byte array beforehand for allocation? Also, If I use the first approach how to append the bytes in the byte array.</p>
  
  <pre><code>while(in.read(b) ! = -1)
  {
   //Add to byte array, but how to append at the end?
  }
  </code></pre>
  
  <p>Can I use StringBuilder to receive the data, append to it and then do <code>toString().getBytes()</code>?</p>