You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2014/01/24 18:04:05 UTC

svn commit: r1561066 - in /httpcomponents/httpclient/trunk: httpclient-cache/src/test/java/org/apache/http/impl/client/cache/ httpclient/src/main/java/org/apache/http/impl/auth/ httpclient/src/test/java/org/apache/http/client/entity/ httpclient/src/tes...

Author: olegk
Date: Fri Jan 24 17:04:04 2014
New Revision: 1561066

URL: http://svn.apache.org/r1561066
Log:
Use String methods and constructors that require Charset instead of String

Modified:
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntrySerializers.java
    httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestStaleWhileRevalidationReleasesConnection.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestDecompressingEntity.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNTLMEngineImpl.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/RandomHandler.java
    httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java
    httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartContentBody.java
    httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntrySerializers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntrySerializers.java?rev=1561066&r1=1561065&r2=1561066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntrySerializers.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestHttpCacheEntrySerializers.java Fri Jan 24 17:04:04 2014
@@ -32,7 +32,6 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
 import java.util.Arrays;
 import java.util.Date;
@@ -80,7 +79,7 @@ public class TestHttpCacheEntrySerialize
         assertTrue(areEqual(readEntry, writeEntry));
     }
 
-    private HttpCacheEntry makeCacheEntryWithVariantMap() throws UnsupportedEncodingException {
+    private HttpCacheEntry makeCacheEntryWithVariantMap() {
         final Header[] headers = new Header[5];
         for (int i = 0; i < headers.length; i++) {
             headers[i] = new BasicHeader("header" + i, "value" + i);
@@ -94,7 +93,7 @@ public class TestHttpCacheEntrySerialize
         variantMap.put("test variant 2","true");
         final HttpCacheEntry cacheEntry = new HttpCacheEntry(new Date(), new Date(),
                 slObj, headers, new HeapResource(Base64.decodeBase64(body
-                        .getBytes(UTF8.name()))), variantMap);
+                        .getBytes(UTF8))), variantMap);
 
         return cacheEntry;
     }

Modified: httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestStaleWhileRevalidationReleasesConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestStaleWhileRevalidationReleasesConnection.java?rev=1561066&r1=1561065&r2=1561066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestStaleWhileRevalidationReleasesConnection.java (original)
+++ httpcomponents/httpclient/trunk/httpclient-cache/src/test/java/org/apache/http/impl/client/cache/TestStaleWhileRevalidationReleasesConnection.java Fri Jan 24 17:04:04 2014
@@ -26,6 +26,7 @@
  */
 package org.apache.http.impl.client.cache;
 
+import org.apache.http.Consts;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
@@ -50,7 +51,6 @@ import org.junit.Before;
 import org.junit.Test;
 
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.util.Locale;
 
 
@@ -283,11 +283,7 @@ public class TestStaleWhileRevalidationR
         public byte[] getHeaderContent(final HttpRequest request) {
             final Header contentHeader = request.getFirstHeader(DEFAULT_CLIENT_CONTROLLED_CONTENT_HEADER);
             if(contentHeader!=null) {
-                try {
-                    return contentHeader.getValue().getBytes("UTF-8");
-                } catch(final UnsupportedEncodingException e) {
-                    return contentHeader.getValue().getBytes();
-                }
+                return contentHeader.getValue().getBytes(Consts.UTF_8);
             } else {
                 return DEFAULT_CONTENT;
             }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java?rev=1561066&r1=1561065&r2=1561066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/auth/NTLMEngineImpl.java Fri Jan 24 17:04:04 2014
@@ -27,6 +27,7 @@
 package org.apache.http.impl.auth;
 
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
 import java.security.Key;
 import java.security.MessageDigest;
 import java.util.Arrays;
@@ -36,7 +37,9 @@ import javax.crypto.Cipher;
 import javax.crypto.spec.SecretKeySpec;
 
 import org.apache.commons.codec.binary.Base64;
+import org.apache.http.Consts;
 import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.util.CharsetUtils;
 import org.apache.http.util.EncodingUtils;
 
 /**
@@ -48,6 +51,8 @@ import org.apache.http.util.EncodingUtil
 @NotThreadSafe
 final class NTLMEngineImpl implements NTLMEngine {
 
+    private static final Charset UNICODE_LITTLE_UNMARKED = CharsetUtils.lookup("UnicodeLittleUnmarked");
+
     // Flags we use; descriptions according to:
     // http://davenport.sourceforge.net/ntlm.html
     // and
@@ -81,16 +86,13 @@ final class NTLMEngineImpl implements NT
     }
 
     /** Character encoding */
-    static final String DEFAULT_CHARSET = "ASCII";
-
-    /** The character set to use for encoding the credentials */
-    private String credentialCharset = DEFAULT_CHARSET;
+    static final Charset DEFAULT_CHARSET = Consts.ASCII;
 
     /** The signature string as bytes in the default encoding */
     private static final byte[] SIGNATURE;
 
     static {
-        final byte[] bytesWithoutNull = EncodingUtils.getBytes("NTLMSSP", "ASCII");
+        final byte[] bytesWithoutNull = "NTLMSSP".getBytes(Consts.ASCII);
         SIGNATURE = new byte[bytesWithoutNull.length + 1];
         System.arraycopy(bytesWithoutNull, 0, SIGNATURE, 0, bytesWithoutNull.length);
         SIGNATURE[bytesWithoutNull.length] = (byte) 0x00;
@@ -169,21 +171,6 @@ final class NTLMEngineImpl implements NT
                 targetInformation).getResponse();
     }
 
