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, Stuart Lewis

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)
          Run a simple test to process the file.
 
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
Run a simple test to process the file.

Parameters:
args - The command line arguments.
Throws:
NoSuchAlgorithmException - If there was an error generating the MD5.
IOException - If there is an error accessing the file.


Copyright © 2010 The DSpace Foundation. All Rights Reserved.