title: Fast way to compare inputstreams
body: <p>I have a problem, I need to compare two inputstreams fast.</p>
  
  <p>Today I have a function like this:</p>
  
  <pre><code>private boolean isEqual(InputStream i1, InputStream i2) throws IOException {
  
      try {
          // do the compare
          while (true) {
              int fr = i1.read();
              int tr = i2.read();
  
              if (fr != tr)
                  return false;
  
              if (fr == -1)
                  return true;
          }
  
      } finally {
          if (i1 != null)
              i1.close();
          if (i2 != null)
              i2.close();
      }
  }
  </code></pre>
  
  <p>But it's really slow. I want to use buffered reads but have not come up with a good way of doing it.</p>
  
  <p>Some extra stuff that makes it harder:</p>
  
  <ul>
  <li>I don't want to read one of the input streams into memory (the whole one)</li>
  <li>I don't want to use a third party library</li>
  </ul>
  
  <p><strong>I need a practial solution - code! :)</strong> </p>