Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
Expand Down
Loading