public boolean downloadAndVerifyChecksum(URL checksumURL,Path originalFile,Path checksumFile,@Nullable DownloadProgress progress,TimeValue timeout,Checksummer hashFunc) throws Exception {
  try {
    if (download(checksumURL,checksumFile,progress,timeout)) {
      byte[] fileBytes=Files.readAllBytes(originalFile);
      List<String> checksumLines=Files.readAllLines(checksumFile,Charsets.UTF_8);
      if (checksumLines.size() != 1) {
        throw new ElasticsearchCorruptionException("invalid format for checksum file (" + hashFunc.name() + "), expected 1 line, got: "+ checksumLines.size());
      }
      String checksumHex=checksumLines.get(0);
      String fileHex=hashFunc.checksum(fileBytes);
      if (fileHex.equals(checksumHex) == false) {
        throw new ElasticsearchCorruptionException("incorrect hash (" + hashFunc.name() + "), file hash: ["+ fileHex+ "], expected: ["+ checksumHex+ "]");
      }
      return true;
    }
  }
 catch (  FileNotFoundException|NoSuchFileException e) {
    return false;
  }
 finally {
    IOUtils.deleteFilesIgnoringExceptions(checksumFile);
  }
  return false;
}

public boolean downloadAndVerifyChecksum ( URL checksumURL , Path originalFile , Path checksumFile , @ Nullable DownloadProgress progress , TimeValue timeout , Checksummer hashFunc ) throws Exception { try { if ( download ( checksumURL , checksumFile , progress , timeout ) ) { byte [ ] fileBytes = Files . readAllBytes ( originalFile ) ; List < String > checksumLines = Files . readAllLines ( checksumFile , Charsets . UTF_8 ) ; if ( checksumLines . size ( ) != 1 ) { throw new ElasticsearchCorruptionException ( "invalid format for checksum file (" + hashFunc . name ( ) + "), expected 1 line, got: " + checksumLines . size ( ) ) ; } String checksumHex = checksumLines . get ( 0 ) ; String fileHex = hashFunc . checksum ( fileBytes ) ; if ( fileHex . equals ( checksumHex ) == false ) { throw new ElasticsearchCorruptionException ( "incorrect hash (" + hashFunc . name ( ) + "), file hash: [" + fileHex + "], expected: [" + checksumHex + "]" ) ; } return true ; } } catch ( FileNotFoundException | NoSuchFileException e ) { return false ; } finally { IOUtils . deleteFilesIgnoringExceptions ( checksumFile ) ; } return false ; }
download the given checksum url to the destination and check the checksum
