mirror of https://github.com/apache/cassandra
use StandardCharsets static fields
patch by Blair Zajac; reviewed by jbellis for CASSANDRA-6290
This commit is contained in:
parent
c0ba85a400
commit
ce206e2014
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue