eu.planets_project.services.utils
Class Checksums

java.lang.Object
  extended by eu.planets_project.services.utils.Checksums

public class Checksums
extends Object

Checksums util class.


Constructor Summary
Checksums()
           
 
Method Summary
static byte[] digest(String algorithm, byte[] in)
          Calculate the checksum of a byte array.
static byte[] digest(String algorithm, File in)
          Calculate the checksum of a given File.
static byte[] digest(String algorithm, InputStream in)
          Calculate the checksum of a given InputStream.
static byte[] digest(String algorithm, String in)
          Calculate the checksum of a given String.
static byte[] md5(File in)
          Calculate the MD5 checksum of a File.
static byte[] md5(InputStream in)
          Calculate the MD5 checksum of a given stream.
static byte[] md5(String in)
          Calculate the MD5 checksum of a string.
static byte[] sha1(File in)
          Calculate the SHA-1 checksum of a File.
static byte[] sha1(InputStream in)
          Calculate the SHA-1 checksum of a given stream.
static byte[] sha1(String in)
          Calculate the SHA-1 checksum of a string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Checksums

public Checksums()
Method Detail

digest

public static byte[] digest(String algorithm,
                            InputStream in)
                     throws IOException,
                            NoSuchAlgorithmException
Calculate the checksum of a given InputStream. The stream is guaranteed to be closed after ended operation.

Parameters:
algorithm - the algorithm to use to compute the digest. Possbile values can be found in the Java CryptoSpec.
in - the stream to digest
Returns:
the computed digest in a byte array
Throws:
IOException - if there is an error reading the input stream
NoSuchAlgorithmException - if the algorithm requested in algorithm isn't known to the jvm.

digest

public static byte[] digest(String algorithm,
                            byte[] in)
                     throws NoSuchAlgorithmException
Calculate the checksum of a byte array. The array will be read in one chunk.

Parameters:
algorithm - the algorithm to use to compute the digest. Possbile values can be found in the Java CryptoSpec.
in - array the byte array to compute the digest of
Returns:
the computed digest in a byte array
Throws:
NoSuchAlgorithmException - if the algorithm requested in algorithm isn't known to the jvm.

digest

public static byte[] digest(String algorithm,
                            String in)
                     throws NoSuchAlgorithmException
Calculate the checksum of a given String.

Throws:
NoSuchAlgorithmException
See Also:
digest(String, java.io.InputStream)

digest

public static byte[] digest(String algorithm,
                            File in)
                     throws NoSuchAlgorithmException,
                            IOException
Calculate the checksum of a given File.

Throws:
NoSuchAlgorithmException
IOException
See Also:
digest(String, java.io.InputStream)

sha1

public static byte[] sha1(InputStream in)
                   throws IOException
Calculate the SHA-1 checksum of a given stream.

Throws:
IOException - if there is an error reading the stream

sha1

public static byte[] sha1(String in)
Calculate the SHA-1 checksum of a string.

Throws:
DigestException - if the JVM doesn't know the SHA-1 algorithm

sha1

public static byte[] sha1(File in)
                   throws IOException
Calculate the SHA-1 checksum of a File.

Throws:
IOException - if there is an error reading the file
DigestException - if the JVM doesn't know the SHA-1 algorithm

md5

public static byte[] md5(InputStream in)
                  throws IOException
Calculate the MD5 checksum of a given stream.

Throws:
IOException - if there is an error reading the stream
DigestException - if the JVM doesn't know the MD5 algorithm

md5

public static byte[] md5(String in)
Calculate the MD5 checksum of a string.

Throws:
DigestException - if the JVM doesn't know the MD5 algorithm

md5

public static byte[] md5(File in)
                  throws IOException
Calculate the MD5 checksum of a File.

Throws:
IOException - if there is an error reading the file
DigestException - if the JVM doesn't know the MD5 algorithm


Copyright © 2013 Open Planets Foundation. All Rights Reserved.