Skip to content

Commit

Permalink
Remove deprecated LettuceCharsets class #1156
Browse files Browse the repository at this point in the history
Move off deprecated API in favor of StandardCharsets.
  • Loading branch information
mp911de committed Nov 8, 2019
1 parent 9c583b9 commit 9115222
Show file tree
Hide file tree
Showing 41 changed files with 142 additions and 217 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/lettuce/core/BitFieldArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
package io.lettuce.core;

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

import io.lettuce.core.internal.LettuceAssert;
import io.lettuce.core.protocol.CommandArgs;
import io.lettuce.core.protocol.CommandType;
import io.lettuce.core.protocol.LettuceCharsets;
import io.lettuce.core.protocol.ProtocolKeyword;

/**
Expand Down Expand Up @@ -566,7 +566,7 @@ public enum OverflowType implements ProtocolKeyword {
public final byte[] bytes;

OverflowType() {
bytes = name().getBytes(LettuceCharsets.ASCII);
bytes = name().getBytes(StandardCharsets.US_ASCII);
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/lettuce/core/LettuceStrings.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package io.lettuce.core;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Collection;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/lettuce/core/RedisURI.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.net.SocketAddress;
import java.net.URI;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.*;
import java.util.function.LongFunction;
Expand All @@ -32,7 +33,6 @@
import io.lettuce.core.internal.HostAndPort;
import io.lettuce.core.internal.LettuceAssert;
import io.lettuce.core.internal.LettuceSets;
import io.lettuce.core.protocol.LettuceCharsets;

/**
* Redis URI. Contains connection details for the Redis/Sentinel connections. You can provide the database, client name,
Expand Down Expand Up @@ -706,7 +706,7 @@ private String getScheme() {
*/
private static String urlEncode(String str) {
try {
return URLEncoder.encode(str, LettuceCharsets.UTF8.name()).replaceAll("%2F", "/");
return URLEncoder.encode(str, StandardCharsets.UTF_8.name()).replaceAll("%2F", "/");
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/lettuce/core/UnblockType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/
package io.lettuce.core;

import io.lettuce.core.protocol.LettuceCharsets;
import java.nio.charset.StandardCharsets;

import io.lettuce.core.protocol.ProtocolKeyword;

/**
Expand All @@ -31,7 +32,7 @@ public enum UnblockType implements ProtocolKeyword {
private final byte[] bytes;

UnblockType() {
bytes = name().getBytes(LettuceCharsets.ASCII);
bytes = name().getBytes(StandardCharsets.US_ASCII);
}

@Override
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/io/lettuce/core/codec/StringCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
import java.nio.charset.*;

import io.lettuce.core.internal.LettuceAssert;
import io.lettuce.core.protocol.LettuceCharsets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
Expand All @@ -38,8 +34,8 @@
*/
public class StringCodec implements RedisCodec<String, String>, ToByteBufEncoder<String, String> {

public static final StringCodec UTF8 = new StringCodec(LettuceCharsets.UTF8);
public static final StringCodec ASCII = new StringCodec(LettuceCharsets.ASCII);
public static final StringCodec UTF8 = new StringCodec(StandardCharsets.UTF_8);
public static final StringCodec ASCII = new StringCodec(StandardCharsets.US_ASCII);

private static final byte[] EMPTY = new byte[0];

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/lettuce/core/codec/Utf8StringCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
*/
package io.lettuce.core.codec;

import io.lettuce.core.protocol.LettuceCharsets;
import java.nio.charset.StandardCharsets;

/**
* A {@link RedisCodec} that handles UTF-8 encoded keys and values.
*
* @author Will Glozer
* @author Mark Paluch
* @see StringCodec
* @see LettuceCharsets#UTF8
* @see StandardCharsets#UTF_8
* @deprecated since 5.2, use {@link StringCodec#UTF8} instead.
*/
@Deprecated
Expand All @@ -33,6 +33,6 @@ public class Utf8StringCodec extends StringCodec implements RedisCodec<String, S
* Initialize a new instance that encodes and decodes strings using the UTF-8 charset;
*/
public Utf8StringCodec() {
super(LettuceCharsets.UTF8);
super(StandardCharsets.UTF_8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.nio.charset.StandardCharsets;
import java.util.*;

import io.lettuce.core.AbstractRedisReactiveCommands;
Expand All @@ -40,7 +41,6 @@
import io.lettuce.core.internal.LettuceLists;
import io.lettuce.core.models.command.CommandDetail;
import io.lettuce.core.models.command.CommandDetailParser;
import io.lettuce.core.protocol.LettuceCharsets;
import io.lettuce.core.protocol.RedisCommand;
import io.lettuce.core.support.ConnectionWrapping;
import io.netty.util.internal.logging.InternalLogger;
Expand Down Expand Up @@ -108,7 +108,7 @@ public class RedisCommandFactory {
* @param connection must not be {@literal null}.
*/
public RedisCommandFactory(StatefulConnection<?, ?> connection) {
this(connection, LettuceLists.newList(new ByteArrayCodec(), new StringCodec(LettuceCharsets.UTF8)));
this(connection, LettuceLists.newList(new ByteArrayCodec(), new StringCodec(StandardCharsets.UTF_8)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.lettuce.core.masterslave;

import java.io.Closeable;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.*;
Expand All @@ -31,7 +32,6 @@
import io.lettuce.core.internal.AsyncCloseable;
import io.lettuce.core.internal.Futures;
import io.lettuce.core.internal.LettuceLists;
import io.lettuce.core.protocol.LettuceCharsets;
import io.lettuce.core.pubsub.RedisPubSubAdapter;
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
import io.netty.util.concurrent.EventExecutorGroup;
Expand All @@ -48,7 +48,7 @@
class SentinelTopologyRefresh implements AsyncCloseable, Closeable {

private static final InternalLogger LOG = InternalLoggerFactory.getInstance(SentinelTopologyRefresh.class);
private static final StringCodec CODEC = new StringCodec(LettuceCharsets.ASCII);
private static final StringCodec CODEC = new StringCodec(StandardCharsets.US_ASCII);
private static final Set<String> PROCESSING_CHANNELS = new HashSet<>(
Arrays.asList("failover-end", "failover-end-for-timeout"));

Expand Down Expand Up @@ -155,8 +155,8 @@ private CompletionStage<Void> initializeSentinels() {

SentinelTopologyRefreshConnections collector = collectConnections(connectionFutures);

CompletionStage<SentinelTopologyRefreshConnections> completionStage = collector.getOrTimeout(timeout, redisClient
.getResources().eventExecutorGroup());
CompletionStage<SentinelTopologyRefreshConnections> completionStage = collector.getOrTimeout(timeout,
redisClient.getResources().eventExecutorGroup());

return completionStage.whenComplete((aVoid, throwable) -> {

Expand Down Expand Up @@ -359,8 +359,8 @@ interface MessagePredicate extends BiPredicate<String, String> {
private static class TopologyRefreshMessagePredicate implements MessagePredicate {

private final String masterId;
private Set<String> TOPOLOGY_CHANGE_CHANNELS = new HashSet<>(Arrays.asList("+slave", "+sdown", "-sdown",
"fix-slave-config", "+convert-to-slave", "+role-change"));
private Set<String> TOPOLOGY_CHANGE_CHANNELS = new HashSet<>(
Arrays.asList("+slave", "+sdown", "-sdown", "fix-slave-config", "+convert-to-slave", "+role-change"));

TopologyRefreshMessagePredicate(String masterId) {
this.masterId = masterId;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/io/lettuce/core/output/StatusOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/
package io.lettuce.core.output;

import static io.lettuce.core.protocol.LettuceCharsets.buffer;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

import io.lettuce.core.codec.RedisCodec;

Expand All @@ -30,7 +29,7 @@
*/
public class StatusOutput<K, V> extends CommandOutput<K, V, String> {

private static final ByteBuffer OK = buffer("OK");
private static final ByteBuffer OK = StandardCharsets.US_ASCII.encode("OK");

public StatusOutput(RedisCodec<K, V> codec) {
super(codec, null);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/lettuce/core/protocol/CommandArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.lettuce.core.protocol;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
Expand Down Expand Up @@ -47,7 +48,7 @@
*/
public class CommandArgs<K, V> {

static final byte[] CRLF = "\r\n".getBytes(LettuceCharsets.ASCII);
static final byte[] CRLF = "\r\n".getBytes(StandardCharsets.US_ASCII);

protected final RedisCodec<K, V> codec;

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/lettuce/core/protocol/CommandKeyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package io.lettuce.core.protocol;

import java.nio.charset.StandardCharsets;

/**
* Keyword modifiers for redis commands.
*
Expand Down Expand Up @@ -45,7 +47,7 @@ public enum CommandKeyword implements ProtocolKeyword {
public final byte[] bytes;

private CommandKeyword() {
bytes = name().getBytes(LettuceCharsets.ASCII);
bytes = name().getBytes(StandardCharsets.US_ASCII);
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/io/lettuce/core/protocol/CommandType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package io.lettuce.core.protocol;

import java.nio.charset.StandardCharsets;

/**
* Redis commands.
*
Expand Down Expand Up @@ -102,7 +104,7 @@ public enum CommandType implements ProtocolKeyword {
public final byte[] bytes;

CommandType() {
bytes = name().getBytes(LettuceCharsets.ASCII);
bytes = name().getBytes(StandardCharsets.US_ASCII);
}

@Override
Expand Down
56 changes: 0 additions & 56 deletions src/main/java/io/lettuce/core/protocol/LettuceCharsets.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/io/lettuce/core/protocol/RedisStateMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/
package io.lettuce.core.protocol;

import static io.lettuce.core.protocol.LettuceCharsets.buffer;
import static io.lettuce.core.protocol.RedisStateMachine.State.Type.*;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;

Expand All @@ -41,7 +41,7 @@
public class RedisStateMachine {

private static final InternalLogger logger = InternalLoggerFactory.getInstance(RedisStateMachine.class);
private static final ByteBuffer QUEUED = buffer("QUEUED");
private static final ByteBuffer QUEUED = StandardCharsets.US_ASCII.encode("QUEUED");

static class State {
enum Type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import io.lettuce.core.RedisChannelWriter;
import io.lettuce.core.codec.StringCodec;
import io.lettuce.core.codec.Utf8StringCodec;
import io.lettuce.core.output.StatusOutput;
import io.lettuce.core.protocol.AsyncCommand;
import io.lettuce.core.protocol.Command;
Expand All @@ -46,8 +45,8 @@ class ClusterCommandUnitTests {
private RedisChannelWriter writerMock;

private ClusterCommand<String, String, String> sut;
private Command<String, String, String> command = new Command<>(CommandType.TYPE,
new StatusOutput<>(StringCodec.UTF8), null);
private Command<String, String, String> command = new Command<>(CommandType.TYPE, new StatusOutput<>(StringCodec.UTF8),
null);

@BeforeEach
void before() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import io.lettuce.core.RedisChannelWriter;
import io.lettuce.core.RedisException;
import io.lettuce.core.codec.StringCodec;
import io.lettuce.core.codec.Utf8StringCodec;
import io.lettuce.core.output.StatusOutput;
import io.lettuce.core.protocol.AsyncCommand;
import io.lettuce.core.protocol.Command;
Expand All @@ -49,8 +48,8 @@
@ExtendWith(MockitoExtension.class)
class ClusterNodeEndpointUnitTests {

private AsyncCommand<String, String, String> command = new AsyncCommand<>(new Command<>(CommandType.APPEND,
new StatusOutput<>(StringCodec.UTF8), null));
private AsyncCommand<String, String, String> command = new AsyncCommand<>(
new Command<>(CommandType.APPEND, new StatusOutput<>(StringCodec.UTF8), null));

private Queue<RedisCommand<String, String, ?>> disconnectedBuffer;

Expand Down
Loading

0 comments on commit 9115222

Please sign in to comment.