org.purl.sword.base
Class ChecksumUtils

java.lang.Object
  extended by org.purl.sword.base.ChecksumUtils

public class ChecksumUtils
extends Object

Utility class that holds Checksum related methods.

Author:
Neil Taylor

Constructor Summary
ChecksumUtils()
           
 
Method Summary
static String generateMD5(byte[] bytes)
          Generate an MD5 hash for the file that is specified in the filepath.
static String generateMD5(InputStream md5Stream)
          Generate an MD5 hash for the file that is specified in the filepath.
static String generateMD5(String filepath)
          Generate an MD5 hash for the file that is specified in the filepath.
static void main(String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChecksumUtils

public ChecksumUtils()
Method Detail

generateMD5

public static String generateMD5(String filepath)
                          throws NoSuchAlgorithmException,
                                 IOException
Generate an MD5 hash for the file that is specified in the filepath. The hash is returned as a String representation.

Parameters:
filepath - The path to the file to load.
Returns:
A string hash of the file.
Throws:
NoSuchAlgorithmException - If the MD5 algorithm is not supported by the installed virtual machine.
IOException - If there is an error accessing the file.

generateMD5

public static String generateMD5(InputStream md5Stream)
                          throws NoSuchAlgorithmException,
                                 IOException
Generate an MD5 hash for the file that is specified in the filepath. The hash is returned as a String representation.

Parameters:
md5Stream - The InputStream to checksum.
Returns:
A string hash of the file.
Throws:
NoSuchAlgorithmException - If the MD5 algorithm is not supported by the installed virtual machine.
IOException - If there is an error accessing the file.

generateMD5

public static String generateMD5(byte[] bytes)
                          throws NoSuchAlgorithmException,
                                 IOException
Generate an MD5 hash for the file that is specified in the filepath. The hash is returned as a String representation.

Parameters:
bytes - The byte array to checksum.
Returns:
A string hash of the file.
Throws:
NoSuchAlgorithmException - If the MD5 algorithm is not supported by the installed virtual machine.
IOException - If there is an error accessing the file.

main

public static void main(String[] args)
                 throws NoSuchAlgorithmException,
                        IOException
Throws:
NoSuchAlgorithmException
IOException


Copyright © 2008 The DSpace Foundation. All Rights Reserved.