title: IndexOutOfBoundsException in ByteBuffer's comparison java
body: <p>I have a problem with this method</p>
  
  <pre><code>private static boolean getBlocks(File file1, File file2) throws IOException {
      FileChannel channel1 = new FileInputStream(file1).getChannel();
      FileChannel channel2 = new FileInputStream(file2).getChannel();
      int SIZE = (int) Math.min((8192), channel1.size());
      int point = 0;
      MappedByteBuffer buffer1 = channel1.map(FileChannel.MapMode.READ_ONLY, 0, channel1.size());
      MappedByteBuffer buffer2 = channel2.map(FileChannel.MapMode.READ_ONLY, 0, channel2.size());
      byte [] bytes1 = new byte[SIZE];
      byte [] bytes2 = new byte[SIZE];
      while (point &lt; channel1.size() - SIZE) {
          buffer1.get(bytes1, point, SIZE);
          buffer2.get(bytes2, point, SIZE);
          if (!compareBlocks(bytes1, bytes2)) {
              return false;
          }
          point += SIZE;
      }
      return true;
  }
  
  private static boolean compareBlocks (byte[] bytes1, byte[] bytes2) {
      for (int i = 0; i &lt; bytes1.length; i++) {
          if (bytes1[i] != bytes2[i]) {
              return false;
          }
      }
      return true;
  }
  </code></pre>
  
  <p>In a result I caught IndexOutOfBoundsException in while loop.
  How can I get around this problem and compare two files by blocks?</p>