com.starteam.util
Class MD5

java.lang.Object
  extended by com.starteam.util.MD5
All Implemented Interfaces:
java.io.Serializable

public final class MD5
extends java.lang.Object
implements java.io.Serializable

A 16 byte hash that uniquely identifies content across space and time

See Also:
Serialized Form

Nested Class Summary
static class MD5.Stream
          The MD5 of content digested from a stream, computed after the stream is closed
 
Constructor Summary
MD5()
          Construct an MD5
MD5(byte[] aSourceBytes)
          This constructor is expecting (previously computed) MD5 bytes themselves.
MD5(MD5 aMD5)
          Construct an MD5 from another
MD5(java.lang.String stringMD5)
          Construct a new MD5 with the given String value.
 
Method Summary
 void computeBufferMD5(byte[] data)
          Compute MD5 for a byte array.
 long computeFileMD5(java.io.File file)
          Compute MD5 on a file and return file length.
 long computeStreamMD5(java.io.InputStream in)
          Compute MD5 on a file and return file length.
 boolean equals(java.lang.Object obj)
          Return true if the given byte[] is identical to this object.
 byte[] getData()
          Return the byte[] of this object's value.
 int hashCode()
          Return a hashcode for this MD5 value.
 void setData(byte[] aSource)
          set the data (payload) of an MD5 - this is a precomputed MD5 byte array
 java.lang.String toHexString()
          Return the a 32-character String equal to the hex equivalent of this MD5 value.
 java.lang.String toString()
          returns a quasi-readable string representation of this MD5
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MD5

public MD5()
Construct an MD5


MD5

public MD5(byte[] aSourceBytes)
This constructor is expecting (previously computed) MD5 bytes themselves. If you need to construct an MD5 for given content, you should be using computeBufferMD5(byte[]).

Parameters:
aSourceBytes - byte[] from previously computed MD5 bytes

MD5

public MD5(MD5 aMD5)
Construct an MD5 from another

Parameters:
aMD5 - another MD5

MD5

public MD5(java.lang.String stringMD5)
Construct a new MD5 with the given String value.

Parameters:
stringMD5 - A 32-character hex value of an MD5 value.
Throws:
java.lang.IllegalArgumentException - If the given value is not 32 characters.
NumberFormatExcpetion - If the given value does not contain all hexadecimal characters (a-z, A-Z, or 0-9).
Method Detail

hashCode

public int hashCode()
Return a hashcode for this MD5 value. Uses the same algorithm as String.hashCode().

Overrides:
hashCode in class java.lang.Object
Returns:
A hash code that distributes nicely based on this object's content, which makes it suitable for hash tables, etc.

equals

public boolean equals(java.lang.Object obj)
Return true if the given byte[] is identical to this object.

Overrides:
equals in class java.lang.Object
Parameters:
obj - Object to be compared.
Returns:
True if the given object is an MD5 object with the same MD5 value.

computeBufferMD5

public void computeBufferMD5(byte[] data)
Compute MD5 for a byte array.

Parameters:
data - the byte[] to compute and encode into an MD5

toHexString

public java.lang.String toHexString()
Return the a 32-character String equal to the hex equivalent of this MD5 value.

Returns:
A 32-character String equal to the hex equivalent of this MD5 value.

toString

public java.lang.String toString()
returns a quasi-readable string representation of this MD5

Overrides:
toString in class java.lang.Object
Returns:
String a quasi-readable string representation of this MD5

computeStreamMD5

public long computeStreamMD5(java.io.InputStream in)
                      throws java.io.IOException
Compute MD5 on a file and return file length.

Parameters:
in - an input stream
Returns:
the length of the file
Throws:
java.io.IOException

computeFileMD5

public long computeFileMD5(java.io.File file)
                    throws java.io.IOException
Compute MD5 on a file and return file length.

Parameters:
file - the file whose md5 is to be computed
Returns:
the file length
Throws:
java.io.IOException

getData

public byte[] getData()
Return the byte[] of this object's value.

Returns:
The 16-byte array containing this object's raw binary value.

setData

public void setData(byte[] aSource)
set the data (payload) of an MD5 - this is a precomputed MD5 byte array

Parameters:
aSource - the MD5


StarTeam SDK 14.0, Build 21
Copyright © 2003-2012 Borland Software Corporation. All rights reserved.