Package com.fizzed.crux.util
Class Hasher
- java.lang.Object
-
- com.fizzed.crux.util.Hasher
-
public abstract class Hasher extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Hasher()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract byte[]asBytes()Closes the hasher (if not yet closed) and returns the result as bytes.abstract java.lang.StringasHex()Closes the hasher (if not yet closed) and returns the result as a hex-encoded valueabstract booleanisCompleted()static Hashermd5()Creates a new (open) MD5 hasher that is ready to accept a stream of bytes.static Hashermd5(java.io.File file)Creates a new (closed) MD5 hasher that has computed the digest for the file.static Hashermd5(java.io.InputStream input)Creates a new (closed) MD5 hasher that has computed the digest for the input.static Hashermd5(java.nio.file.Path file)Creates a new (closed) MD5 hasher that has computed the digest for the file.abstract Hasherupdate(byte[] buffer)Updates the hash/digest with the supplied byte buffer.abstract Hasherupdate(byte[] buffer, int offset, int length)Updates the hash/digest with the supplied byte buffer.abstract Hasherupdate(java.nio.ByteBuffer buffer)Updates the hash/digest with the supplied byte buffer.
-
-
-
Method Detail
-
update
public abstract Hasher update(java.nio.ByteBuffer buffer)
Updates the hash/digest with the supplied byte buffer. The hasher must still be OPEN otherwise this will throw an exception.- Parameters:
buffer-- Returns:
-
update
public abstract Hasher update(byte[] buffer)
Updates the hash/digest with the supplied byte buffer. The hasher must still be OPEN otherwise this will throw an exception.- Parameters:
buffer-- Returns:
-
update
public abstract Hasher update(byte[] buffer, int offset, int length)
Updates the hash/digest with the supplied byte buffer. The hasher must still be OPEN otherwise this will throw an exception.- Parameters:
buffer-offset-length-- Returns:
-
isCompleted
public abstract boolean isCompleted()
-
asBytes
public abstract byte[] asBytes()
Closes the hasher (if not yet closed) and returns the result as bytes.- Returns:
-
asHex
public abstract java.lang.String asHex()
Closes the hasher (if not yet closed) and returns the result as a hex-encoded value- Returns:
-
md5
public static Hasher md5()
Creates a new (open) MD5 hasher that is ready to accept a stream of bytes.- Returns:
-
md5
public static Hasher md5(java.io.File file) throws java.io.IOException
Creates a new (closed) MD5 hasher that has computed the digest for the file.- Parameters:
file- The file to compute MD5 digest- Returns:
- Throws:
java.io.IOException
-
md5
public static Hasher md5(java.nio.file.Path file) throws java.io.IOException
Creates a new (closed) MD5 hasher that has computed the digest for the file.- Parameters:
file- The file to compute MD5 digest- Returns:
- Throws:
java.io.IOException
-
md5
public static Hasher md5(java.io.InputStream input) throws java.io.IOException
Creates a new (closed) MD5 hasher that has computed the digest for the input.- Parameters:
input- The input to compute MD5 digest. The input will be read until its exhausted. Caller is responsible for closing the input!- Returns:
- Throws:
java.io.IOException
-
-