Author: markt Date: Fri Oct 24 18:42:42 2014 New Revision: 1634117 URL: http://svn.apache.org/r1634117 Log: Follow up to 1631520. Use the cached encoder instance that already exists in the Charset
Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties tomcat/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties?rev=1634117&r1=1634116&r2=1634117&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties Fri Oct 24 18:42:42 2014 @@ -19,8 +19,6 @@ c2bConverter.recycleFailed=Failed to rec hexUtils.fromHex.oddDigits=The input must consist of an even number of hex digits hexUtils.fromHex.nonHex=The input must consist only of hex digits -messageBytes.toBytesFailed=Failed to convert the String [{0}] to bytes using Charset [{0}] - uDecoder.urlDecode.missingDigit=The % character must be followed by two hexademical digits uDecoder.convertHexDigit.notHex=[{0}] is not a hexadecimal digit uDecoder.urlDecode.uee=Unable to URL decode the specified input since the encoding [{0}] is not supported. Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java?rev=1634117&r1=1634116&r2=1634117&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/MessageBytes.java Fri Oct 24 18:42:42 2014 @@ -20,14 +20,8 @@ import java.io.IOException; import java.io.Serializable; import java.nio.ByteBuffer; import java.nio.CharBuffer; -import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; -import java.nio.charset.CharsetEncoder; -import java.util.HashMap; import java.util.Locale; -import java.util.Map; - -import org.apache.tomcat.util.res.StringManager; /** * This class is used to represent a subarray of bytes in an HTTP message. @@ -44,9 +38,6 @@ import org.apache.tomcat.util.res.String public final class MessageBytes implements Cloneable, Serializable { private static final long serialVersionUID = 1L; - private static final StringManager sm = StringManager.getManager( - Constants.Package); - // primary type ( whatever is set as original value ) private int type = T_NULL; @@ -75,8 +66,6 @@ public final class MessageBytes implemen // strValue!=null is the same private boolean hasStrValue=false; - private Map<Charset,CharsetEncoder> encoders = new HashMap<>(); - /** * Creates a new, uninitialized MessageBytes object. * Use static newInstance() in order to allow @@ -238,18 +227,7 @@ public final class MessageBytes implemen toString(); type=T_BYTES; Charset charset = byteC.getCharset(); - CharsetEncoder encoder = encoders.get(charset); - if (encoder == null) { - encoder = charset.newEncoder(); - encoders.put(charset, encoder); - } - ByteBuffer result; - try { - result = encoder.encode(CharBuffer.wrap(strValue)); - } catch (CharacterCodingException e) { - throw new IllegalArgumentException(sm.getString( - "messageBytes.toBytesFailed", strValue, charset), e); - } + ByteBuffer result = charset.encode(CharBuffer.wrap(strValue)); byteC.setBytes(result.array(), result.arrayOffset(), result.limit()); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org