TUM CCSM Commons

edu.tum.cs.commons.digest
Class MD5Digest

java.lang.Object
  extended by edu.tum.cs.commons.digest.MD5Digest
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<MD5Digest>

public final class MD5Digest
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable<MD5Digest>

An MD5 digest. This is just a thin thin wrapper around a byte array with some convenience methods and hashCode(), equals(Object) and compareTo(MD5Digest) implemented correctly. This class is used instead of plain strings to save both memory and (some) execution time. The class is immutable. Custom (de)serialization is provided to make this efficient to use in storage or RMI senarios.

Version:
$Rev: 26722 $
Author:
hummelb, $Author: heineman $
See Also:
Serialized Form
Rating:
GREEN Hash: 1F3799422871C3DC0A88A5AF75FE6BCD

Nested Class Summary
static class MD5Digest.Comparator
          Comparator for MD5Digest.
 
Field Summary
static int MD5_BYTES
          Number of bytes in an MD5 sum.
 
Constructor Summary
MD5Digest(byte[] digest)
          Constructor.
MD5Digest(java.security.MessageDigest digester)
          Constructor.
 
Method Summary
 int compareTo(MD5Digest o)
          
 boolean equals(java.lang.Object o)
          
 byte[] getBytes()
          Returns a copy of the internal byte representation.
 int hashCode()
          
 void insertIntoDigester(java.security.MessageDigest md)
          Inserts the digest data into the given MD.
 int partialHashCode()
          Calculates and returns a hashcode that only depends on the first 3 bytes.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MD5_BYTES

public static final int MD5_BYTES
Number of bytes in an MD5 sum.

See Also:
Constant Field Values
Constructor Detail

MD5Digest

public MD5Digest(java.security.MessageDigest digester)
Constructor. This calls MessageDigest.digest(), so the digester will be reset afterwards.


MD5Digest

public MD5Digest(byte[] digest)
Constructor.

Method Detail

insertIntoDigester

public void insertIntoDigester(java.security.MessageDigest md)
Inserts the digest data into the given MD. This method is used to rehash multiple hashes.

This method is provided instead of a getter, to keep this immutable.


hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

partialHashCode

public int partialHashCode()
Calculates and returns a hashcode that only depends on the first 3 bytes.


equals

public boolean equals(java.lang.Object o)

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(MD5Digest o)

Specified by:
compareTo in interface java.lang.Comparable<MD5Digest>

getBytes

public byte[] getBytes()
Returns a copy of the internal byte representation.


toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

TUM CCSM Commons

TUM CCSM Commons - 2.7