Use StandardCharsets
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java
index ac90834..068ad3c 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/lateral/socket/tcp/LateralTCPService.java
@@ -22,6 +22,7 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -414,7 +415,7 @@
boolean notDone = true;
String message = null;
// wait to dispose
- BufferedReader br = new BufferedReader( new InputStreamReader( System.in, "UTF-8" ) );
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8));
while ( notDone )
{
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java
index 3bf3c99..7b80ef9 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/http/client/RemoteHttpCacheDispatcher.java
@@ -21,6 +21,7 @@
import java.io.IOException;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import org.apache.commons.jcs.auxiliary.remote.behavior.IRemoteCacheDispatcher;
import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheRequest;
@@ -41,7 +42,7 @@
implements IRemoteCacheDispatcher
{
/** Parameter encoding */
- private static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8");
+ private static final Charset DEFAULT_ENCODING = StandardCharsets.UTF_8;
/** Named of the parameter */
private static final String PARAMETER_REQUEST_TYPE = "RequestType";
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheStartupServlet.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheStartupServlet.java
index 59241f6..538f64f 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheStartupServlet.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/remote/server/RemoteCacheStartupServlet.java
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.net.UnknownHostException;
+import java.nio.charset.StandardCharsets;
import java.util.Properties;
import javax.servlet.ServletConfig;
@@ -180,7 +181,7 @@
String characterEncoding = response.getCharacterEncoding();
if (characterEncoding == null)
{
- characterEncoding = "UTF-8";
+ characterEncoding = StandardCharsets.UTF_8.name();
response.setCharacterEncoding(characterEncoding);
}
OutputStream os = response.getOutputStream();
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCacheUnitTestAbstract.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCacheUnitTestAbstract.java
index 45f816c..fb6e7db 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCacheUnitTestAbstract.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCacheUnitTestAbstract.java
@@ -22,6 +22,7 @@
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
+import java.nio.charset.StandardCharsets;
import java.util.Map;
import junit.framework.TestCase;
@@ -249,8 +250,7 @@
}
string = sb.toString();
// System.out.println( "The string contains " + string.length() + " characters" );
- String UTF8 = "UTF-8";
- byte[] bytes = string.getBytes(UTF8);
+ byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
String cacheName = "testUTF8ByteArray";
@@ -275,7 +275,7 @@
assertNotNull(after);
assertEquals("wrong bytes after retrieval", bytes.length, after.length);
// assertEquals( "wrong bytes after retrieval", bytes, after );
- // assertEquals( "wrong bytes after retrieval", string, new String( after, UTF8 ) );
+ // assertEquals( "wrong bytes after retrieval", string, new String( after, StandardCharsets.UTF_8 ) );
}
@@ -297,9 +297,8 @@
}
string = sb.toString();
// System.out.println( "The string contains " + string.length() + " characters" );
- String UTF8 = "UTF-8";
before.string = string;
- before.bytes = string.getBytes(UTF8);
+ before.bytes = string.getBytes(StandardCharsets.UTF_8);
String cacheName = "testUTF8StringAndBytes";
@@ -322,7 +321,7 @@
assertNotNull(after);
assertEquals("wrong string after retrieval", string, after.string);
- assertEquals("wrong bytes after retrieval", string, new String(after.bytes, UTF8));
+ assertEquals("wrong bytes after retrieval", string, new String(after.bytes, StandardCharsets.UTF_8));
}
@@ -372,9 +371,8 @@
sb.append(sb.toString()); // big string
}
string = sb.toString();
- String UTF8 = "UTF-8";
before.string = string;
- before.bytes = string.getBytes(UTF8);
+ before.bytes = string.getBytes(StandardCharsets.UTF_8);
// initialize cache
String cacheName = "testLoadFromDisk";
@@ -403,7 +401,7 @@
assertNotNull(after);
assertEquals("wrong string after retrieval", string, after.string);
- assertEquals("wrong bytes after retrieval", string, new String(after.bytes, UTF8));
+ assertEquals("wrong bytes after retrieval", string, new String(after.bytes, StandardCharsets.UTF_8));
}
diskCache.dispose();
diff --git a/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTestAbstract.java b/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTestAbstract.java
index da4f5b3..3bc4eb8 100644
--- a/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTestAbstract.java
+++ b/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTestAbstract.java
@@ -20,6 +20,7 @@
*/
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -770,8 +771,7 @@
}
string = sb.toString();
// System.out.println( "The string contains " + string.length() + " characters" );
- String UTF8 = "UTF-8";
- byte[] bytes = string.getBytes(UTF8);
+ byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
String cacheName = "testUTF8ByteArray";
@@ -793,7 +793,7 @@
byte[] after = afterElement.getVal();
assertNotNull(after);
- assertEquals("wrong bytes after retrieval", string, new String(after, UTF8));
+ assertEquals("wrong bytes after retrieval", string, new String(after, StandardCharsets.UTF_8));
}
/**