Android Utililty Methods File Checksum

List of utility methods to do File Checksum

Description

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

Method

voidchecksumFile(final Checksum chk, final String fname)
Computes the checksum of a given file and adds it to the provided Checksum object.
BufferedInputStream bis = null;
FileInputStream fis = null;
try {
    fis = new FileInputStream(fname);
    bis = new BufferedInputStream(fis);
    int len = 0;
    byte[] bytes = new byte[8192];
    while ((len = bis.read(bytes)) >= 0) {
...
longcomputeChecksum(String path)
Returns the checksum of a given directory tree.
String dir = getDir(path);
Checksum checksum = new CRC32();
checksumDir(checksum, dir);
return checksum.getValue();
StringgetChecksum(String filePath)
get Checksum
FileInputStream file = new FileInputStream(filePath);
CheckedInputStream check = new CheckedInputStream(file, new CRC32());
BufferedInputStream in = new BufferedInputStream(check);
String checkSum = "";
while (in.read() != -1) {
if (in != null) {
    in.close();
...
booleanverifyChecksum(String path)
Computes the checksum of a given directory tree and verifies that it matches the checksum stored in a file at the root the that directory
long checksum_long = computeChecksum(path);
byte[] checksum1 = String.valueOf(checksum_long).getBytes();
byte[] checksum2 = new byte[checksum1.length];
File f = new File(getDir(path), CHECKSUM_FILENAME);
if (!f.exists()) {
    throw new FileNotFoundException(
            "FileUtil.verifyChecksum: Missing checksum file in "
                    + path);
...
intcheckSum(File f)
check Sum
long checksum = 0;
try {
    FileInputStream fileImg = new FileInputStream(f);
    do {
        byte[] block = new byte[2];
        int size = fileImg.read(block);
        if (size != 2) {
            break;
...