diff --git a/oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStore.java b/oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStore.java index b7787debfdd..75754351e21 100644 --- a/oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStore.java +++ b/oak-blob-plugins/src/main/java/org/apache/jackrabbit/oak/plugins/blob/datastore/OakFileDataStore.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.jackrabbit.oak.plugins.blob.datastore; import java.io.File; @@ -25,18 +24,15 @@ import java.io.InputStream; import java.lang.ref.WeakReference; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.AbstractMap; import java.util.ArrayList; +import java.util.Base64; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Set; import org.apache.jackrabbit.guava.common.base.Strings; -import org.apache.jackrabbit.guava.common.io.BaseEncoding; import org.apache.jackrabbit.guava.common.io.Closeables; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; @@ -95,7 +91,7 @@ protected byte[] getOrCreateReferenceKey() throws DataStoreException { * Set Base64 encoded signing key */ public void setReferenceKeyEncoded(String encodedKey) { - this.referenceKey = BaseEncoding.base64().decode(encodedKey); + this.referenceKey = Base64.getDecoder().decode(encodedKey); } /** diff --git a/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/AbstractBlobStore.java b/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/AbstractBlobStore.java index 63d6a8bf251..24ff274d877 100644 --- a/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/AbstractBlobStore.java +++ b/oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/AbstractBlobStore.java @@ -32,6 +32,7 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; +import java.util.Base64; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -44,7 +45,7 @@ import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; -import org.apache.jackrabbit.guava.common.io.BaseEncoding; +import org.apache.commons.codec.binary.Base32; import org.apache.commons.io.FileUtils; import org.apache.jackrabbit.oak.commons.cache.Cache; import org.apache.jackrabbit.oak.commons.IOUtils; @@ -135,6 +136,12 @@ public abstract class AbstractBlobStore implements GarbageCollectableBlobStore, */ private byte[] referenceKey; + /** + * Encode in Base 32, hex encoding, no line breaks, padding with "=" + */ + private static final Base32 BASE32ENCODER = + new Base32(0, new byte[0], true, (byte)'='); + private final Logger log = LoggerFactory.getLogger(getClass()); private BlobStatsCollector statsCollector = BlobStatsCollector.NOOP; @@ -237,7 +244,7 @@ public String getReference(@NotNull String blobId) { Mac mac = Mac.getInstance(ALGORITHM); mac.init(new SecretKeySpec(getReferenceKey(), ALGORITHM)); byte[] hash = mac.doFinal(blobId.getBytes("UTF-8")); - return blobId + ':' + BaseEncoding.base32Hex().encode(hash); + return blobId + ':' + BASE32ENCODER.encodeToString(hash); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(e); } catch (InvalidKeyException e) { @@ -307,7 +314,7 @@ public void setReferenceKey(byte[] referenceKey) { * @param encodedKey base64 encoded key */ public void setReferenceKeyEncoded(String encodedKey) { - setReferenceKey(BaseEncoding.base64().decode(encodedKey)); + setReferenceKey(Base64.getDecoder().decode(encodedKey)); } /** diff --git a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferenceBinaryIT.java b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferenceBinaryIT.java index bb63258f57a..be628a1c446 100644 --- a/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferenceBinaryIT.java +++ b/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/ReferenceBinaryIT.java @@ -23,6 +23,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.Base64; import java.util.Collection; import java.util.List; import java.util.Random; @@ -56,8 +57,6 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import org.apache.jackrabbit.guava.common.io.BaseEncoding; - @RunWith(Parameterized.class) public class ReferenceBinaryIT { @@ -179,7 +178,7 @@ private static BlobStore createBlobStore(){ OakFileDataStore fds = new OakFileDataStore(); byte[] key = new byte[256]; new Random().nextBytes(key); - fds.setReferenceKeyEncoded(BaseEncoding.base64().encode(key)); + fds.setReferenceKeyEncoded(Base64.getEncoder().encodeToString(key)); fds.setMinRecordLength(4092); fds.init(file.getAbsolutePath()); return new DataStoreBlobStore(fds);