Class 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 in newBlock where the newest byte has been stored.
      protected int pos
      The place from whence the current checksum has been computed.
    • 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 java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • 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.
      • newIndex

        protected int newIndex
        The index in newBlock where the newest byte has been stored.
      • 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.
    • Method Detail

      • getValue

        public int getValue()
        Description copied from class: Fingerprinter
        Return the value of the currently computed checksum.
        Specified by:
        getValue in class Fingerprinter
        Returns:
        The currently computed checksum.
      • 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 class Fingerprinter
        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 class Fingerprinter
        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 class java.lang.Object
        Throws:
        java.lang.CloneNotSupportedException
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.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 class Fingerprinter