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

bytecheckSum(byte value)
check Sum
return (byte) (value ^ (-1));
longcheckSum(byte[] b, int offset, int length)
Calculate an OpenType checksum from the array.
long checkSum = 0;
for (int i = offset; i < length; i += 4) {
    for (int j = 0; j < 4; j++) {
        if (j + i < length) {
            checkSum += (b[j + i] & 0xff) << (24 - 8 * j);
return checkSum & 0xffffffffL;
intchecksum(byte[] buf, int off, int len)
checksum
return update(buf, off, len) ^ 0xFFFFFFFF;
longchecksum(byte[] data)
Calculated the checksum of the given data array as a long value.
long crc64Number = 0;
for (int i = 0; i < data.length; ++i) {
    int symbol = data[i];
    long a = (crc64Number >>> 8);
    long b = (crc64Number ^ symbol) & 0xff;
    crc64Number = a ^ _crc64Array[(int) b];
return crc64Number;
...
shortchecksum(byte[] message, int offset, int count)
Standard internet checksum algorithm shared by IP, ICMP, UDP and TCP.
int sum = 0, cursor = 0;
while (cursor < count - 1) {
    sum += (int) integralFromBytes(message, offset + cursor, 2);
    cursor += 2;
if (cursor == count - 1) {
    sum += (message[offset + cursor] >= 0 ? message[offset + cursor]
            : message[offset + cursor] ^ 0xffffff00) << 8;
...
Stringchecksum(File file)
checksum
String checksum;
try {
    checksum = com.google.common.io.Files.hash(file, Hashing.md5()).toString();
} catch (IOException e) {
    throw Throwables.propagate(e);
return checksum;
longchecksum(File file)
Get checksum value of a file.
FileInputStream fInStream = new FileInputStream(file);
CheckedInputStream cInStream = new CheckedInputStream(fInStream, new CRC32());
BufferedInputStream bInStream = new BufferedInputStream(cInStream);
while (bInStream.read() != -1) {
return cInStream.getChecksum().getValue();
longchecksum(InputStream is)
Compute a checksum for the file or directory that consists of the name, length and the last modified date for a file and its children in case of a directory
CRC32 crc = new CRC32();
byte[] buffer = new byte[8192];
int l;
while ((l = is.read(buffer)) > 0) {
    crc.update(buffer, 0, l);
return crc.getValue();
longchecksum(InputStream is)
Compute a checksum for the file or directory that consists of the name, length and the last modified date for a file and its children in case of a directory
try {
    CRC32 crc = new CRC32();
    byte[] buffer = new byte[8192];
    int l;
    while ((l = is.read(buffer)) > 0) {
        crc.update(buffer, 0, l);
    return crc.getValue();
...
longchecksum(String filename)
Calculate a checksum for a file, based on the Adler32 algorithm invented by Mark Adler.
CheckedInputStream cis = new CheckedInputStream(new FileInputStream(filename), new Adler32());
byte[] buffer = new byte[128];
while (cis.read(buffer) >= 0)
    continue;
return cis.getChecksum().getValue();