Package org.apache.hadoop.io
Class MD5Hash
java.lang.Object
org.apache.hadoop.io.MD5Hash
- All Implemented Interfaces:
Comparable<MD5Hash>,Writable,WritableComparable<MD5Hash>
A Writable for MD5 hash values.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classorg.apache.hadoop.io.MD5Hash.ComparatorA WritableComparator optimized for MD5Hash keys. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintCompares this object with the specified object for order.static MD5Hashdigest(byte[] data) Construct a hash value for a byte array.static MD5Hashdigest(byte[][] dataArr, int start, int len) Construct a hash value for an array of byte array.static MD5Hashdigest(byte[] data, int start, int len) Construct a hash value for a byte array.static MD5Hashdigest(InputStream in) Construct a hash value for the content from the InputStream.static MD5HashConstruct a hash value for a String.static MD5Hashdigest(org.apache.hadoop.io.UTF8 utf8) Construct a hash value for a String.booleanReturns true iffois an MD5Hash whose digest contains the same values.byte[]Returns the digest bytes.static MessageDigestCreate a thread local MD5 digester.longConstruct a half-sized version of this MD5.inthashCode()Returns a hash code value for this object.intReturn a 32-bit digest of the MD5.static MD5HashConstructs, reads and returns an instance.voidreadFields(DataInput in) Deserialize the fields of this object fromin.voidCopy the contents of another instance into this instance.voidSets the digest value from a hex string.toString()Returns a string representation of this object.voidwrite(DataOutput out) Serialize the fields of this object toout.
-
Field Details
-
MD5_LEN
public static final int MD5_LEN- See Also:
-
-
Constructor Details
-
MD5Hash
public MD5Hash()Constructs an MD5Hash. -
MD5Hash
Constructs an MD5Hash from a hex string.- Parameters:
hex- input hex.
-
MD5Hash
public MD5Hash(byte[] digest) Constructs an MD5Hash with a specified value.- Parameters:
digest- digest.
-
-
Method Details
-
readFields
Description copied from interface:WritableDeserialize the fields of this object fromin.For efficiency, implementations should attempt to re-use storage in the existing object where possible.
- Specified by:
readFieldsin interfaceWritable- Parameters:
in-DataInputto deseriablize this object from.- Throws:
IOException- any other problem for readFields.
-
read
Constructs, reads and returns an instance.- Parameters:
in- in.- Returns:
- MD5Hash.
- Throws:
IOException- raised on errors performing I/O.
-
write
Description copied from interface:WritableSerialize the fields of this object toout.- Specified by:
writein interfaceWritable- Parameters:
out-DataOuputto serialize this object into.- Throws:
IOException- any other problem for write.
-
set
Copy the contents of another instance into this instance.- Parameters:
that- that.
-
getDigest
public byte[] getDigest()Returns the digest bytes.- Returns:
- digest.
-
digest
Construct a hash value for a byte array.- Parameters:
data- data.- Returns:
- MD5Hash.
-
getDigester
Create a thread local MD5 digester.- Returns:
- MessageDigest.
-
digest
Construct a hash value for the content from the InputStream.- Parameters:
in- input stream.- Returns:
- MD5Hash.
- Throws:
IOException- raised on errors performing I/O.
-
digest
Construct a hash value for a byte array.- Parameters:
data- data.start- start.len- len.- Returns:
- MD5Hash.
-
digest
Construct a hash value for an array of byte array.- Parameters:
dataArr- dataArr.start- start.len- len.- Returns:
- MD5Hash.
-
digest
Construct a hash value for a String.- Parameters:
string- string.- Returns:
- MD5Hash.
-
digest
Construct a hash value for a String.- Parameters:
utf8- utf8.- Returns:
- MD5Hash.
-
halfDigest
public long halfDigest()Construct a half-sized version of this MD5. Fits in a long.- Returns:
- halfDigest.
-
quarterDigest
public int quarterDigest()Return a 32-bit digest of the MD5.- Returns:
- the first 4 bytes of the md5
-
equals
Returns true iffois an MD5Hash whose digest contains the same values. -
hashCode
public int hashCode()Returns a hash code value for this object. Only uses the first 4 bytes, since md5s are evenly distributed. -
compareTo
Compares this object with the specified object for order.- Specified by:
compareToin interfaceComparable<MD5Hash>
-
toString
Returns a string representation of this object. -
setDigest
Sets the digest value from a hex string.- Parameters:
hex- hex.
-