Use StandardCharset instead of Charset.forName() patch by Robert Stupp; reviewed by Stefania for CASSANDRA-13104
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/8cb8c63e Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/8cb8c63e Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/8cb8c63e Branch: refs/heads/trunk Commit: 8cb8c63e029b453c706922443d187d029d687af0 Parents: 84c3fee Author: Robert Stupp <sn...@snazy.de> Authored: Fri Jan 6 09:39:12 2017 +0100 Committer: Robert Stupp <sn...@snazy.de> Committed: Fri Jan 6 09:39:12 2017 +0100 ---------------------------------------------------------------------- src/java/org/apache/cassandra/db/marshal/AsciiType.java | 6 +++--- src/java/org/apache/cassandra/db/marshal/UTF8Type.java | 4 ++-- .../metrics/DecayingEstimatedHistogramReservoir.java | 9 +++------ src/java/org/apache/cassandra/transport/CBUtil.java | 4 ++-- .../org/apache/cassandra/io/util/FileUtilsTest.java | 6 +++--- .../cassandra/io/util/RandomAccessReaderTest.java | 12 ++++++------ 6 files changed, 19 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/8cb8c63e/src/java/org/apache/cassandra/db/marshal/AsciiType.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/marshal/AsciiType.java b/src/java/org/apache/cassandra/db/marshal/AsciiType.java index 3cd45de..05077ee 100644 --- a/src/java/org/apache/cassandra/db/marshal/AsciiType.java +++ b/src/java/org/apache/cassandra/db/marshal/AsciiType.java @@ -19,9 +19,9 @@ package org.apache.cassandra.db.marshal; import java.nio.ByteBuffer; import java.nio.CharBuffer; -import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import java.nio.charset.CharacterCodingException; +import java.nio.charset.StandardCharsets; import io.netty.util.concurrent.FastThreadLocal; import org.apache.cassandra.cql3.Constants; @@ -46,7 +46,7 @@ public class AsciiType extends AbstractType<String> @Override protected CharsetEncoder initialValue() { - return Charset.forName("US-ASCII").newEncoder(); + return StandardCharsets.US_ASCII.newEncoder(); } }; @@ -85,7 +85,7 @@ public class AsciiType extends AbstractType<String> { try { - return '"' + Json.quoteAsJsonString(ByteBufferUtil.string(buffer, Charset.forName("US-ASCII"))) + '"'; + return '"' + Json.quoteAsJsonString(ByteBufferUtil.string(buffer, StandardCharsets.US_ASCII)) + '"'; } catch (CharacterCodingException exc) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/8cb8c63e/src/java/org/apache/cassandra/db/marshal/UTF8Type.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/marshal/UTF8Type.java b/src/java/org/apache/cassandra/db/marshal/UTF8Type.java index 1da6629..46e0d90 100644 --- a/src/java/org/apache/cassandra/db/marshal/UTF8Type.java +++ b/src/java/org/apache/cassandra/db/marshal/UTF8Type.java @@ -19,7 +19,7 @@ package org.apache.cassandra.db.marshal; import java.nio.ByteBuffer; import java.nio.charset.CharacterCodingException; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import org.apache.cassandra.cql3.Constants; import org.apache.cassandra.cql3.Json; @@ -63,7 +63,7 @@ public class UTF8Type extends AbstractType<String> { try { - return '"' + Json.quoteAsJsonString(ByteBufferUtil.string(buffer, Charset.forName("UTF-8"))) + '"'; + return '"' + Json.quoteAsJsonString(ByteBufferUtil.string(buffer, StandardCharsets.UTF_8)) + '"'; } catch (CharacterCodingException exc) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/8cb8c63e/src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java b/src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java index e0cddee..d5a85cf 100644 --- a/src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java +++ b/src/java/org/apache/cassandra/metrics/DecayingEstimatedHistogramReservoir.java @@ -21,7 +21,7 @@ package org.apache.cassandra.metrics; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLongArray; @@ -48,7 +48,7 @@ import org.apache.cassandra.utils.EstimatedHistogram; * end of the 30:th minute all collected values will roughly add up to 1.000.000 * 60 * pow(2, 30) which can be * represented with 56 bits giving us some head room in a signed 64 bit long. * - * Internally two reservoirs are maintained, one with decay and one without decay. All public getters in a {@Snapshot} + * Internally two reservoirs are maintained, one with decay and one without decay. All public getters in a {@link Snapshot} * will expose the decay functionality with the exception of the {@link Snapshot#getValues()} which will return values * from the reservoir without decay. This makes it possible for the caller to maintain precise deltas in an interval of * its choise. @@ -331,9 +331,6 @@ public class DecayingEstimatedHistogramReservoir implements Reservoir this.lock.writeLock().unlock(); } - - private static final Charset UTF_8 = Charset.forName("UTF-8"); - /** * Represents a snapshot of the decaying histogram. * @@ -539,7 +536,7 @@ public class DecayingEstimatedHistogramReservoir implements Reservoir public void dump(OutputStream output) { - try (PrintWriter out = new PrintWriter(new OutputStreamWriter(output, UTF_8))) + try (PrintWriter out = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8))) { int length = decayingBuckets.length; http://git-wip-us.apache.org/repos/asf/cassandra/blob/8cb8c63e/src/java/org/apache/cassandra/transport/CBUtil.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/transport/CBUtil.java b/src/java/org/apache/cassandra/transport/CBUtil.java index 66e5e73..824ad26 100644 --- a/src/java/org/apache/cassandra/transport/CBUtil.java +++ b/src/java/org/apache/cassandra/transport/CBUtil.java @@ -23,9 +23,9 @@ import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; -import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CoderResult; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -64,7 +64,7 @@ public abstract class CBUtil @Override protected CharsetDecoder initialValue() { - return Charset.forName("UTF-8").newDecoder(); + return StandardCharsets.UTF_8.newDecoder(); } }; http://git-wip-us.apache.org/repos/asf/cassandra/blob/8cb8c63e/test/unit/org/apache/cassandra/io/util/FileUtilsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/io/util/FileUtilsTest.java b/test/unit/org/apache/cassandra/io/util/FileUtilsTest.java index 0e7d8c8..8821672 100644 --- a/test/unit/org/apache/cassandra/io/util/FileUtilsTest.java +++ b/test/unit/org/apache/cassandra/io/util/FileUtilsTest.java @@ -21,7 +21,7 @@ package org.apache.cassandra.io.util; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -54,11 +54,11 @@ public class FileUtilsTest assertTrue(file.exists()); byte[] b = Files.readAllBytes(file.toPath()); - assertEquals(expected, new String(b, Charset.forName("UTF-8"))); + assertEquals(expected, new String(b, StandardCharsets.UTF_8)); FileUtils.truncate(file.getAbsolutePath(), 10); b = Files.readAllBytes(file.toPath()); - assertEquals("The quick ", new String(b, Charset.forName("UTF-8"))); + assertEquals("The quick ", new String(b, StandardCharsets.UTF_8)); FileUtils.truncate(file.getAbsolutePath(), 0); b = Files.readAllBytes(file.toPath()); http://git-wip-us.apache.org/repos/asf/cassandra/blob/8cb8c63e/test/unit/org/apache/cassandra/io/util/RandomAccessReaderTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/io/util/RandomAccessReaderTest.java b/test/unit/org/apache/cassandra/io/util/RandomAccessReaderTest.java index 8941d2a..3a34855 100644 --- a/test/unit/org/apache/cassandra/io/util/RandomAccessReaderTest.java +++ b/test/unit/org/apache/cassandra/io/util/RandomAccessReaderTest.java @@ -29,7 +29,7 @@ import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Random; import java.util.concurrent.ExecutorService; @@ -338,7 +338,7 @@ public class RandomAccessReaderTest assertEquals(expected.length(), reader.length()); ByteBuffer b = ByteBufferUtil.read(reader, expected.length()); - assertEquals(expected, new String(b.array(), Charset.forName("UTF-8"))); + assertEquals(expected, new String(b.array(), StandardCharsets.UTF_8)); assertTrue(reader.isEOF()); assertEquals(0, reader.bytesRemaining()); @@ -368,7 +368,7 @@ public class RandomAccessReaderTest assertEquals(expected.length() * numIterations, reader.length()); ByteBuffer b = ByteBufferUtil.read(reader, expected.length()); - assertEquals(expected, new String(b.array(), Charset.forName("UTF-8"))); + assertEquals(expected, new String(b.array(), StandardCharsets.UTF_8)); assertFalse(reader.isEOF()); assertEquals((numIterations - 1) * expected.length(), reader.bytesRemaining()); @@ -380,7 +380,7 @@ public class RandomAccessReaderTest for (int i = 0; i < (numIterations - 1); i++) { b = ByteBufferUtil.read(reader, expected.length()); - assertEquals(expected, new String(b.array(), Charset.forName("UTF-8"))); + assertEquals(expected, new String(b.array(), StandardCharsets.UTF_8)); } assertTrue(reader.isEOF()); assertEquals(expected.length() * (numIterations - 1), reader.bytesPastMark()); @@ -393,7 +393,7 @@ public class RandomAccessReaderTest for (int i = 0; i < (numIterations - 1); i++) { b = ByteBufferUtil.read(reader, expected.length()); - assertEquals(expected, new String(b.array(), Charset.forName("UTF-8"))); + assertEquals(expected, new String(b.array(), StandardCharsets.UTF_8)); } reader.reset(); @@ -403,7 +403,7 @@ public class RandomAccessReaderTest for (int i = 0; i < (numIterations - 1); i++) { b = ByteBufferUtil.read(reader, expected.length()); - assertEquals(expected, new String(b.array(), Charset.forName("UTF-8"))); + assertEquals(expected, new String(b.array(), StandardCharsets.UTF_8)); } assertTrue(reader.isEOF());