Package io.milton.zsync
Class Rsum
java.lang.Object
io.milton.zsync.Rsum
- All Implemented Interfaces:
RollingChecksum,Serializable,Cloneable
Implementation of rolling checksum for zsync purposes
- Author:
- Tomáš Hlavnička
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheck(byte[] buf, int offset, int length) Update the checksum with an entirely different block, and potentially a different block length.clone()Copies this checksum instance into a new instance.booleanTests if a particular checksum is equal to this checksum.voidfirst(byte[] buf, int offset, int length) Update the checksum with an entirely different block, and potentially a different block length.intgetValue()Return the value of the currently computed checksum.voidreset()Reset the checksumvoidroll(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
-
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:
getValuein interfaceRollingChecksum- Returns:
- The currently computed checksum.
-
reset
public void reset()Reset the checksum- Specified by:
resetin interfaceRollingChecksum
-
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:
rollin interfaceRollingChecksum- 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:
checkin interfaceRollingChecksum- 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:
firstin interfaceRollingChecksum- 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
Description copied from interface:RollingChecksumCopies this checksum instance into a new instance. This method should be optional, and only implemented if the class implements theCloneableinterface.- Specified by:
clonein interfaceRollingChecksum- Overrides:
clonein classObject- Returns:
- A clone of this instance.
-
equals
Description copied from interface:RollingChecksumTests 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:
equalsin interfaceRollingChecksum- Overrides:
equalsin classObject- Parameters:
o- The object to test.- Returns:
trueif this checksum equals the other checksum.
-