@Override public String toString() { return getName(); } }
/** * Create a MessageDigest object that generates this type of checksum. */ public MessageDigest createMessageDigest() { try { return MessageDigest.getInstance(getName()); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("This is a bug in ChecksumType: " + e.getMessage(), e); } }
/** * Creates a new instance of Checksum based on supplied type and a * string of the checksum value in hexadecimal. If the type is ADLER32 * then the value may omit any leading zeros. * @param type The checksum algorithm. * @param value The hexadecimal representation of the checksum value. * @throws NullPointerException if either argument is null * @throws IllegalArgumentException if the value contains non-hexadecimal * characters or has the wrong length for the checksum type. */ public Checksum(ChecksumType type, String value) { checkNotNull(type, "type may not be null"); checkNotNull(value, "value may not be null"); this.type = type; this.value = normalise(type, value); checkArgument(HEXADECIMAL.matchesAllOf(this.value), "checksum value \"%s\" contains non-hexadecimal digits", value); checkArgument(this.value.length() == type.getNibbles(), "%s requires %d hexadecimal digits but \"%s\" has %d", type.getName(), type.getNibbles(), value, this.value.length()); }