Return-Path: X-Original-To: apmail-tomcat-dev-archive@www.apache.org Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6AD7D4F56 for ; Mon, 27 Jun 2011 13:39:37 +0000 (UTC) Received: (qmail 36840 invoked by uid 500); 27 Jun 2011 13:39:36 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 36733 invoked by uid 500); 27 Jun 2011 13:39:36 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 36724 invoked by uid 99); 27 Jun 2011 13:39:35 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Jun 2011 13:39:35 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Jun 2011 13:39:34 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3FC8423889BB for ; Mon, 27 Jun 2011 13:39:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1140156 - in /tomcat/trunk/java/org/apache/tomcat/util/buf: B2CConverter.java Constants.java LocalStrings.properties Date: Mon, 27 Jun 2011 13:39:14 -0000 To: dev@tomcat.apache.org From: markt@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110627133914.3FC8423889BB@eris.apache.org> Author: markt Date: Mon Jun 27 13:39:13 2011 New Revision: 1140156 URL: http://svn.apache.org/viewvc?rev=1140156&view=rev Log: Pre-populate Charset cache. Since cache is pre-populated, no need to look up non-matching values which effectively caches misses too. Added: tomcat/trunk/java/org/apache/tomcat/util/buf/Constants.java (with props) tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties (with props) Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java?rev=1140156&r1=1140155&r2=1140156&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/B2CConverter.java Mon Jun 27 13:39:13 2011 @@ -23,11 +23,12 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; -import java.nio.charset.IllegalCharsetNameException; -import java.nio.charset.UnsupportedCharsetException; import java.util.Locale; +import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; +import org.apache.tomcat.util.res.StringManager; + /** Efficient conversion of bytes to character . * * This uses the standard JDK mechanism - a reader - but provides mechanisms @@ -45,9 +46,20 @@ public class B2CConverter { private static final org.apache.juli.logging.Log log= org.apache.juli.logging.LogFactory.getLog( B2CConverter.class ); + private static final StringManager sm = + StringManager.getManager(Constants.Package); + private static final ConcurrentHashMap encodingToCharsetCache = new ConcurrentHashMap(); + static { + for (Entry entry : + Charset.availableCharsets().entrySet()) { + encodingToCharsetCache.put(entry.getKey().toLowerCase(), + entry.getValue()); + } + } + public static Charset getCharset(String enc) throws UnsupportedEncodingException{ @@ -55,21 +67,11 @@ public class B2CConverter { String lowerCaseEnc = enc.toLowerCase(Locale.US); Charset charset = encodingToCharsetCache.get(lowerCaseEnc); + if (charset == null) { - try { - charset = Charset.forName(enc); - } catch (IllegalCharsetNameException icne) { - UnsupportedEncodingException uee = - new UnsupportedEncodingException(); - uee.initCause(icne); - throw uee; - } catch (UnsupportedCharsetException uce) { - UnsupportedEncodingException uee = - new UnsupportedEncodingException(); - uee.initCause(uce); - throw uee; - } - encodingToCharsetCache.put(enc, charset); + // Pre-population of the cache means this must be invalid + throw new UnsupportedEncodingException( + sm.getString("b2cConvertor.unknownEncoding", enc)); } return charset; } Added: tomcat/trunk/java/org/apache/tomcat/util/buf/Constants.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/Constants.java?rev=1140156&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/Constants.java (added) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/Constants.java Mon Jun 27 13:39:13 2011 @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tomcat.util.buf; + +/** + * String constants for the file package. + */ +public final class Constants { + + public static final String Package = "org.apache.tomcat.util.buf"; + +} Propchange: tomcat/trunk/java/org/apache/tomcat/util/buf/Constants.java ------------------------------------------------------------------------------ svn:eol-style = native Added: 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=1140156&view=auto ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties (added) +++ tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties Mon Jun 27 13:39:13 2011 @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +b2cConvertor.unknownEncoding=The character encoding [{0}] is not supported Propchange: tomcat/trunk/java/org/apache/tomcat/util/buf/LocalStrings.properties ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org