calculate InputStream Checksum - Java Security

Java examples for Security:CRC

Description

calculate InputStream Checksum

Demo Code


import java.io.*;
import java.net.*;
import java.util.*;
import java.util.zip.*;
import org.apache.log4j.*;

public class Main{
    public static long calculateChecksum(InputStream stream)
            throws IOException {
        CRC32 crc32 = new CRC32();
        int read;
        while ((read = stream.read()) != -1) {
            crc32.update(read);// ww  w. ja v a 2  s .  c o m
        }
        return crc32.getValue();
    }
}

Related Tutorials