title: Java - Why while(true){ inputStream.read(incomingData) } does not work?
body: <p>I want to ask simple question. Let's consider this psudo code: </p>
  
  <pre><code>InputStream is = socket.getInputStream(); 
  
  byte[] incomingData = new byte[1024];   
  int incomingDataLenght = 0;
  
  while(true)  {        
     incomingDataLenght =is.read(incomingData,0,incomingData.length);   
  }
  </code></pre>
  
  <p>does not working. </p>
  
  <p>But if you get byte array inside to while loop like </p>
  
  <pre><code>int incomingDataLenght = 0;
  
  while(true)  {     
      byte[] incomingData = new byte[1024];    
      incomingDataLenght =is.read(incomingData,0,incomingData.length);   
  }
  </code></pre>
  
  <p>everything is working well. The problem that i dont understand, when i declare a byte array, actually i'm declaring pointer. And one tour of while loop, i 'm giving that pointer to read method and it is filling my array which started from my declared pointer and i should use this pointer with fresh data. But in reality that does not work. </p>
  
  <p>Could some one explain why it is not working? </p>
  
  <h2><strong>Edit</strong></h2>
  
  <p>Sorry for my unclear question. I'm reading media bytes from socket and storing inside <code>ConcurrentLinkedQueue&lt;byte&gt;</code> for some buffering time(that is producer). Then my consumer thread is starting.  As i quoeted at above, when i move my array initialitizion inside the while loop, my data is gettin clear and my consumer thread can process my data successfully. </p>
  
  <p>I think my answer is secret from my question. Whenewer i store byte array inside the queue, I'm stroing the same pointer(which is byte[] incomingData's pointer). When i start reading from queue, i'm reading current time's data instead of buffered data.</p>
  
  <p>If this consideration is true, is that the best way to initialize array every while cycle? </p>