Class Rsum

java.lang.Object
io.milton.zsync.Rsum
All Implemented Interfaces:
RollingChecksum, Serializable, Cloneable

public class Rsum extends Object implements RollingChecksum, Cloneable, Serializable
Implementation of rolling checksum for zsync purposes
Author:
Tomáš Hlavnička
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor of rolling checksum
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    check(byte[] buf, int offset, int length)
    Update the checksum with an entirely different block, and potentially a different block length.
    Copies this checksum instance into a new instance.
    boolean
    Tests if a particular checksum is equal to this checksum.
    void
    first(byte[] buf, int offset, int length)
    Update the checksum with an entirely different block, and potentially a different block length.
    int
    Return the value of the currently computed checksum.
    void
    Reset the checksum
    void
    roll(byte newByte)
    Rolling checksum that takes single byte and compute checksum of block from file in offset that equals offset of newByte minus length of block

    Methods inherited from class java.lang.Object

    finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Rsum

      public Rsum()
      Constructor of rolling checksum
  • Method Details

    • getValue

      public int getValue()
      Return the value of the currently computed checksum.
      Specified by:
      getValue in interface RollingChecksum
      Returns:
      The currently computed checksum.
    • reset

      public void reset()
      Reset the checksum
      Specified by:
      reset in interface RollingChecksum
    • roll

      public void roll(byte newByte)
      Rolling checksum that takes single byte and compute checksum of block from file in offset that equals offset of newByte minus length of block
      Specified by:
      roll in interface RollingChecksum
      Parameters:
      newByte - New byte that will actualize a checksum
    • check

      public void check(byte[] buf, int offset, int length)
      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.
      offset - From whence to begin reading.
      length - The length of the block to read.
    • first

      public void first(byte[] buf, int offset, int length)
      Update the checksum with an entirely different block, and potentially a different block length. This method is only used to initialize rolling checksum.
      Specified by:
      first in interface RollingChecksum
      Parameters:
      buf - The byte array that holds the new block.
      offset - From whence to begin reading.
      length - The length of the block to read.
    • 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.