You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2017/06/08 08:15:37 UTC

[03/48] [lang] Deprecate CharEncoding and direct users to Java 7 classes

Deprecate CharEncoding and direct users to Java 7 classes

Java 7 introduced java.nio.charset.StandardCharsets, which negates the
need for our CharEncoding method. Additionally, the constants in the
class now point to the constants defined in Java 7.

Fixes: LANG-1334

Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/7c19a1ff
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/7c19a1ff
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/7c19a1ff

Branch: refs/heads/release
Commit: 7c19a1ff4c217f03c0be62baf1169d689f566825
Parents: 53def50
Author: duncan <du...@wortharead.com>
Authored: Mon May 22 13:16:29 2017 +0100
Committer: duncan <du...@wortharead.com>
Committed: Mon May 22 13:16:29 2017 +0100

----------------------------------------------------------------------
 src/changes/changes.xml                          |  1 +
 .../org/apache/commons/lang3/CharEncoding.java   | 19 +++++++++++++------
 .../apache/commons/lang3/CharEncodingTest.java   |  1 +
 3 files changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/7c19a1ff/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 9f52a9b..69b95d7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
   <body>
 
   <release version="3.6" date="2017-MM-DD" description="TBD">
+    <action issue="LANG-1334" type="update" dev="djones">Deprecate CharEncoding in favour of java.nio.charset.StandardCharsets</action>
     <action issue="LANG-1319" type="fix" dev="djones">MultilineRecursiveToStringStyle StackOverflowError when object is an array</action>
     <action issue="LANG-1325" type="add" dev="kinow" due-to="Arshad Basha">Increase test coverage of ToStringBuilder class to 100%</action>
     <action issue="LANG-1307" type="add" dev="pschumacher" due-to="Arshad Basha">Add a method in StringUtils to extract only digits out of input string</action>

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/7c19a1ff/src/main/java/org/apache/commons/lang3/CharEncoding.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/CharEncoding.java b/src/main/java/org/apache/commons/lang3/CharEncoding.java
index 7fe9296..65dca33 100644
--- a/src/main/java/org/apache/commons/lang3/CharEncoding.java
+++ b/src/main/java/org/apache/commons/lang3/CharEncoding.java
@@ -19,6 +19,7 @@ package org.apache.commons.lang3;
 
 import java.nio.charset.Charset;
 import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.StandardCharsets;
 
 /**
  * <p>Character encoding names required of every implementation of the Java platform.</p>
@@ -32,7 +33,11 @@ import java.nio.charset.IllegalCharsetNameException;
  *
  * @see <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/intl/encoding.doc.html">JRE character encoding names</a>
  * @since 2.1
+ * @deprecated Java 7 introduced {@link StandardCharsets}, which defines these constants as
+ * {@link Charset} objects. Use {@link Charset#name()} to get the string values provided in this class.
+ * This class will be removed in a future release.
  */
+@Deprecated
 public class CharEncoding {
 
     /**
@@ -40,7 +45,7 @@ public class CharEncoding {
      *
      * <p>Every implementation of the Java platform is required to support this character encoding.</p>
      */
-    public static final String ISO_8859_1 = "ISO-8859-1";
+    public static final String ISO_8859_1 = StandardCharsets.ISO_8859_1.name();
 
     /**
      * <p>Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block
@@ -48,7 +53,7 @@ public class CharEncoding {
      *
      * <p>Every implementation of the Java platform is required to support this character encoding.</p>
      */
-    public static final String US_ASCII = "US-ASCII";
+    public static final String US_ASCII = StandardCharsets.US_ASCII.name();
 
     /**
      * <p>Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial
@@ -56,28 +61,28 @@ public class CharEncoding {
      *
      * <p>Every implementation of the Java platform is required to support this character encoding.</p>
      */
-    public static final String UTF_16 = "UTF-16";
+    public static final String UTF_16 = StandardCharsets.UTF_16.name();
 
     /**
      * <p>Sixteen-bit Unicode Transformation Format, big-endian byte order.</p>
      *
      * <p>Every implementation of the Java platform is required to support this character encoding.</p>
      */
-    public static final String UTF_16BE = "UTF-16BE";
+    public static final String UTF_16BE = StandardCharsets.UTF_16BE.name();
 
     /**
      * <p>Sixteen-bit Unicode Transformation Format, little-endian byte order.</p>
      *
      * <p>Every implementation of the Java platform is required to support this character encoding.</p>
      */
-    public static final String UTF_16LE = "UTF-16LE";
+    public static final String UTF_16LE = StandardCharsets.UTF_16LE.name();
 
     /**
      * <p>Eight-bit Unicode Transformation Format.</p>
      *
      * <p>Every implementation of the Java platform is required to support this character encoding.</p>
      */
-    public static final String UTF_8 = "UTF-8";
+    public static final String UTF_8 = StandardCharsets.UTF_8.name();
 
     /**
      * <p>Returns whether the named charset is supported.</p>
@@ -88,6 +93,8 @@ public class CharEncoding {
      *
      * @param name  the name of the requested charset; may be either a canonical name or an alias, null returns false
      * @return {@code true} if the charset is available in the current Java virtual machine
+     * @deprecated Please use {@link Charset#isSupported(String)} instead, although be aware that {@code null}
+     * values are not accepted by that method and an {@link IllegalCharsetNameException} may be thrown.
      */
     public static boolean isSupported(final String name) {
         if (name == null) {

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/7c19a1ff/src/test/java/org/apache/commons/lang3/CharEncodingTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/CharEncodingTest.java b/src/test/java/org/apache/commons/lang3/CharEncodingTest.java
index 4324c6f..9e8e540 100644
--- a/src/test/java/org/apache/commons/lang3/CharEncodingTest.java
+++ b/src/test/java/org/apache/commons/lang3/CharEncodingTest.java
@@ -27,6 +27,7 @@ import org.junit.Test;
  * 
  * @see CharEncoding
  */
+@SuppressWarnings("deprecation")
 public class CharEncodingTest  {
 
     private void assertSupportedEncoding(final String name) {