Class Checksum

java.lang.Object
org.opencastproject.util.Checksum
All Implemented Interfaces:
Serializable

public final class Checksum extends Object implements Serializable
This class stores value and type of a generated checksum.
See Also:
  • Field Details

    • value

      protected String value
      The checksum value
    • type

      protected ChecksumType type
      The checksum type
  • Constructor Details

    • Checksum

      public Checksum()
      Needed by JAXB
  • Method Details

    • getType

      public ChecksumType getType()
      Returns the checksum type.
      Returns:
      the type
    • getValue

      public String getValue()
      Returns the checksum value.
      Returns:
      the value
    • convertToHex

      public static String convertToHex(byte[] data)
      Converts the checksum to a hex string.
      Parameters:
      data - the digest
      Returns:
      the digest hex representation
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • fromString

      public static Checksum fromString(String checksum) throws NoSuchAlgorithmException
      Creates a checksum from a string in the form "value (type)".
      Parameters:
      checksum - the checksum in string form
      Returns:
      the checksum
      Throws:
      NoSuchAlgorithmException - if the checksum of the specified type cannot be created
    • create

      public static Checksum create(String type, String value) throws NoSuchAlgorithmException
      Creates a checksum of type type and value value.
      Parameters:
      type - the checksum type name
      value - the checksum value
      Returns:
      the checksum
      Throws:
      NoSuchAlgorithmException - if the checksum of the specified type cannot be created
    • create

      public static Checksum create(ChecksumType type, String value)
      Creates a checksum of type type and value value.
      Parameters:
      type - the checksum type
      value - the checksum value
      Returns:
      the checksum
    • create

      public static Checksum create(ChecksumType type, File file) throws IOException
      Creates a checksum of type type from the given file.
      Parameters:
      type - the checksum type
      file - the file
      Returns:
      the checksum
      Throws:
      IOException - if the file cannot be accessed
    • create

      public static Checksum create(ChecksumType type, InputStream is) throws IOException
      Creates a checksum of type type from the given input stream. The stream gets closed afterwards.
      Throws:
      IOException