at.spardat.xma.boot.transform
Class HashChecksum

java.lang.Object
  extended byat.spardat.xma.boot.transform.HashChecksum

public class HashChecksum
extends java.lang.Object

Class for calculation checksum values for jar-files and plain files. For jar-files a MD5-hash is calculated over the contents of all files contained in the jar-file. Only the contents of the files determine the hash value, their names, timestamps etc. do not influence the hash value. For plain files (text files, native libs, etc.) a MD5-hash is clalculated over the content of the file.

Since:
1.3.0

Constructor Summary
HashChecksum()
           
 
Method Summary
static boolean areEqual(byte[] a, byte[] b)
          Compare two application descriptor hash codes
static java.lang.String calcCheckSum(byte[] data)
          Calculates the hashvalue over the content of a plain file or a native lib.
static java.lang.String calcFileCheckSum(java.io.File file)
          Calculates the hashvalue for a plain file or a native lib.
static java.lang.String calcJarCheckSum(java.io.File file)
          Calculates the hasvalue for jar-files.
static java.lang.String toHexString(byte[] data)
          Converts the given binary data int a hexadezimal string representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HashChecksum

public HashChecksum()
Method Detail

calcJarCheckSum

public static java.lang.String calcJarCheckSum(java.io.File file)
                                        throws java.io.IOException
Calculates the hasvalue for jar-files. It is calculated over all contained files. The order of the files in the jar-file is significant. The timestamps of the files do not influence the hash value.

Parameters:
file - the jar-file to calculate the hash value for.
Returns:
the calculated checksum
Throws:
java.io.IOException - on errors reading the file

calcFileCheckSum

public static java.lang.String calcFileCheckSum(java.io.File file)
                                         throws java.io.IOException
Calculates the hashvalue for a plain file or a native lib. The binary content of the file is hashed. Every change to the file content leads to a change in the resulting hash value.

Parameters:
file - the jar-file to calculate the hash value for.
Returns:
the calculated checksum
Throws:
java.io.IOException - on errors reading the file
Since:
1.3.0

calcCheckSum

public static java.lang.String calcCheckSum(byte[] data)
Calculates the hashvalue over the content of a plain file or a native lib. Every change to the given data leads to a change in the resulting hash value.

Parameters:
data - the bytes over which to caluclate the checksum
Returns:
the calculated checksum
Since:
1.3.0

toHexString

public static java.lang.String toHexString(byte[] data)
Converts the given binary data int a hexadezimal string representation.

Parameters:
data - to convert
Returns:
the converted data
Since:
1.3.0

areEqual

public static boolean areEqual(byte[] a,
                               byte[] b)
Compare two application descriptor hash codes

Returns:
true if both byte arrays contain the same sequence of bytes false otherwise