public class Adler32
extends java.lang.Object
implements java.util.zip.Checksum
#define BASE 65521 largest prime smaller than 65536 unsigned long update_adler32(unsigned long adler, unsigned char *buf, int len) { unsigned long s1 = adler & 0xffff; unsigned long s2 = (adler >> 16) & 0xffff; int n; for (n = 0; n < len; n++) { s1 = (s1 + buf[n]) % BASE; s2 = (s2 + s1) % BASE; } return (s2 << 16) + s1; } unsigned long adler32(unsigned char *buf, int len) { return update_adler32(1L, buf, len); }The NMAX optimization is so that we don't have to do modulo calculations on every iteration. NMAX is the max number of additions to make before you have to perform the modulo calculation.
Modifier and Type | Class and Description |
---|---|
static class |
Adler32.ChunkingAdler32 |
Constructor and Description |
---|
Adler32() |
Modifier and Type | Method and Description |
---|---|
long |
getValue()
Returns current checksum value.
|
static java.util.zip.Checksum |
makeChecksum() |
void |
reset()
Reset Adler-32 checksum to initial value.
|
void |
update(byte[] b,
int off,
int len)
Update current Adler-32 checksum given the specified byte array.
|
void |
update(int b)
Update current Adler-32 checksum given the specified byte.
|
public static java.util.zip.Checksum makeChecksum()
public void update(int b)
update
in interface java.util.zip.Checksum
public void update(byte[] b, int off, int len)
update
in interface java.util.zip.Checksum
public void reset()
reset
in interface java.util.zip.Checksum
public long getValue()
getValue
in interface java.util.zip.Checksum