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 intaThe first half of the checksum.protected intbThe second half of the checksum.protected byte[]blockThe block from which the checksum is computed.protected intcharOffsetprotected intlenThe place to where the current checksum has been computed.protected byte[]newBlockThe block that is receiving new input.protected intnewIndexThe index innewBlockwhere the newest byte has been stored.protected intposThe 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 voidcheck(byte[] buf, int off, int len)Update the checksum with an entirely different block, and potentially a different block length.java.lang.Objectclone()booleanequals(java.lang.Object o)intgetValue()Return the value of the currently computed checksum.inthashCode()voidreset()Reset the checksum.voidroll(byte bt)"Roll" the checksum.java.lang.StringtoString()Returns a string representation of the fingerprinter implementation.voidtrim()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:FingerprinterReturn the value of the currently computed checksum.- Specified by:
getValuein classFingerprinter- Returns:
- The currently computed checksum.
-
reset
public void reset()
Description copied from class:FingerprinterReset the checksum.- Specified by:
resetin 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:
rollin 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:FingerprinterUpdate the checksum with an entirely different block, and potentially a different block length.- Specified by:
checkin 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:
clonein classjava.lang.Object- Throws:
java.lang.CloneNotSupportedException
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
Description copied from class:FingerprinterReturns a string representation of the fingerprinter implementation.- Specified by:
toStringin classFingerprinter
-
-