title: Read all InputStream values at once into a byte[] array
body: <p>Is there a way to read all InputStream values at once without a need of using some <code>Apache IO lib</code>?</p>
  
  <p>I am reading IR signal and saving it from the <code>InputStream</code> into the <code>byte[]</code> array. While debugging, I have noticed that it works only if I put a delay there, so that I read all bytes at once and then process it. </p>
  
  <p>Is there a smarter way to do it?</p>
  
  <p>CODE: </p>
  
  <pre><code> public void run() {
          Log.i(TAG, "BEGIN mConnectedThread");
          byte[] buffer = new byte[100];
          int numberOfBytes;
          removeSharedPrefs("mSharedPrefs");
          // Keep listening to the InputStream while connected
          while (true) {
              try {
                  // Read from the InputStream
                  numberOfBytes = mmInStream.read(buffer);
                  Thread.sleep(700);  //If I stop it here for a while, all works fine, because array is fully populated
                  if (numberOfBytes  &gt; 90){
                      // GET AXIS VALUES FROM THE SHARED PREFS
                      String[] refValues = loadArray("gestureBuffer", context);
                      if (refValues!=null &amp;&amp; refValues.length&gt;90) {
                          int incorrectPoints;
                          if ((incorrectPoints = checkIfGesureIsSameAsPrevious(buffer, refValues, numberOfBytes)) &lt; 5) {
                             //Correct
                          } else {
                             //Incorrect
                          }
                      }
                      saveArray(buffer, numberOfBytes);
                  }else{
                      System.out.println("Transmission of the data was corrupted.");
                  }
                  buffer = new byte[100];
                  // Send the obtained bytes to the UI Activity
                  mHandler.obtainMessage(Constants.MESSAGE_READ, numberOfBytes, -1, buffer)
                          .sendToTarget();
              } catch (IOException e) {
                  Log.e(TAG, "disconnected", e);
                  connectionLost();
                  // Start the service over to restart listening mode
                  BluetoothChatService.this.start();
                  break;
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
          }
      }
  </code></pre>