You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by re...@apache.org on 2025/07/06 14:10:15 UTC
(jackrabbit-oak) 01/02: Revert "OAK-11792: remove usage of Guava common.hash"
This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch OAK-11793
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
commit 3b71f9824e9382c2d8218cb216e0ddcff8bf8dd7
Author: Julian Reschke <re...@apache.org>
AuthorDate: Sun Jul 6 15:08:59 2025 +0100
Revert "OAK-11792: remove usage of Guava common.hash"
This reverts commit 5beec487f8b8274fddc05f8a8ea3e83e8564d899.
---
.../oak/plugins/memory/AbstractBlob.java | 52 +++++-----------------
1 file changed, 12 insertions(+), 40 deletions(-)
diff --git a/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java b/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java
index 456d5040d7..f0bca90bf9 100644
--- a/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java
+++ b/oak-store-spi/src/main/java/org/apache/jackrabbit/oak/plugins/memory/AbstractBlob.java
@@ -20,12 +20,11 @@ package org.apache.jackrabbit.oak.plugins.memory;
import java.io.IOException;
import java.io.InputStream;
-import java.math.BigInteger;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.util.Arrays;
import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.guava.common.hash.HashCode;
+import org.apache.jackrabbit.guava.common.hash.Hashing;
+
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.commons.properties.SystemPropertySupplier;
import org.jetbrains.annotations.NotNull;
@@ -121,7 +120,7 @@ public abstract class AbstractBlob implements Blob {
// Blobs are immutable so we can safely cache the hash
if (hashCode == null) {
try {
- hashCode = HashCode.of(this.getNewStream().readAllBytes());
+ hashCode = Hashing.sha256().hashBytes(this.getNewStream().readAllBytes());
} catch (IOException e) {
throw new IllegalStateException("Hash calculation failed", e);
}
@@ -129,6 +128,14 @@ public abstract class AbstractBlob implements Blob {
return hashCode;
}
+ /**
+ * This hash code implementation returns the hash code of the underlying stream
+ * @return a byte array of the hash
+ */
+ protected byte[] sha256() {
+ return getSha256().asBytes();
+ }
+
//--------------------------------------------------------------< Blob >--
@Override @Nullable
@@ -182,39 +189,4 @@ public abstract class AbstractBlob implements Blob {
return getSha256().toString();
}
- public static class HashCode {
-
- private byte[] digest;
-
- private HashCode(byte[] digest){
- this.digest = digest;
- }
-
- private static HashCode of(byte[] bytes) {
- try {
- return new HashCode(MessageDigest.getInstance("SHA-256").digest(bytes));
- } catch (NoSuchAlgorithmException ex) {
- throw new IllegalStateException("no SHA256 digest", ex);
- }
- }
-
- @Override
- public boolean equals(Object o) {
- if (o == null || getClass() != o.getClass()) return false;
- return Arrays.equals(digest, ((HashCode)o).digest);
- }
-
- @Override
- public int hashCode() {
- return Arrays.hashCode(digest);
- }
-
- @Override
- public String toString() {
- // could use commons-coded
- BigInteger bigInteger = new BigInteger(1, digest);
- return String.format(
- "%0" + (digest.length << 1) + "x", bigInteger);
- }
- }
}