Package org.icij.datashare.text
Enum Hasher
- java.lang.Object
-
- java.lang.Enum<Hasher>
-
- org.icij.datashare.text.Hasher
-
- All Implemented Interfaces:
Serializable,Comparable<Hasher>
public enum Hasher extends Enum<Hasher>
-
-
Field Summary
Fields Modifier and Type Field Description static CharsetDEFAULT_ENCODINGintdigestLength
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringgetHex(byte[] raw)byte[]hash(byte[] buffer)Stringhash(InputStream stream)Hash message from InputStreamStringhash(String message)Stringhash(String message, Charset charset)Hash message String with algorithm and charsetStringhash(Path filePath)Hash message from PathStringhash(Path filePath, String prefix)Hash message from Path and string prefixstatic Optional<Hasher>parse(String algo)Parse Hasher value from Stringstatic Stringshorten(String s, int l)StringtoString()static HashervalueOf(int length)Returns the enum constant of this type with the specified name.static HashervalueOf(String name)Returns the enum constant of this type with the specified name.static Hasher[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Field Detail
-
DEFAULT_ENCODING
public static final Charset DEFAULT_ENCODING
-
digestLength
public final int digestLength
-
-
Method Detail
-
values
public static Hasher[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (Hasher c : Hasher.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static Hasher valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
valueOf
public static Hasher valueOf(int length)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
length- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
getHex
public static String getHex(byte[] raw)
-
hash
public String hash(String message, Charset charset)
Hash message String with algorithm and charset- Parameters:
message- the String to hashcharset- the charset to use for message- Returns:
- the corresponding hash code String; empty if algorithm is UNKNOWN or NONE or if message is empty.
-
hash
public String hash(Path filePath)
Hash message from Path- Parameters:
filePath- representing the message to hash- Returns:
- the corresponding hash code String; empty if algorithm is UNKNOWN or NONE or nothing to take from stream.
-
hash
public String hash(Path filePath, String prefix)
Hash message from Path and string prefix- Parameters:
filePath- representing the message to hash- Returns:
- the corresponding hash code String; empty if algorithm is UNKNOWN or NONE or nothing to take from stream.
-
hash
public String hash(InputStream stream)
Hash message from InputStream- Parameters:
stream- the message to hash- Returns:
- the corresponding hash code String; empty if algorithm is UNKNOWN or NONE or nothing to take from stream.
-
parse
public static Optional<Hasher> parse(String algo)
Parse Hasher value from String- Parameters:
algo- the algorithm name as a String- Returns:
- the corresponding Optional Enum value if successful; empty Optional otherwise
-
hash
public byte[] hash(byte[] buffer)
-
-