Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAK-11399: Remove usage of Guava io.BaseEncoding #1992

Merged
merged 5 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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 ':' + BASE32ENCODER.encodeToString(hash);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It used to be: return blobId + ':' +...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, so much for opening PRs while tests are still running, and making last-second changes.

} 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