diff options
author | Gabriel Harris-Rouquette <gabizou@me.com> | 2021-01-17 16:49:22 -0800 |
---|---|---|
committer | LexManos <LexManos@gmail.com> | 2021-01-17 17:28:00 -0800 |
commit | 631cd05e726092c51e95b52bb8a8bb6a2ae2cc42 (patch) | |
tree | 7508b126e2287f78a4d8f59c80c200f7c2d52646 /src/shared | |
parent | 5725530e7e8b379d506ca737e9ddd0f00c7f1e32 (diff) | |
download | Artifactural-631cd05e726092c51e95b52bb8a8bb6a2ae2cc42.tar.gz Artifactural-631cd05e726092c51e95b52bb8a8bb6a2ae2cc42.tar.bz2 Artifactural-631cd05e726092c51e95b52bb8a8bb6a2ae2cc42.zip |
Bump project to Gradle 6.8
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/java/com/amadornes/artifactural/base/util/HashFunction.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/shared/java/com/amadornes/artifactural/base/util/HashFunction.java b/src/shared/java/com/amadornes/artifactural/base/util/HashFunction.java index 61119e7..9fe4ea9 100644 --- a/src/shared/java/com/amadornes/artifactural/base/util/HashFunction.java +++ b/src/shared/java/com/amadornes/artifactural/base/util/HashFunction.java @@ -30,8 +30,6 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Locale; -import org.apache.commons.io.IOUtils; - //These are all standard hashing functions the JRE is REQUIRED to have, so add a nice factory that doesnt require catching annoying exceptions; public enum HashFunction { MD5("md5", 32), @@ -43,7 +41,8 @@ public enum HashFunction { private HashFunction(String algo, int length) { this.algo = algo; - this.pad = String.format("%0" + length + "d", 0); + // must specify locale to get correct number formatting + this.pad = String.format(Locale.ENGLISH, "%0" + length + "d", 0); } public String getExtension() { @@ -90,7 +89,12 @@ public enum HashFunction { } public String hash(InputStream stream) throws IOException { - return hash(IOUtils.toByteArray(stream)); + MessageDigest hash = get(); + byte[] buf = new byte[1024]; + int count = -1; + while ((count = stream.read(buf)) != -1) + hash.update(buf, 0, count); + return pad(new BigInteger(1, hash.digest()).toString(16)); } public String hash(byte[] data) { |