title: Faster way to read from Socket with ByteBuffer?
body: <p>I have connected by TCP to a socket which is constantly sending a large amount of data, which I need to read in. What I have so far is a byte buffer that is reading byte by byte in a while loop. But the test case I am using right now is about 3 MB, which takes a while to read when reading in byte by byte.</p>
  
  <p>Here is my code for this explanation:</p>
  
  <pre><code>ByteBuffer buff = ByteBuffer.allocate(3200000);
  while(true)
  {
       int b = in.read();
       if(b == -1 || buff.remaining() == 0)
       {
             break;
       }
       buff.put((byte)b);
  }
  </code></pre>
  
  <p>I know that byte buffers are not thread safe and I'm not sure if this could be made faster by possibly reading in multiple bytes at a time and then storing it in the buffer? What would be a way for me to speed this process up?</p>