Package org.syncany.chunk
Class Adler32Fingerprinter
- java.lang.Object
-
- org.syncany.chunk.Fingerprinter
-
- org.syncany.chunk.Adler32Fingerprinter
-
public class Adler32Fingerprinter extends Fingerprinter
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.The class has been adapted to work with the Syncany chunking classes.
-
-
Field Summary
Fields Modifier and Type Field Description 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
charOffset
protected int
len
The place to where the current checksum has been computed.protected byte[]
newBlock
The block that is receiving new input.protected int
newIndex
The index innewBlock
where the newest byte has been stored.protected int
pos
The place from whence the current checksum has been computed.
-
Constructor Summary
Constructors Constructor Description Adler32Fingerprinter()
Adler32Fingerprinter(int charOffset)
Creates a new rolling checksum.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
check(byte[] buf, int off, int len)
Update the checksum with an entirely different block, and potentially a different block length.java.lang.Object
clone()
boolean
equals(java.lang.Object o)
int
getValue()
Return the value of the currently computed checksum.int
hashCode()
void
reset()
Reset the checksum.void
roll(byte bt)
"Roll" the checksum.java.lang.String
toString()
Returns a string representation of the fingerprinter implementation.void
trim()
Update the checksum by trimming off a byte only, not adding anything.-
Methods inherited from class org.syncany.chunk.Fingerprinter
getInstance
-
-
-
-
Field Detail
-
charOffset
protected final int charOffset
-
a
protected int a
The first half of the checksum.
-
b
protected int b
The second half of the checksum.
-
pos
protected int pos
The place from whence the current checksum has been computed.
-
len
protected int len
The place to where the current checksum has been computed.
-
block
protected byte[] block
The block from which the checksum is computed.
-
newBlock
protected byte[] newBlock
The block that is receiving new input.
-
-
Constructor Detail
-
Adler32Fingerprinter
public Adler32Fingerprinter(int charOffset)
Creates a new rolling checksum. The charOffset argument affects the output of this checksum; rsync uses a char offset of 0, librsync 31.
-
Adler32Fingerprinter
public Adler32Fingerprinter()
-
-
Method Detail
-
getValue
public int getValue()
Description copied from class:Fingerprinter
Return the value of the currently computed checksum.- Specified by:
getValue
in classFingerprinter
- Returns:
- The currently computed checksum.
-
reset
public void reset()
Description copied from class:Fingerprinter
Reset the checksum.- Specified by:
reset
in classFingerprinter
-
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 classFingerprinter
- Parameters:
bt
- The next byte.
-
trim
public void trim()
Update the checksum by trimming off a byte only, not adding anything.
-
check
public void check(byte[] buf, int off, int len)
Description copied from class:Fingerprinter
Update the checksum with an entirely different block, and potentially a different block length.- Specified by:
check
in classFingerprinter
- Parameters:
buf
- The byte array that holds the new block.off
- From whence to begin reading.len
- The length of the block to read.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
Description copied from class:Fingerprinter
Returns a string representation of the fingerprinter implementation.- Specified by:
toString
in classFingerprinter
-
-