net.anidb.checksum
Class Checksum

java.lang.Object
  extended by net.anidb.checksum.Checksum
Direct Known Subclasses:
Crc32Checksum, Ed2kChecksum, Md4Checksum, Md5Checksum, Sha160Checksum, TigerChecksum, TigerTreeChecksum

public abstract class Checksum
extends java.lang.Object

The super class of all checksum / hash classes.

Version:
1.0, 03.01.2010
Author:
grizzlyxp (http://anidb.net/perl-bin/animedb.pl?show=userpage&uid=63935)

Constructor Summary
Checksum()
          Creates a checksum object.
 
Method Summary
abstract  byte[] getDigest()
          Builds and returns the digest.
 java.lang.String getHexDigest()
          Calls getDigest() and returns the digest into a hex format.
abstract  void reset()
          Resets the checksum object.
abstract  void update(byte[] buf, int off, int len)
          Updates the checksum with data.
abstract  void update(int data)
          Updates the checksum with data.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Checksum

public Checksum()
Creates a checksum object.

Method Detail

getDigest

public abstract byte[] getDigest()

Builds and returns the digest.

After calling this method you have to use reset().

Returns:
The digest.
See Also:
reset(), getHexDigest()

getHexDigest

public java.lang.String getHexDigest()
Calls getDigest() and returns the digest into a hex format.

Returns:
The digest in hexdecimal presentation.
See Also:
getDigest()

reset

public abstract void reset()
Resets the checksum object.


update

public abstract void update(byte[] buf,
                            int off,
                            int len)
Updates the checksum with data.

Parameters:
buf - The data buffer.
off - The offset.
len - The length.
Throws:
java.lang.IllegalArgumentException - If the data buffer is null.
java.lang.IllegalArgumentException - If the offset is less than 0.
java.lang.IllegalArgumentException - If the length is less than 1.
java.lang.IllegalArgumentException - If the offset + the length is greater than the length of the data buffer.

update

public abstract void update(int data)
Updates the checksum with data.

Parameters:
data - The data.