FileDocCategorySizeDatePackage
Adler32.javaAPI DocExample1362Tue Dec 12 18:57:40 GMT 2000None

Adler32

public class Adler32 extends Object implements Checksum

Fields Summary
private int
value
private static final int
BASE
private static final int
NMAX
Constructors Summary
Methods Summary
public longgetValue()
Returns current checksum value.

        return (long)value & 0xffffffff;
    
public voidreset()
Reset Adler-32 checksum to initial value.

        value = 1;
    
public voidupdate(int b)
Update current Adler-32 checksum given the specified byte.


                 
        
        int s1 = value & 0xffff;
        int s2 = (value >> 16) & 0xffff;
        s1 += b & 0xff;
        s2 += s1;
        value = ((s2 % BASE) << 16) | (s1 % BASE);
    
public voidupdate(byte[] b, int off, int len)
Update current Adler-32 checksum given the specified byte array.

        int s1 = value & 0xffff;
        int s2 = (value >> 16) & 0xffff;

        while (len > 0) {
            int k = len < NMAX ? len : NMAX;
            len -= k;
            while (k-- > 0) {
                s1 += b[off++] & 0xff;
                s2 += s1;
            }
            s1 %= BASE;
            s2 %= BASE;
        }
        value = (s2 << 16) | s1;