railo.commons.lang
Class MD5Hash

java.lang.Object
  extended by railo.commons.lang.MD5Hash

public final class MD5Hash
extends Object


Constructor Summary
MD5Hash()
          Class constructor
 
Method Summary
 byte[] getHash()
          Gets this hash sum as an array of 16 bytes.
static byte[] getHash(byte[] b)
          Gets the MD5 hash of the given byte array.
static byte[] getHash(File f)
          Gets the MD5 hash of the given file.
static byte[] getHash(InputStream in)
          Gets the MD5 hash the data on the given InputStream.
static byte[] getHash(Resource f)
          Gets the MD5 hash of the given file.
static byte[] getHash(String s)
          Gets the MD5 hash of the given String.
static byte[] getHash(String s, String enc)
          Gets the MD5 hash of the given String.
 String getHashString()
          Returns 32-character hex representation of this hash.
static String getHashString(byte[] b)
          Gets the MD5 hash of the given byte array.
static String getHashString(File f)
          Gets the MD5 hash of the given file.
static String getHashString(InputStream in)
          Gets the MD5 hash the data on the given InputStream.
static String getHashString(Resource f)
          Gets the MD5 hash of the given file.
static String getHashString(String s)
          Gets the MD5 hash of the given String.
static String getHashString(String s, String enc)
          Gets the MD5 hash of the given String.
 void reset()
          Reset the MD5 sum to its initial state.
 String toString()
          Returns 32-character hex representation of this hash.
 void update(byte b)
          Updates this hash with a single byte.
 void update(byte[] buffer)
          Update this hash with the given data.
 void update(byte[] buffer, int length)
          Update this hash with the given data.
 void update(byte[] buffer, int offset, int length)
          Update this hash with the given data.
 void update(String s)
          Update this hash with a String.
 void update(String s, String enc)
          Update this hash with a String.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MD5Hash

public MD5Hash()
Class constructor

Method Detail

getHash

public byte[] getHash()
Gets this hash sum as an array of 16 bytes.

Returns:
Array of 16 bytes, the hash of all updated bytes.

getHashString

public String getHashString()
Returns 32-character hex representation of this hash.

Returns:
String representation of this object's hash.

getHash

public static byte[] getHash(byte[] b)
Gets the MD5 hash of the given byte array.

Parameters:
b - byte array for which an MD5 hash is desired.
Returns:
Array of 16 bytes, the hash of all updated bytes.

getHashString

public static String getHashString(byte[] b)
Gets the MD5 hash of the given byte array.

Parameters:
b - byte array for which an MD5 hash is desired.
Returns:
32-character hex representation the data's MD5 hash.

getHash

public static byte[] getHash(InputStream in)
                      throws IOException
Gets the MD5 hash the data on the given InputStream.

Parameters:
in - byte array for which an MD5 hash is desired.
Returns:
Array of 16 bytes, the hash of all updated bytes.
Throws:
IOException - if an I/O error occurs.

getHashString

public static String getHashString(InputStream in)
                            throws IOException
Gets the MD5 hash the data on the given InputStream.

Parameters:
in - byte array for which an MD5 hash is desired.
Returns:
32-character hex representation the data's MD5 hash.
Throws:
IOException - if an I/O error occurs.

getHash

public static byte[] getHash(File f)
                      throws IOException
Gets the MD5 hash of the given file.

Parameters:
f - file for which an MD5 hash is desired.
Returns:
Array of 16 bytes, the hash of all updated bytes.
Throws:
IOException - if an I/O error occurs.

getHash

public static byte[] getHash(Resource f)
                      throws IOException
Gets the MD5 hash of the given file.

Parameters:
f - file for which an MD5 hash is desired.
Returns:
Array of 16 bytes, the hash of all updated bytes.
Throws:
IOException - if an I/O error occurs.

getHashString

public static String getHashString(File f)
                            throws IOException
Gets the MD5 hash of the given file.

Parameters:
f - file array for which an MD5 hash is desired.
Returns:
32-character hex representation the data's MD5 hash.
Throws:
IOException - if an I/O error occurs.

getHashString

public static String getHashString(Resource f)
                            throws IOException
Gets the MD5 hash of the given file.

Parameters:
f - file array for which an MD5 hash is desired.
Returns:
32-character hex representation the data's MD5 hash.
Throws:
IOException - if an I/O error occurs.

getHash

public static byte[] getHash(String s)
Gets the MD5 hash of the given String. The string is converted to bytes using the current platform's default character encoding.

Parameters:
s - String for which an MD5 hash is desired.
Returns:
Array of 16 bytes, the hash of all updated bytes.

getHashString

public static String getHashString(String s)
Gets the MD5 hash of the given String. The string is converted to bytes using the current platform's default character encoding.

Parameters:
s - String for which an MD5 hash is desired.
Returns:
32-character hex representation the data's MD5 hash.

getHash

public static byte[] getHash(String s,
                             String enc)
                      throws UnsupportedEncodingException
Gets the MD5 hash of the given String.

Parameters:
s - String for which an MD5 hash is desired.
enc - The name of a supported character encoding.
Returns:
Array of 16 bytes, the hash of all updated bytes.
Throws:
UnsupportedEncodingException - If the named encoding is not supported.

getHashString

public static String getHashString(String s,
                                   String enc)
                            throws UnsupportedEncodingException
Gets the MD5 hash of the given String.

Parameters:
s - String for which an MD5 hash is desired.
enc - The name of a supported character encoding.
Returns:
32-character hex representation the data's MD5 hash.
Throws:
UnsupportedEncodingException - If the named encoding is not supported.

reset

public void reset()
Reset the MD5 sum to its initial state.


toString

public String toString()
Returns 32-character hex representation of this hash.

Overrides:
toString in class Object
Returns:
String representation of this object's hash.

update

public void update(byte[] buffer,
                   int offset,
                   int length)
Update this hash with the given data.

If length bytes are not available to be hashed, as many bytes as possible will be hashed.

Parameters:
buffer - Array of bytes to be hashed.
offset - Offset to buffer array.
length - number of bytes to hash.

update

public void update(byte[] buffer,
                   int length)
Update this hash with the given data.

If length bytes are not available to be hashed, as many bytes as possible will be hashed.

Parameters:
buffer - Array of bytes to be hashed.
length - number of bytes to hash.

update

public void update(byte[] buffer)
Update this hash with the given data.

Parameters:
buffer - Array of bytes to be hashed.

update

public void update(byte b)
Updates this hash with a single byte.

Parameters:
b - byte to be hashed.

update

public void update(String s)
Update this hash with a String. The string is converted to bytes using the current platform's default character encoding.

Parameters:
s - String to be hashed.

update

public void update(String s,
                   String enc)
            throws UnsupportedEncodingException
Update this hash with a String.

Parameters:
s - String to be hashed.
enc - The name of a supported character encoding.
Throws:
UnsupportedEncodingException - If the named encoding is not supported.


Copyright © 2012 Railo