Java Utililty Methods Checksum Calculate

List of utility methods to do Checksum Calculate

Description

The list of methods to do Checksum Calculate are organized into topic(s).

Method

booleanchecksum(String nmea)
checksum
int len = nmea.length();
if (len < 3)
    return false;
try {
    String checksumString = nmea.substring(len - 2, len);
    int target = Integer.valueOf(checksumString, 16);
    int chk = computeChecksum(nmea);
    if (chk == target)
...
intchecksum_icmpv6(byte pkt[])
checksuicmpv
return checksum_icmpv6(pkt, 0);
StringchecksumBytesToString(byte[] digestBytes)
Converts a message digest byte array into a String based on the hex values appearing in the array.
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < digestBytes.length; i++) {
    String hex = Integer.toHexString(0xff & digestBytes[i]);
    if (hex.length() == 1) {
        hexString.append('0');
    hexString.append(hex);
return hexString.toString();
longchecksumFile(File file)
checksum File
return checksum(new FileInputStream(file));
intchecksumLength(int algorithmCode, int dataLength)
checksum Length
if (algorithmCode == NO_CHECKSUM) {
    return 0;
} else {
    return (int) Math.ceil((double) dataLength / CHECK_CHUNK_SIZE) * 8;
StringcreateChecksum(File file, String shaAlgo)
create Checksum
try {
    InputStream fis = new FileInputStream(file);
    byte[] buffer = new byte[1024];
    MessageDigest complete = MessageDigest.getInstance(shaAlgo);
    int numRead;
    do {
        numRead = fis.read(buffer);
        if (numRead > 0) {
...
StringgenerateChecksum(InputStream is)
generate Checksum
return generateChecksum(is, DEFAULT_ALGORITHM);
StringgenerateChecksum(String path, String flavor)
Creates a checksum for a file by first reading in its byte and passing those bytes through a formula that allows each chunk of bytes to be read as an integer and then made into a String
final byte[] digest = makeChecksum(path, flavor);
String output = "";
for (int i = 0; i < digest.length; i++) {
    int current = (digest[i] & 0xff) + 0x100;
    output += Integer.toString(current, 16).substring(1);
return output;
StringgenerateChecksum(String pType, String pInFile)
Generates a checksum for a file
if (!new File(pInFile).exists())
    throw new IOException("File not found: " + pInFile);
MessageDigest md;
try {
    md = MessageDigest.getInstance(pType.toUpperCase());
} catch (NoSuchAlgorithmException e) {
    return null;
FileInputStream input;
try {
    input = new FileInputStream(pInFile);
    byte[] readBuffer = new byte[BUFSIZE];
    int bytesRead = 0;
    while (input.available() > 0) {
        bytesRead = input.read(readBuffer);
        md.update(readBuffer, 0, bytesRead);
    input.close();
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
String hash = "";
for (byte b : md.digest())
    hash += String.format("%02x", b);
return hash;
StringgenerateCheckSum(String string)
This method generates a checksum from a passed string
try {
    MessageDigest md = MessageDigest.getInstance("MD5");
    md.update(string.getBytes());
    byte byteData[] = md.digest();
    StringBuilder hexString = new StringBuilder();
    for (byte aByteData : byteData) {
        String hex = Integer.toHexString(0xff & aByteData);
        if (hex.length() == 1)
...