Skip to content

Instantly share code, notes, and snippets.

@adityasatrio
Created June 8, 2017 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adityasatrio/babc0b90b127b2aaf845fca369da379b to your computer and use it in GitHub Desktop.
Save adityasatrio/babc0b90b127b2aaf845fca369da379b to your computer and use it in GitHub Desktop.
to mba fai
private void validateCheckSum(DocumentUploadRequest documentUploadRequest) {
long checksumValue = Utilities.checksum(documentUploadRequest.getDocument().getBytes());
long checksumReq = Long.parseLong(documentUploadRequest.getDocumentChecksum());
Logger.info("Checksum Document request " + checksumReq);
Logger.info("Checksum Document calculate " + checksumValue);
if (checksumReq != checksumValue) {
Logger.info("Checksum Document calculate " + checksumValue);
throw new ConstraintValidationException("Checksum vallidation failed");
}
}
import java.util.zip.CRC32;
import java.util.zip.Checksum;
public static long checksum(byte[] file) {
Checksum checksumHash = new CRC32();
checksumHash.update(file, 0, file.length);
return checksumHash.getValue();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment