net.sourceforge.jaulp.file.checksum
Class ChecksumUtils

java.lang.Object
  extended by net.sourceforge.jaulp.file.checksum.ChecksumUtils

public class ChecksumUtils
extends java.lang.Object

The Class ChecksumUtils is a utility class for computing checksum from files and byte arrays.

Version:
1.0
Author:
Asterios Raptis

Constructor Summary
ChecksumUtils()
           
 
Method Summary
static java.lang.String getChecksum(byte[] bytes, java.lang.String algorithm)
          Gets the checksum from the given byte array with an instance of MessageDigest object.
static long getChecksum(java.io.File file, boolean crc)
          Gets the checksum from the given file.
static java.lang.String getChecksum(java.io.File file, java.lang.String algorithm)
          Gets the checksum from the given file with an instance of MessageDigest object.
static long getCheckSumAdler32(byte[] bytes)
          Gets the checksum from the given byte array with an instance of Adler32 object.
static long getCheckSumAdler32(java.io.File file)
          Gets the checksum from the given file with an instance of Adler32 object.
static long getCheckSumCRC32(byte[] bytes)
          Gets the checksum from the given byte array with an instance of CRC32 object.
static long getCheckSumCRC32(java.io.File file)
          Gets the checksum from the given file with an instance of CRC32 object.
static void main(java.lang.String[] args)
          The main method.
 
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

main

public static void main(java.lang.String[] args)
                 throws java.io.FileNotFoundException,
                        java.io.IOException,
                        java.security.NoSuchAlgorithmException
The main method.

Parameters:
args - The args
Throws:
java.io.IOException - Signals that an I/O exception has occurred.
java.io.FileNotFoundException - Is thrown if the file is not found.
java.security.NoSuchAlgorithmException - Is thrown if the algorithm is not supported or does not exists.

getChecksum

public static long getChecksum(java.io.File file,
                               boolean crc)
                        throws java.io.FileNotFoundException,
                               java.io.IOException
Gets the checksum from the given file. If the flag crc is true than the CheckedInputStream is constructed with an instance of CRC32 object otherwise it is constructed with an instance of Adler32 object.

Parameters:
file - The file The file from what to get the checksum.
crc - The crc If the flag crc is true than the CheckedInputStream is constructed with an instance of CRC32 object otherwise it is constructed with an instance of Adler32 object.
Returns:
The checksum from the given file as long.
Throws:
java.io.FileNotFoundException - Is thrown if the file is not found.
java.io.IOException - Signals that an I/O exception has occurred.

getCheckSumAdler32

public static long getCheckSumAdler32(byte[] bytes)
Gets the checksum from the given byte array with an instance of Adler32 object.

Parameters:
bytes - The byte array.
Returns:
The checksum from the byte array as long.

getCheckSumAdler32

public static long getCheckSumAdler32(java.io.File file)
Gets the checksum from the given file with an instance of Adler32 object.

Parameters:
file - The file.
Returns:
The checksum from the file as long.

getCheckSumCRC32

public static long getCheckSumCRC32(byte[] bytes)
Gets the checksum from the given byte array with an instance of CRC32 object.

Parameters:
bytes - The byte array.
Returns:
The checksum from the byte array as long.

getCheckSumCRC32

public static long getCheckSumCRC32(java.io.File file)
Gets the checksum from the given file with an instance of CRC32 object.

Parameters:
file - The file.
Returns:
The checksum from the file as long.

getChecksum

public static java.lang.String getChecksum(byte[] bytes,
                                           java.lang.String algorithm)
                                    throws java.security.NoSuchAlgorithmException
Gets the checksum from the given byte array with an instance of MessageDigest object.

Parameters:
bytes - the byte array.
algorithm - the algorithm to get the checksum. This could be for instance "MD4", "MD5", "SHA-1", "SHA-256", "SHA-384" or "SHA-512".
Returns:
The checksum from the file as a String object.
Throws:
java.security.NoSuchAlgorithmException - Is thrown if the algorithm is not supported or does not exists.

getChecksum

public static java.lang.String getChecksum(java.io.File file,
                                           java.lang.String algorithm)
                                    throws java.security.NoSuchAlgorithmException
Gets the checksum from the given file with an instance of MessageDigest object.

Parameters:
file - the file.
algorithm - the algorithm to get the checksum. This could be for instance "MD4", "MD5", "SHA-1", "SHA-256", "SHA-384" or "SHA-512".
Returns:
The checksum from the file as a String object.
Throws:
java.security.NoSuchAlgorithmException - Is thrown if the algorithm is not supported or does not exists.


Copyright © 2010. All Rights Reserved.