-    /**
-     * @return Returns the credentialCharset.
-     */
-    String getCredentialCharset() {
-        return credentialCharset;
-    }
-
-    /**
-     * @param credentialCharset
-     *            The credentialCharset to set.
-     */
-    void setCredentialCharset(final String credentialCharset) {
-        this.credentialCharset = credentialCharset;
-    }
-
     /** Strip dot suffix from a name */
     private static String stripDotSuffix(final String value) {
         if (value == null) {
@@ -608,13 +595,13 @@ final class NTLMEngineImpl implements NT
      */
     private static byte[] lmHash(final String password) throws NTLMEngineException {
         try {
-            final byte[] oemPassword = password.toUpperCase(Locale.US).getBytes("US-ASCII");
+            final byte[] oemPassword = password.toUpperCase(Locale.US).getBytes(Consts.ASCII);
             final int length = Math.min(oemPassword.length, 14);
             final byte[] keyBytes = new byte[14];
             System.arraycopy(oemPassword, 0, keyBytes, 0, length);
             final Key lowKey = createDESKey(keyBytes, 0);
             final Key highKey = createDESKey(keyBytes, 7);
-            final byte[] magicConstant = "KGS!@#$%".getBytes("US-ASCII");
+            final byte[] magicConstant = "KGS!@#$%".getBytes(Consts.ASCII);
             final Cipher des = Cipher.getInstance("DES/ECB/NoPadding");
             des.init(Cipher.ENCRYPT_MODE, lowKey);
             final byte[] lowHash = des.doFinal(magicConstant);
@@ -639,14 +626,13 @@ final class NTLMEngineImpl implements NT
      *         the NTLM Response and the NTLMv2 and LMv2 Hashes.
      */
     private static byte[] ntlmHash(final String password) throws NTLMEngineException {
-        try {
-            final byte[] unicodePassword = password.getBytes("UnicodeLittleUnmarked");
-            final MD4 md4 = new MD4();
-            md4.update(unicodePassword);
-            return md4.getOutput();
-        } catch (final UnsupportedEncodingException e) {
-            throw new NTLMEngineException("Unicode not supported: " + e.getMessage(), e);
+        if (UNICODE_LITTLE_UNMARKED == null) {
+            throw new NTLMEngineException("Unicode not supported");
         }
+        final byte[] unicodePassword = password.getBytes(UNICODE_LITTLE_UNMARKED);
+        final MD4 md4 = new MD4();
+        md4.update(unicodePassword);
+        return md4.getOutput();
     }
 
     /**
@@ -657,17 +643,16 @@ final class NTLMEngineImpl implements NT
      */
     private static byte[] lmv2Hash(final String domain, final String user, final byte[] ntlmHash)
             throws NTLMEngineException {
-        try {
-            final HMACMD5 hmacMD5 = new HMACMD5(ntlmHash);
-            // Upper case username, upper case domain!
-            hmacMD5.update(user.toUpperCase(Locale.US).getBytes("UnicodeLittleUnmarked"));
-            if (domain != null) {
-                hmacMD5.update(domain.toUpperCase(Locale.US).getBytes("UnicodeLittleUnmarked"));
-            }
-            return hmacMD5.getOutput();
-        } catch (final UnsupportedEncodingException e) {
-            throw new NTLMEngineException("Unicode not supported! " + e.getMessage(), e);
+        if (UNICODE_LITTLE_UNMARKED == null) {
+            throw new NTLMEngineException("Unicode not supported");
+        }
+        final HMACMD5 hmacMD5 = new HMACMD5(ntlmHash);
+        // Upper case username, upper case domain!
+        hmacMD5.update(user.toUpperCase(Locale.US).getBytes(UNICODE_LITTLE_UNMARKED));
+        if (domain != null) {
+            hmacMD5.update(domain.toUpperCase(Locale.US).getBytes(UNICODE_LITTLE_UNMARKED));
         }
+        return hmacMD5.getOutput();
     }
 
     /**
@@ -678,17 +663,16 @@ final class NTLMEngineImpl implements NT
      */
     private static byte[] ntlmv2Hash(final String domain, final String user, final byte[] ntlmHash)
             throws NTLMEngineException {
-        try {
-            final HMACMD5 hmacMD5 = new HMACMD5(ntlmHash);
-            // Upper case username, mixed case target!!
-            hmacMD5.update(user.toUpperCase(Locale.US).getBytes("UnicodeLittleUnmarked"));
-            if (domain != null) {
-                hmacMD5.update(domain.getBytes("UnicodeLittleUnmarked"));
-            }
-            return hmacMD5.getOutput();
-        } catch (final UnsupportedEncodingException e) {
-            throw new NTLMEngineException("Unicode not supported! " + e.getMessage(), e);
+        if (UNICODE_LITTLE_UNMARKED == null) {
+            throw new NTLMEngineException("Unicode not supported");
         }
+        final HMACMD5 hmacMD5 = new HMACMD5(ntlmHash);
+        // Upper case username, mixed case target!!
+        hmacMD5.update(user.toUpperCase(Locale.US).getBytes(UNICODE_LITTLE_UNMARKED));
+        if (domain != null) {
+            hmacMD5.update(domain.getBytes(UNICODE_LITTLE_UNMARKED));
+        }
+        return hmacMD5.getOutput();
     }
 
     /**
@@ -848,8 +832,7 @@ final class NTLMEngineImpl implements NT
 
         /** Constructor to use when message contents are known */
         NTLMMessage(final String messageBody, final int expectedType) throws NTLMEngineException {
-            messageContents = Base64.decodeBase64(EncodingUtils.getBytes(messageBody,
-                    DEFAULT_CHARSET));
+            messageContents = Base64.decodeBase64(messageBody.getBytes(DEFAULT_CHARSET));
             // Look for NTLM message
             if (messageContents.length < SIGNATURE.length) {
                 throw new NTLMEngineException("NTLM message decoding error - packet too short");
@@ -1001,18 +984,14 @@ final class NTLMEngineImpl implements NT
         /** Constructor. Include the arguments the message will need */
         Type1Message(final String domain, final String host) throws NTLMEngineException {
             super();
-            try {
-                // Strip off domain name from the host!
-                final String unqualifiedHost = convertHost(host);
-                // Use only the base domain name!
-                final String unqualifiedDomain = convertDomain(domain);
-
-                hostBytes = unqualifiedHost != null? unqualifiedHost.getBytes("ASCII") : null;
-                domainBytes = unqualifiedDomain != null ? unqualifiedDomain
-                        .toUpperCase(Locale.US).getBytes("ASCII") : null;
-            } catch (final UnsupportedEncodingException e) {
-                throw new NTLMEngineException("Unicode unsupported: " + e.getMessage(), e);
-            }
+            // Strip off domain name from the host!
+            final String unqualifiedHost = convertHost(host);
+            // Use only the base domain name!
+            final String unqualifiedDomain = convertDomain(domain);
+
+            hostBytes = unqualifiedHost != null? unqualifiedHost.getBytes(Consts.ASCII) : null;
+            domainBytes = unqualifiedDomain != null ? unqualifiedDomain
+                    .toUpperCase(Locale.US).getBytes(Consts.ASCII) : null;
         }
 
         /**
@@ -1260,16 +1239,13 @@ final class NTLMEngineImpl implements NT
             } else {
                 sessionKey = null;
             }
-
-            try {
-                hostBytes = unqualifiedHost != null ? unqualifiedHost
-                        .getBytes("UnicodeLittleUnmarked") : null;
-                domainBytes = unqualifiedDomain != null ? unqualifiedDomain
-                        .toUpperCase(Locale.US).getBytes("UnicodeLittleUnmarked") : null;
-                userBytes = user.getBytes("UnicodeLittleUnmarked");
-            } catch (final UnsupportedEncodingException e) {
-                throw new NTLMEngineException("Unicode not supported: " + e.getMessage(), e);
+            if (UNICODE_LITTLE_UNMARKED == null) {
+                throw new NTLMEngineException("Unicode not supported");
             }
+            hostBytes = unqualifiedHost != null ? unqualifiedHost.getBytes(UNICODE_LITTLE_UNMARKED) : null;
+            domainBytes = unqualifiedDomain != null ? unqualifiedDomain
+                    .toUpperCase(Locale.US).getBytes(UNICODE_LITTLE_UNMARKED) : null;
+            userBytes = user.getBytes(UNICODE_LITTLE_UNMARKED);
         }
 
         /** Assemble the response */

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestDecompressingEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestDecompressingEntity.java?rev=1561066&r1=1561065&r2=1561066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestDecompressingEntity.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/entity/TestDecompressingEntity.java Fri Jan 24 17:04:04 2014
@@ -35,6 +35,7 @@ import java.util.zip.CRC32;
 import java.util.zip.CheckedInputStream;
 import java.util.zip.Checksum;
 
+import org.apache.http.Consts;
 import org.apache.http.HttpEntity;
 import org.apache.http.entity.InputStreamEntity;
 import org.apache.http.entity.StringEntity;
@@ -61,7 +62,7 @@ public class TestDecompressingEntity {
     @Test
     public void testStreaming() throws Exception {
         final CRC32 crc32 = new CRC32();
-        final ByteArrayInputStream in = new ByteArrayInputStream("1234567890".getBytes("ASCII"));
+        final ByteArrayInputStream in = new ByteArrayInputStream("1234567890".getBytes(Consts.ASCII));
         final InputStreamEntity wrapped = new InputStreamEntity(in, -1);
         final ChecksumEntity entity = new ChecksumEntity(wrapped, crc32);
         Assert.assertTrue(entity.isStreaming());

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNTLMEngineImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNTLMEngineImpl.java?rev=1561066&r1=1561065&r2=1561066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNTLMEngineImpl.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/auth/TestNTLMEngineImpl.java Fri Jan 24 17:04:04 2014
@@ -26,6 +26,7 @@
  */
 package org.apache.http.impl.auth;
 
+import org.apache.http.Consts;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -69,7 +70,7 @@ public class TestNTLMEngineImpl {
     static void checkMD4(final String input, final String hexOutput) throws Exception {
         NTLMEngineImpl.MD4 md4;
         md4 = new NTLMEngineImpl.MD4();
-        md4.update(input.getBytes("ASCII"));
+        md4.update(input.getBytes(Consts.ASCII));
         final byte[] answer = md4.getOutput();
         final byte[] correctAnswer = toBytes(hexOutput);
         if (answer.length != correctAnswer.length) {

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java?rev=1561066&r1=1561065&r2=1561066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/integration/TestContentCodings.java Fri Jan 24 17:04:04 2014
@@ -39,6 +39,7 @@ import java.util.concurrent.Executors;
 import java.util.zip.Deflater;
 import java.util.zip.GZIPOutputStream;
 
+import org.apache.http.Consts;
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
 import org.apache.http.HttpException;
@@ -310,7 +311,7 @@ public class TestContentCodings extends 
                             // response.setEntity(new InputStreamEntity(new DeflaterInputStream(new
                             // ByteArrayInputStream(
                             // entityText.getBytes("utf-8"))), -1));
-                            final byte[] uncompressed = entityText.getBytes("utf-8");
+                            final byte[] uncompressed = entityText.getBytes(Consts.UTF_8);
                             final Deflater compressor = new Deflater(Deflater.DEFAULT_COMPRESSION, rfc1951);
                             compressor.setInput(uncompressed);
                             compressor.finish();
@@ -368,7 +369,7 @@ public class TestContentCodings extends 
                             final OutputStream out = new GZIPOutputStream(bytes);
 
                             final ByteArrayInputStream uncompressed = new ByteArrayInputStream(
-                                    entityText.getBytes("utf-8"));
+                                    entityText.getBytes(Consts.UTF_8));
 
                             final byte[] buf = new byte[60];
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java?rev=1561066&r1=1561065&r2=1561066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/SessionInputBufferMock.java Fri Jan 24 17:04:04 2014
@@ -100,7 +100,7 @@ public class SessionInputBufferMock exte
     public SessionInputBufferMock(
             final String s,
             final Charset charset) throws UnsupportedEncodingException {
-        this(s.getBytes(charset.name()), charset);
+        this(s.getBytes(charset), charset);
     }
 
     @Override

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/RandomHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/RandomHandler.java?rev=1561066&r1=1561065&r2=1561066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/RandomHandler.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/RandomHandler.java Fri Jan 24 17:04:04 2014
@@ -30,9 +30,9 @@ package org.apache.http.localserver;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
 import java.util.Locale;
 
+import org.apache.http.Consts;
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
@@ -42,19 +42,10 @@ import org.apache.http.entity.AbstractHt
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
 
-
-
 /**
  * A handler that generates random data.
- *
- *
- *
- * <!-- empty lines to avoid 'svn diff' problems -->
  */
-public class RandomHandler
-    implements HttpRequestHandler {
-
-    // public default constructor
+public class RandomHandler implements HttpRequestHandler {
 
     /**
      * Handles a request by generating random data.
@@ -131,19 +122,8 @@ public class RandomHandler
     public static class RandomEntity extends AbstractHttpEntity {
 
         /** The range from which to generate random data. */
-        private final static byte[] RANGE;
-        static {
-            byte[] range = null;
-            try {
-                range = ("abcdefghijklmnopqrstuvwxyz" +
-                         "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789"
-                    ).getBytes("US-ASCII");
-            } catch (final UnsupportedEncodingException uex) {
-                // never, US-ASCII is guaranteed
-            }
-            RANGE = range;
-        }
-
+        private final static byte[] RANGE = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
+                .getBytes(Consts.ASCII);
 
         /** The length of the random data to generate. */
         protected final long length;

Modified: httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java?rev=1561066&r1=1561065&r2=1561066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java (original)
+++ httpcomponents/httpclient/trunk/httpmime/src/main/java/org/apache/http/entity/mime/content/StringBody.java Fri Jan 24 17:04:04 2014
@@ -35,7 +35,6 @@ import java.io.OutputStream;
 import java.io.Reader;
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
-import java.nio.charset.UnsupportedCharsetException;
 
 import org.apache.http.Consts;
 import org.apache.http.entity.ContentType;
@@ -154,13 +153,7 @@ public class StringBody extends Abstract
     public StringBody(final String text, final ContentType contentType) {
         super(contentType);
         final Charset charset = contentType.getCharset();
-        final String csname = charset != null ? charset.name() : Consts.ASCII.name();
-        try {
-            this.content = text.getBytes(csname);
-        } catch (final UnsupportedEncodingException ex) {
-            // Should never happen
-            throw new UnsupportedCharsetException(csname);
-        }
+        this.content = text.getBytes(charset != null ? charset : Consts.ASCII);
     }
 
     public Reader getReader() {

Modified: httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartContentBody.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartContentBody.java?rev=1561066&r1=1561065&r2=1561066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartContentBody.java (original)
+++ httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartContentBody.java Fri Jan 24 17:04:04 2014
@@ -29,6 +29,7 @@ package org.apache.http.entity.mime;
 
 import java.io.ByteArrayInputStream;
 
+import org.apache.http.Consts;
 import org.apache.http.entity.ContentType;
 import org.apache.http.entity.mime.content.InputStreamBody;
 import org.apache.http.entity.mime.content.StringBody;
@@ -66,7 +67,7 @@ public class TestMultipartContentBody {
 
     @Test
     public void testInputStreamBody() throws Exception {
-        final byte[] stuff = "Stuff".getBytes("US-ASCII");
+        final byte[] stuff = "Stuff".getBytes(Consts.ASCII);
         final InputStreamBody b1 = new InputStreamBody(new ByteArrayInputStream(stuff), "stuff");
         Assert.assertEquals(-1, b1.getContentLength());
 

Modified: httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java?rev=1561066&r1=1561065&r2=1561066&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java (original)
+++ httpcomponents/httpclient/trunk/httpmime/src/test/java/org/apache/http/entity/mime/TestMultipartForm.java Fri Jan 24 17:04:04 2014
@@ -341,17 +341,17 @@ public class TestMultipartForm {
             "Content-Disposition: form-data; name=\"field1\"\r\n" +
             "Content-Type: text/plain; charset=ISO-8859-1\r\n" +
             "Content-Transfer-Encoding: 8bit\r\n" +
-            "\r\n").getBytes("US-ASCII"));
-        out2.write(s1.getBytes("ISO-8859-1"));
+            "\r\n").getBytes(Consts.ASCII));
+        out2.write(s1.getBytes(Consts.ISO_8859_1));
         out2.write(("\r\n" +
             "--foo\r\n" +
             "Content-Disposition: form-data; name=\"field2\"\r\n" +
             "Content-Type: text/plain; charset=KOI8-R\r\n" +
             "Content-Transfer-Encoding: 8bit\r\n" +
-            "\r\n").getBytes("US-ASCII"));
-        out2.write(s2.getBytes("KOI8-R"));
+            "\r\n").getBytes(Consts.ASCII));
+        out2.write(s2.getBytes(Charset.forName("KOI8-R")));
         out2.write(("\r\n" +
-            "--foo--\r\n").getBytes("US-ASCII"));
+            "--foo--\r\n").getBytes(Consts.ASCII));
         out2.close();
 
         final byte[] actual = out1.toByteArray();