private void verifyCopyResult(final FileStatus inputStat, final FileStatus outputStat)
      throws IOException {
      long inputLen = inputStat.getLen();
      long outputLen = outputStat.getLen();
      Path inputPath = inputStat.getPath();
      Path outputPath = outputStat.getPath();

      if (inputLen != outputLen) {
        throw new IOException("Mismatch in length of input:" + inputPath + " (" + inputLen
          + ") and output:" + outputPath + " (" + outputLen + ")");
      }

      // If length==0, we will skip checksum
      if (inputLen != 0 && verifyChecksum) {
        FileChecksum inChecksum = getFileChecksum(inputFs, inputStat.getPath());
        FileChecksum outChecksum = getFileChecksum(outputFs, outputStat.getPath());

        ChecksumComparison checksumComparison = verifyChecksum(inChecksum, outChecksum);
        if (!checksumComparison.equals(ChecksumComparison.TRUE)) {
          StringBuilder errMessage = new StringBuilder("Checksum mismatch between ")
            .append(inputPath).append(" and ").append(outputPath).append(".");

          boolean addSkipHint = false;
          String inputScheme = inputFs.getScheme();
          String outputScheme = outputFs.getScheme();
          if (!inputScheme.equals(outputScheme)) {
            errMessage.append(" Input and output filesystems are of different types.\n")
              .append("Their checksum algorithms may be incompatible.");
            addSkipHint = true;
          } else if (inputStat.getBlockSize() != outputStat.getBlockSize()) {
            errMessage.append(" Input and output differ in block-size.");
            addSkipHint = true;
          } else if (
            inChecksum != null && outChecksum != null
              && !inChecksum.getAlgorithmName().equals(outChecksum.getAlgorithmName())
          ) {
            errMessage.append(" Input and output checksum algorithms are of different types.");
            addSkipHint = true;
          }
          if (addSkipHint) {
            errMessage
              .append(" You can choose file-level checksum validation via "
                + "-Ddfs.checksum.combine.mode=COMPOSITE_CRC when block-sizes"
                + " or filesystems are different.\n")
              .append(" Or you can skip checksum-checks altogether with -no-checksum-verify,")
              .append(
                " for the table backup scenario, you should use -i option to skip checksum-checks.\n")
              .append(" (NOTE: By skipping checksums, one runs the risk of "
                + "masking data-corruption during file-transfer.)\n");
          }
          throw new IOException(errMessage.toString());
        }
      }
    }
Utility to compare the file length and checksums for the paths specified.
hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java