You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2013/11/03 06:08:47 UTC
[2/3] git commit: use StandardCharsets static fields patch by Blair
Zajac; reviewed by jbellis for CASSANDRA-6290
use StandardCharsets static fields
patch by Blair Zajac; reviewed by jbellis for CASSANDRA-6290
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/ce206e20
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/ce206e20
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/ce206e20
Branch: refs/heads/trunk
Commit: ce206e20142024dbeff9ed68cb0ff4aeb4aaf0b8
Parents: c0ba85a
Author: Jonathan Ellis <jb...@apache.org>
Authored: Sun Nov 3 00:06:34 2013 -0500
Committer: Jonathan Ellis <jb...@apache.org>
Committed: Sun Nov 3 00:06:34 2013 -0500
----------------------------------------------------------------------
.../apache/cassandra/auth/PasswordAuthenticator.java | 7 +++----
src/java/org/apache/cassandra/cli/CliClient.java | 4 ++--
src/java/org/apache/cassandra/gms/VersionedValue.java | 4 ++--
src/java/org/apache/cassandra/locator/Ec2Snitch.java | 5 ++---
.../apache/cassandra/serializers/AsciiSerializer.java | 4 ++--
.../apache/cassandra/serializers/UTF8Serializer.java | 4 ++--
.../org/apache/cassandra/service/StorageService.java | 4 ++--
src/java/org/apache/cassandra/transport/Client.java | 6 +++---
src/java/org/apache/cassandra/transport/DataType.java | 4 ++--
src/java/org/apache/cassandra/utils/ByteBufferUtil.java | 8 ++++----
test/unit/org/apache/cassandra/SchemaLoader.java | 8 ++++----
.../org/apache/cassandra/db/marshal/RoundTripTest.java | 12 +++++-------
.../org/apache/cassandra/utils/FBUtilitiesTest.java | 4 ++--
.../org/apache/cassandra/stress/operations/Reader.java | 3 +--
.../src/org/apache/cassandra/stress/util/Operation.java | 2 +-
15 files changed, 37 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/src/java/org/apache/cassandra/auth/PasswordAuthenticator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/auth/PasswordAuthenticator.java b/src/java/org/apache/cassandra/auth/PasswordAuthenticator.java
index 4f79b4b..3d9ba98 100644
--- a/src/java/org/apache/cassandra/auth/PasswordAuthenticator.java
+++ b/src/java/org/apache/cassandra/auth/PasswordAuthenticator.java
@@ -17,7 +17,7 @@
*/
package org.apache.cassandra.auth;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -277,7 +277,6 @@ public class PasswordAuthenticator implements ISaslAwareAuthenticator
private class PlainTextSaslAuthenticator implements ISaslAwareAuthenticator.SaslAuthenticator
{
private static final byte NUL = 0;
- private final Charset UTF8_CHARSET = Charset.forName("UTF-8");
private boolean complete = false;
private Map<String, String> credentials;
@@ -339,8 +338,8 @@ public class PasswordAuthenticator implements ISaslAwareAuthenticator
throw new AuthenticationException("Password must not be null");
Map<String, String> credentials = new HashMap<String, String>();
- credentials.put(IAuthenticator.USERNAME_KEY, new String(user, UTF8_CHARSET));
- credentials.put(IAuthenticator.PASSWORD_KEY, new String(pass, UTF8_CHARSET));
+ credentials.put(IAuthenticator.USERNAME_KEY, new String(user, StandardCharsets.UTF_8));
+ credentials.put(IAuthenticator.PASSWORD_KEY, new String(pass, StandardCharsets.UTF_8));
return credentials;
}
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/src/java/org/apache/cassandra/cli/CliClient.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cli/CliClient.java b/src/java/org/apache/cassandra/cli/CliClient.java
index cf6c9d5..c3d2600 100644
--- a/src/java/org/apache/cassandra/cli/CliClient.java
+++ b/src/java/org/apache/cassandra/cli/CliClient.java
@@ -25,9 +25,9 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
+import java.nio.charset.StandardCharsets;
import java.util.*;
-import com.google.common.base.Charsets;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Iterables;
@@ -760,7 +760,7 @@ public class CliClient
}
else
{
- valueAsString = (validator == null) ? new String(columnValue, Charsets.UTF_8) : validator.getString(ByteBuffer.wrap(columnValue));
+ valueAsString = (validator == null) ? new String(columnValue, StandardCharsets.UTF_8) : validator.getString(ByteBuffer.wrap(columnValue));
}
String formattedColumnName = isSuper
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/src/java/org/apache/cassandra/gms/VersionedValue.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/gms/VersionedValue.java b/src/java/org/apache/cassandra/gms/VersionedValue.java
index 7c64a83..ec0f39f 100644
--- a/src/java/org/apache/cassandra/gms/VersionedValue.java
+++ b/src/java/org/apache/cassandra/gms/VersionedValue.java
@@ -23,9 +23,9 @@ import java.net.InetAddress;
import java.util.Collection;
import java.util.UUID;
-import com.google.common.collect.Iterables;
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
-import static com.google.common.base.Charsets.ISO_8859_1;
+import com.google.common.collect.Iterables;
import org.apache.cassandra.db.TypeSizes;
import org.apache.cassandra.dht.IPartitioner;
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/src/java/org/apache/cassandra/locator/Ec2Snitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/Ec2Snitch.java b/src/java/org/apache/cassandra/locator/Ec2Snitch.java
index 37301c1..8b404d1 100644
--- a/src/java/org/apache/cassandra/locator/Ec2Snitch.java
+++ b/src/java/org/apache/cassandra/locator/Ec2Snitch.java
@@ -23,10 +23,9 @@ import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.Map;
-import com.google.common.base.Charsets;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.cassandra.db.SystemKeyspace;
@@ -84,7 +83,7 @@ public class Ec2Snitch extends AbstractNetworkTopologySnitch
byte[] b = new byte[cl];
d = new DataInputStream((FilterInputStream) conn.getContent());
d.readFully(b);
- return new String(b, Charsets.UTF_8);
+ return new String(b, StandardCharsets.UTF_8);
}
finally
{
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/src/java/org/apache/cassandra/serializers/AsciiSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/serializers/AsciiSerializer.java b/src/java/org/apache/cassandra/serializers/AsciiSerializer.java
index 701f588..b013b23 100644
--- a/src/java/org/apache/cassandra/serializers/AsciiSerializer.java
+++ b/src/java/org/apache/cassandra/serializers/AsciiSerializer.java
@@ -18,7 +18,7 @@
package org.apache.cassandra.serializers;
import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
public class AsciiSerializer extends AbstractTextSerializer
{
@@ -26,7 +26,7 @@ public class AsciiSerializer extends AbstractTextSerializer
private AsciiSerializer()
{
- super(Charset.forName("US-ASCII"));
+ super(StandardCharsets.US_ASCII);
}
public void validate(ByteBuffer bytes) throws MarshalException
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/src/java/org/apache/cassandra/serializers/UTF8Serializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/serializers/UTF8Serializer.java b/src/java/org/apache/cassandra/serializers/UTF8Serializer.java
index 98e51aa..be5d2d6 100644
--- a/src/java/org/apache/cassandra/serializers/UTF8Serializer.java
+++ b/src/java/org/apache/cassandra/serializers/UTF8Serializer.java
@@ -18,7 +18,7 @@
package org.apache.cassandra.serializers;
import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
public class UTF8Serializer extends AbstractTextSerializer
{
@@ -26,7 +26,7 @@ public class UTF8Serializer extends AbstractTextSerializer
private UTF8Serializer()
{
- super(Charset.forName("UTF-8"));
+ super(StandardCharsets.UTF_8);
}
public void validate(ByteBuffer bytes) throws MarshalException
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/src/java/org/apache/cassandra/service/StorageService.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StorageService.java b/src/java/org/apache/cassandra/service/StorageService.java
index 77a7e5a..fec8290 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -34,6 +34,8 @@ import javax.management.Notification;
import javax.management.NotificationBroadcasterSupport;
import javax.management.ObjectName;
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.*;
import com.google.common.util.concurrent.AtomicDouble;
@@ -85,8 +87,6 @@ import org.apache.cassandra.thrift.cassandraConstants;
import org.apache.cassandra.tracing.Tracing;
import org.apache.cassandra.utils.*;
-import static com.google.common.base.Charsets.ISO_8859_1;
-
/**
* This abstraction contains the token/identifier of this node
* on the identifier space. This token gets gossiped around.
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/src/java/org/apache/cassandra/transport/Client.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/transport/Client.java b/src/java/org/apache/cassandra/transport/Client.java
index f0b700c..4a50bde 100644
--- a/src/java/org/apache/cassandra/transport/Client.java
+++ b/src/java/org/apache/cassandra/transport/Client.java
@@ -21,7 +21,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -219,8 +219,8 @@ public class Client extends SimpleClient
private byte[] encodeCredentialsForSasl(Map<String, String> credentials)
{
- byte[] username = credentials.get(IAuthenticator.USERNAME_KEY).getBytes(Charset.forName("UTF-8"));
- byte[] password = credentials.get(IAuthenticator.PASSWORD_KEY).getBytes(Charset.forName("UTF-8"));
+ byte[] username = credentials.get(IAuthenticator.USERNAME_KEY).getBytes(StandardCharsets.UTF_8);
+ byte[] password = credentials.get(IAuthenticator.PASSWORD_KEY).getBytes(StandardCharsets.UTF_8);
byte[] initialResponse = new byte[username.length + password.length + 2];
initialResponse[0] = 0;
System.arraycopy(username, 0, initialResponse, 1, username.length);
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/src/java/org/apache/cassandra/transport/DataType.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/transport/DataType.java b/src/java/org/apache/cassandra/transport/DataType.java
index 8a75e80..1656d24 100644
--- a/src/java/org/apache/cassandra/transport/DataType.java
+++ b/src/java/org/apache/cassandra/transport/DataType.java
@@ -17,13 +17,13 @@
*/
package org.apache.cassandra.transport;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
-import com.google.common.base.Charsets;
import org.jboss.netty.buffer.ChannelBuffer;
import org.apache.cassandra.exceptions.RequestValidationException;
@@ -125,7 +125,7 @@ public enum DataType implements OptionCodec.Codecable<DataType>
switch (this)
{
case CUSTOM:
- return 2 + ((String)value).getBytes(Charsets.UTF_8).length;
+ return 2 + ((String)value).getBytes(StandardCharsets.UTF_8).length;
case LIST:
case SET:
return codec.oneSerializedSize(DataType.fromType((AbstractType)value));
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/src/java/org/apache/cassandra/utils/ByteBufferUtil.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/utils/ByteBufferUtil.java b/src/java/org/apache/cassandra/utils/ByteBufferUtil.java
index 4471fb9..491f1fb 100644
--- a/src/java/org/apache/cassandra/utils/ByteBufferUtil.java
+++ b/src/java/org/apache/cassandra/utils/ByteBufferUtil.java
@@ -28,6 +28,7 @@ import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.UUID;
@@ -74,7 +75,6 @@ import org.apache.cassandra.io.util.FileUtils;
*/
public class ByteBufferUtil
{
- private static final Charset UTF_8 = Charset.forName("UTF-8");
public static final ByteBuffer EMPTY_BYTE_BUFFER = ByteBuffer.wrap(new byte[0]);
public static int compareUnsigned(ByteBuffer o1, ByteBuffer o2)
@@ -121,7 +121,7 @@ public class ByteBufferUtil
*/
public static String string(ByteBuffer buffer) throws CharacterCodingException
{
- return string(buffer, UTF_8);
+ return string(buffer, StandardCharsets.UTF_8);
}
/**
@@ -135,7 +135,7 @@ public class ByteBufferUtil
*/
public static String string(ByteBuffer buffer, int position, int length) throws CharacterCodingException
{
- return string(buffer, position, length, UTF_8);
+ return string(buffer, position, length, StandardCharsets.UTF_8);
}
/**
@@ -228,7 +228,7 @@ public class ByteBufferUtil
*/
public static ByteBuffer bytes(String s)
{
- return ByteBuffer.wrap(s.getBytes(UTF_8));
+ return ByteBuffer.wrap(s.getBytes(StandardCharsets.UTF_8));
}
/**
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/test/unit/org/apache/cassandra/SchemaLoader.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/SchemaLoader.java b/test/unit/org/apache/cassandra/SchemaLoader.java
index f3cc38f..58cc52f 100644
--- a/test/unit/org/apache/cassandra/SchemaLoader.java
+++ b/test/unit/org/apache/cassandra/SchemaLoader.java
@@ -20,9 +20,9 @@ package org.apache.cassandra;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.*;
-import com.google.common.base.Charsets;
import org.apache.cassandra.db.index.PerRowSecondaryIndexTest;
import org.apache.cassandra.db.index.SecondaryIndex;
import org.junit.AfterClass;
@@ -318,7 +318,7 @@ public class SchemaLoader
.keyValidator(AsciiType.instance)
.columnMetadata(new HashMap<ByteBuffer, ColumnDefinition>()
{{
- ByteBuffer cName = ByteBuffer.wrap("indexed".getBytes(Charsets.UTF_8));
+ ByteBuffer cName = ByteBuffer.wrap("indexed".getBytes(StandardCharsets.UTF_8));
put(cName, new ColumnDefinition(cName,
AsciiType.instance,
IndexType.CUSTOM,
@@ -357,7 +357,7 @@ public class SchemaLoader
.keyValidator(AsciiType.instance)
.columnMetadata(new HashMap<ByteBuffer, ColumnDefinition>()
{{
- ByteBuffer cName = ByteBuffer.wrap("birthdate".getBytes(Charsets.UTF_8));
+ ByteBuffer cName = ByteBuffer.wrap("birthdate".getBytes(StandardCharsets.UTF_8));
IndexType keys = withIdxType ? IndexType.KEYS : null;
put(cName, ColumnDefinition.regularDef(cName, LongType.instance, null).setIndex(withIdxType ? ByteBufferUtil.bytesToHex(cName) : null, keys, null));
}});
@@ -372,7 +372,7 @@ public class SchemaLoader
null)
.columnMetadata(new HashMap<ByteBuffer, ColumnDefinition>()
{{
- ByteBuffer cName = ByteBuffer.wrap("col1".getBytes(Charsets.UTF_8));
+ ByteBuffer cName = ByteBuffer.wrap("col1".getBytes(StandardCharsets.UTF_8));
IndexType idxType = withIdxType ? IndexType.COMPOSITES : null;
put(cName, ColumnDefinition.regularDef(cName, UTF8Type.instance, 1)
.setIndex(withIdxType ? "col1_idx" : null, idxType, Collections.<String, String>emptyMap()));
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/test/unit/org/apache/cassandra/db/marshal/RoundTripTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/marshal/RoundTripTest.java b/test/unit/org/apache/cassandra/db/marshal/RoundTripTest.java
index b3e0760..9f46850 100644
--- a/test/unit/org/apache/cassandra/db/marshal/RoundTripTest.java
+++ b/test/unit/org/apache/cassandra/db/marshal/RoundTripTest.java
@@ -20,9 +20,6 @@ package org.apache.cassandra.db.marshal;
*
*/
-
-import com.google.common.base.Charsets;
-
import org.apache.cassandra.serializers.*;
import org.apache.cassandra.utils.Hex;
import org.apache.cassandra.utils.UUIDGen;
@@ -30,6 +27,7 @@ import org.junit.Test;
import java.math.BigInteger;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.UUID;
public class RoundTripTest
@@ -71,7 +69,7 @@ public class RoundTripTest
@Test
public void testAscii() throws Exception
{
- byte[] abc = "abc".getBytes(Charsets.US_ASCII);
+ byte[] abc = "abc".getBytes(StandardCharsets.US_ASCII);
assert AsciiType.instance.getString(AsciiType.instance.fromString("abc")).equals("abc");
assert AsciiType.instance.fromString(AsciiType.instance.getString(ByteBuffer.wrap(abc)))
.equals(ByteBuffer.wrap(abc));
@@ -116,9 +114,9 @@ public class RoundTripTest
{
String v = "\u2297\u5432\u2376\u263d\uf543";
assert UTF8Type.instance.getString(UTF8Type.instance.fromString(v)).equals(v);
- assert UTF8Type.instance.fromString(UTF8Type.instance.getString(ByteBuffer.wrap(v.getBytes(Charsets.UTF_8))))
- .equals(ByteBuffer.wrap(v.getBytes(Charsets.UTF_8)));
- assert UTF8Type.instance.compose(ByteBuffer.wrap(v.getBytes(Charsets.UTF_8))).equals(v);
+ assert UTF8Type.instance.fromString(UTF8Type.instance.getString(ByteBuffer.wrap(v.getBytes(StandardCharsets.UTF_8))))
+ .equals(ByteBuffer.wrap(v.getBytes(StandardCharsets.UTF_8)));
+ assert UTF8Type.instance.compose(ByteBuffer.wrap(v.getBytes(StandardCharsets.UTF_8))).equals(v);
assert UTF8Serializer.instance.toString(v).equals(v);
}
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java b/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java
index e91cbd1..adf3763 100644
--- a/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java
+++ b/test/unit/org/apache/cassandra/utils/FBUtilitiesTest.java
@@ -23,7 +23,7 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
-import com.google.common.base.Charsets;
+import java.nio.charset.StandardCharsets;
import com.google.common.primitives.Ints;
import org.junit.Test;
@@ -74,6 +74,6 @@ public class FBUtilitiesTest
public void testDecode() throws IOException
{
ByteBuffer bytes = ByteBuffer.wrap(new byte[]{(byte)0xff, (byte)0xfe});
- ByteBufferUtil.string(bytes, Charsets.UTF_8);
+ ByteBufferUtil.string(bytes, StandardCharsets.UTF_8);
}
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/tools/stress/src/org/apache/cassandra/stress/operations/Reader.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/operations/Reader.java b/tools/stress/src/org/apache/cassandra/stress/operations/Reader.java
index f75502a..72d09b4 100644
--- a/tools/stress/src/org/apache/cassandra/stress/operations/Reader.java
+++ b/tools/stress/src/org/apache/cassandra/stress/operations/Reader.java
@@ -27,8 +27,7 @@ import org.apache.cassandra.thrift.*;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
-
-import static com.google.common.base.Charsets.UTF_8;
+import static java.nio.charset.StandardCharsets.UTF_8;
public class Reader extends Operation
{
http://git-wip-us.apache.org/repos/asf/cassandra/blob/ce206e20/tools/stress/src/org/apache/cassandra/stress/util/Operation.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/util/Operation.java b/tools/stress/src/org/apache/cassandra/stress/util/Operation.java
index f7924da..e2e12f8 100644
--- a/tools/stress/src/org/apache/cassandra/stress/util/Operation.java
+++ b/tools/stress/src/org/apache/cassandra/stress/util/Operation.java
@@ -17,7 +17,7 @@
*/
package org.apache.cassandra.stress.util;
-import static com.google.common.base.Charsets.UTF_8;
+import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.IOException;
import java.math.BigInteger;