How do I calculate the checksum of a byte array?

John Zukowski

The Adler32 class in the java.util.zip package can be used to calculate the sum:

byte buffer[] = ...
ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
CheckedInputStream cis = new CheckedInputStream(bais, new Adler32());
byte readBuffer[] = new byte[128];
while (cis.read(readBuffer) >= 0);
long value = cis.getChecksum().getValue();
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.