org.metastatic.rsync
Class Checksum32

java.lang.Object
  |
  +--org.metastatic.rsync.Checksum32
All Implemented Interfaces:
Cloneable, RollingChecksum, Serializable

public class Checksum32
extends Object
implements RollingChecksum, Cloneable, Serializable

A simple 32-bit "rolling" checksum. This checksum algorithm is based upon the algorithm outlined in the paper "The rsync algorithm" by Andrew Tridgell and Paul Mackerras. The algorithm works in such a way that if one knows the sum of a block Xk...Xl, then it is a simple matter to compute the sum for Xk+1...Xl+1.

See Also:
Serialized Form

Field Summary
protected  int a
          The first half of the checksum.
protected  int b
          The second half of the checksum.
protected  byte[] block
          The block from which the checksum is computed.
protected  int char_offset
           
protected  int k
          The place from whence the current checksum has been computed.
protected  int l
          The place to where the current checksum has been computed.
protected  byte[] new_block
          The block that is recieving new input.
protected  int new_index
          The index in new_block where the newest byte has been stored.
 
Constructor Summary
Checksum32()
           
Checksum32(int char_offset)
          Creates a new rolling checksum.
 
Method Summary
 void check(byte[] buf, int off, int len)
          Update the checksum with an entirely different block, and potentially a different block length.
 Object clone()
          Copies this checksum instance into a new instance.
 boolean equals(Object o)
          Tests if a particular checksum is equal to this checksum.
 int getValue()
          Return the value of the currently computed checksum.
 void reset()
          Reset the checksum.
 void roll(byte bt)
          "Roll" the checksum.
 void trim()
          Update the checksum by trimming off a byte only, not adding anything.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

char_offset

protected final int char_offset

a

protected int a
The first half of the checksum.

Since:
1.1

b

protected int b
The second half of the checksum.

Since:
1.1

k

protected int k
The place from whence the current checksum has been computed.

Since:
1.1

l

protected int l
The place to where the current checksum has been computed.

Since:
1.1

block

protected byte[] block
The block from which the checksum is computed.

Since:
1.1

new_index

protected int new_index
The index in new_block where the newest byte has been stored.

Since:
1.1

new_block

protected byte[] new_block
The block that is recieving new input.

Since:
1.1
Constructor Detail

Checksum32

public Checksum32(int char_offset)
Creates a new rolling checksum. The char_offset argument affects the output of this checksum; rsync uses a char offset of 0, librsync 31.


Checksum32

public Checksum32()
Method Detail

getValue

public int getValue()
Return the value of the currently computed checksum.

Specified by:
getValue in interface RollingChecksum
Returns:
The currently computed checksum.
Since:
1.1

reset

public void reset()
Reset the checksum.

Specified by:
reset in interface RollingChecksum
Since:
1.1

roll

public void roll(byte bt)
"Roll" the checksum. This method takes a single byte as byte Xl+1, and recomputes the checksum for Xk+1...Xl+1. This is the preferred method for updating the checksum.

Specified by:
roll in interface RollingChecksum
Parameters:
bt - The next byte.
Since:
1.1

trim

public void trim()
Update the checksum by trimming off a byte only, not adding anything.

Specified by:
trim in interface RollingChecksum

check

public void check(byte[] buf,
                  int off,
                  int len)
Update the checksum with an entirely different block, and potentially a different block length.

Specified by:
check in interface RollingChecksum
Parameters:
buf - The byte array that holds the new block.
off - From whence to begin reading.
len - The length of the block to read.
Since:
1.1

clone

public Object clone()
Description copied from interface: RollingChecksum
Copies this checksum instance into a new instance. This method should be optional, and only implemented if the class implements the Cloneable interface.

Specified by:
clone in interface RollingChecksum
Overrides:
clone in class Object
Returns:
A clone of this instance.

equals

public boolean equals(Object o)
Description copied from interface: RollingChecksum
Tests if a particular checksum is equal to this checksum. This means that the other object is an instance of this class, and its internal state equals this checksum's internal state.

Specified by:
equals in interface RollingChecksum
Overrides:
equals in class Object
Parameters:
o - The object to test.
Returns:
true if this checksum equals the other checksum.