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-10691: remove use of Guava Charsets class #1342

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -20,14 +20,13 @@

import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.jackrabbit.guava.common.base.Charsets;
import org.apache.jackrabbit.guava.common.base.Splitter;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.guava.common.collect.Maps;
Expand Down Expand Up @@ -179,7 +178,7 @@ public static void main(String[] args) throws Exception {
if (options.has(scalabilityOptions.getCsvFile())) {
out =
new PrintStream(FileUtils.openOutputStream(scalabilityOptions.getCsvFile().value(options), true), false,
Charsets.UTF_8.name());
StandardCharsets.UTF_8);
}
for (ScalabilitySuite suite : suites) {
if (suite instanceof CSVResultGenerator) {
Expand Down
Expand Up @@ -29,10 +29,10 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.time.Instant;
import java.util.Collection;
Expand All @@ -46,7 +46,6 @@
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import org.apache.jackrabbit.guava.common.base.Charsets;
import org.apache.jackrabbit.guava.common.base.Function;
import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.guava.common.cache.Cache;
Expand Down Expand Up @@ -1183,9 +1182,9 @@ private URI createPresignedURI(String key,
StringBuilder builder = new StringBuilder();
for (Map.Entry<String, String> e : additionalQueryParams.entrySet()) {
builder.append("&");
builder.append(URLEncoder.encode(e.getKey(), Charsets.UTF_8.name()));
builder.append(URLEncoder.encode(e.getKey(), StandardCharsets.UTF_8));
builder.append("=");
builder.append(URLEncoder.encode(e.getValue(), Charsets.UTF_8.name()));
builder.append(URLEncoder.encode(e.getValue(), StandardCharsets.UTF_8));
}
uriString += builder.toString();
}
Expand All @@ -1195,7 +1194,7 @@ private URI createPresignedURI(String key,
catch (DataStoreException e) {
LOG.error("No connection to Azure Blob Storage", e);
}
catch (URISyntaxException | InvalidKeyException | UnsupportedEncodingException e) {
catch (URISyntaxException | InvalidKeyException e) {
LOG.error("Can't generate a presigned URI for key {}", key, e);
}
catch (StorageException e) {
Expand Down
Expand Up @@ -35,6 +35,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.util.ArrayDeque;
import java.util.Collections;
Expand All @@ -50,7 +51,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.jackrabbit.guava.common.base.Charsets;
import org.apache.jackrabbit.guava.common.base.Function;
import org.apache.jackrabbit.guava.common.base.Joiner;
import org.apache.jackrabbit.guava.common.base.StandardSystemProperty;
Expand Down Expand Up @@ -519,10 +519,10 @@ protected long sweep(GarbageCollectorFileState fs, long markStart, boolean force
long deletedSize = 0;
int numDeletedSizeAvailable = 0;
try {
removesWriter = Files.newWriter(fs.getGarbage(), Charsets.UTF_8);
removesWriter = Files.newWriter(fs.getGarbage(), StandardCharsets.UTF_8);
ArrayDeque<String> removesQueue = new ArrayDeque<String>();
iterator =
FileUtils.lineIterator(fs.getGcCandidates(), Charsets.UTF_8.name());
FileUtils.lineIterator(fs.getGcCandidates(), StandardCharsets.UTF_8.name());

Iterator<List<String>> partitions = Iterators.partition(iterator, getBatchCount());
while (partitions.hasNext()) {
Expand Down Expand Up @@ -627,7 +627,7 @@ static void saveBatchToFile(List<String> ids, BufferedWriter writer) throws IOEx
* @param logPath whether to log path in the file or not
*/
protected void iterateNodeTree(GarbageCollectorFileState fs, final boolean logPath) throws IOException {
final BufferedWriter writer = Files.newWriter(fs.getMarkedRefs(), Charsets.UTF_8);
final BufferedWriter writer = Files.newWriter(fs.getMarkedRefs(), StandardCharsets.UTF_8);
final AtomicInteger count = new AtomicInteger();
try {
marker.collectReferences(
Expand Down
Expand Up @@ -23,7 +23,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
Expand All @@ -46,7 +46,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.jackrabbit.guava.common.base.Charsets.UTF_8;
import static org.apache.jackrabbit.guava.common.base.Predicates.alwaysTrue;
import static org.apache.jackrabbit.guava.common.collect.Iterables.transform;
import static org.apache.jackrabbit.guava.common.collect.Lists.newArrayList;
Expand Down Expand Up @@ -678,7 +677,7 @@ private synchronized void nextGeneration() throws IOException {
close();

processFile = new File(rootDir, prefix + IN_PROCESS.getFileNameSuffix());
writer = newWriter(processFile, UTF_8);
writer = newWriter(processFile, StandardCharsets.UTF_8);
LOG.info("Created new process file and writer over {} ", processFile.getAbsolutePath());
}

Expand Down
Expand Up @@ -24,17 +24,14 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.charset.StandardCharsets;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.apache.jackrabbit.guava.common.base.Charsets;
import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.guava.common.io.BaseEncoding;
import org.apache.jackrabbit.guava.common.io.Closeables;
Expand Down Expand Up @@ -111,7 +108,7 @@ public void setReferenceKeyEncoded(String encodedKey) {
* @see org.apache.jackrabbit.oak.commons.PropertiesUtil#populate(Object, java.util.Map, boolean)
*/
public void setReferenceKeyPlainText(String textKey) {
this.referenceKey = textKey.getBytes(Charsets.UTF_8);
this.referenceKey = textKey.getBytes(StandardCharsets.UTF_8);
}

public void setReferenceKey(byte[] referenceKey) {
Expand Down
Expand Up @@ -27,7 +27,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import org.apache.jackrabbit.guava.common.base.Charsets;
import org.apache.jackrabbit.guava.common.base.Joiner;
import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.guava.common.collect.Sets;
Expand Down Expand Up @@ -158,7 +157,7 @@ else if (DISPOSITION_TYPE_ATTACHMENT.equals(this.dispositionType)) {
private String formatContentDispositionHeader(@NotNull final String dispositionType,
@NotNull final String fileName,
@Nullable final String rfc8187EncodedFileName) {
Charset ISO_8859_1 = Charsets.ISO_8859_1;
Charset ISO_8859_1 = StandardCharsets.ISO_8859_1;
String iso_8859_1_fileName = new String(
ISO_8859_1.encode(fileName).array(),
ISO_8859_1
Expand Down
Expand Up @@ -21,6 +21,7 @@
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.util.List;
Expand All @@ -30,7 +31,6 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import org.apache.jackrabbit.guava.common.base.Charsets;
import org.apache.jackrabbit.guava.common.base.Optional;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.guava.common.io.Closer;
Expand Down Expand Up @@ -501,6 +501,6 @@ private void waitFinish() {
}

private static InputStream getStream(String str) {
return new ByteArrayInputStream(str.getBytes(Charsets.UTF_8));
return new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));
}
}
Expand Up @@ -22,6 +22,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand All @@ -34,7 +35,7 @@
import java.util.concurrent.atomic.AtomicInteger;

import ch.qos.logback.classic.Level;
import org.apache.jackrabbit.guava.common.base.Charsets;

import org.apache.jackrabbit.guava.common.base.Optional;
import org.apache.jackrabbit.guava.common.collect.Iterators;
import org.apache.jackrabbit.guava.common.collect.Lists;
Expand Down Expand Up @@ -718,7 +719,7 @@ private void createUpgradeLoad(File home, File pendingUploadFile) throws IOExcep
private void createGibberishLoad(File home, File pendingUploadFile) throws IOException {
BufferedWriter writer = null;
try {
writer = Files.newWriter(pendingUploadFile, Charsets.UTF_8);
writer = Files.newWriter(pendingUploadFile, StandardCharsets.UTF_8);
FileIOUtils.writeAsLine(writer, "jerhgiuheirghoeoorqehgsjlwjpfkkwpkf", false);
} finally {
Closeables.close(writer, true);
Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.net.URI;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand All @@ -44,7 +45,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.jackrabbit.guava.common.base.Charsets;
import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.guava.common.collect.Lists;
import org.apache.jackrabbit.guava.common.collect.Maps;
Expand Down Expand Up @@ -179,8 +179,8 @@ record = doSynchronousAddRecord((DataStore) dataStore, testStream);
public void testGetDownloadURIWithCustomHeadersIT() throws DataStoreException, IOException {
String umlautFilename = "Uml\u00e4utfile.png";
String umlautFilename_ISO_8859_1 = new String(
Charsets.ISO_8859_1.encode(umlautFilename).array(),
Charsets.ISO_8859_1
StandardCharsets.ISO_8859_1.encode(umlautFilename).array(),
StandardCharsets.ISO_8859_1
);
List<String> fileNames = Lists.newArrayList(
"image.png",
Expand Down
Expand Up @@ -19,12 +19,12 @@

package org.apache.jackrabbit.oak.plugins.blob.datastore.directaccess;

import java.nio.charset.StandardCharsets;
import java.util.List;

import org.apache.jackrabbit.oak.api.blob.BlobDownloadOptions;
import org.junit.Test;

import org.apache.jackrabbit.guava.common.base.Charsets;
import org.apache.jackrabbit.guava.common.base.Joiner;
import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.guava.common.collect.Lists;
Expand Down Expand Up @@ -264,8 +264,8 @@ public void testGetContentDispositionWithNoDispositionTypeOrFileName() {
public void testGetContentDispositionWithSpecialCharacterFilenames() {
String umlautFilename = "Uml\u00e4utfile.jpg";
String umlautFilename_ISO_8859_1 = new String(
Charsets.ISO_8859_1.encode(umlautFilename).array(),
Charsets.ISO_8859_1
StandardCharsets.ISO_8859_1.encode(umlautFilename).array(),
StandardCharsets.ISO_8859_1
);
List<String> filenames = Lists.newArrayList(
"image.png",
Expand Down
Expand Up @@ -21,18 +21,17 @@

import java.io.File;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import org.apache.jackrabbit.guava.common.base.Strings;
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.plugins.blob.serializer.FSBlobSerializer;
import org.apache.jackrabbit.oak.plugins.memory.AbstractBlob;
import org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob;
import org.jetbrains.annotations.NotNull;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import static org.apache.jackrabbit.guava.common.base.Charsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand All @@ -48,7 +47,7 @@ public void blobs() throws Exception{
FSBlobSerializer serializer = new FSBlobSerializer(folder.getRoot(), maxInlineSize);
String data = Strings.repeat("x", maxInlineSize * 10);

Blob b = new ArrayBasedBlob(data.getBytes(UTF_8));
Blob b = new ArrayBasedBlob(data.getBytes(StandardCharsets.UTF_8));

String id = serializer.serialize(b);
Blob b2 = serializer.deserialize(id);
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
Expand All @@ -43,7 +44,6 @@
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import org.apache.jackrabbit.guava.common.base.Charsets;
import org.apache.jackrabbit.guava.common.io.BaseEncoding;
import org.apache.commons.io.FileUtils;
import org.apache.jackrabbit.oak.commons.cache.Cache;
Expand Down Expand Up @@ -325,7 +325,7 @@ public void setReferenceKeyEncoded(String encodedKey) {
* java.util.Map, boolean)
*/
public void setReferenceKeyPlainText(String textKey) {
setReferenceKey(textKey.getBytes(Charsets.UTF_8));
setReferenceKey(textKey.getBytes(StandardCharsets.UTF_8));
}

protected void usesBlobId(String blobId) {
Expand Down
Expand Up @@ -25,12 +25,12 @@
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.jackrabbit.guava.common.base.Charsets;
import org.apache.jackrabbit.guava.common.cache.Cache;
import org.apache.jackrabbit.guava.common.cache.CacheBuilder;
import org.apache.jackrabbit.guava.common.hash.BloomFilter;
Expand All @@ -48,7 +48,7 @@ class BlobIdSet {

BlobIdSet(String repositoryDir, String filename) {
store = new File(new File(repositoryDir), filename);
bloomFilter = BloomFilter.create(Funnels.stringFunnel(Charsets.UTF_8), 9000000); // about 8MB
bloomFilter = BloomFilter.create(Funnels.stringFunnel(StandardCharsets.UTF_8), 9000000); // about 8MB
cache = CacheBuilder.newBuilder().maximumSize(1000).build();
fillBloomFilter();
}
Expand Down