Author: markt Date: Fri Sep 21 22:41:41 2012 New Revision: 1388713 URL: http://svn.apache.org/viewvc?rev=1388713&view=rev Log: Sync with trunk
Added: tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/collections/ConcurrentCache.java (with props) tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/http/parser/MediaTypeCache.java - copied unchanged from r1388712, tomcat/trunk/java/org/apache/tomcat/util/http/parser/MediaTypeCache.java Modified: tomcat/sandbox/trunk-resources/ (props changed) tomcat/sandbox/trunk-resources/java/org/apache/catalina/connector/Response.java Propchange: tomcat/sandbox/trunk-resources/ ------------------------------------------------------------------------------ Merged /tomcat/trunk:r1387959-1388712 Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/connector/Response.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/connector/Response.java?rev=1388713&r1=1388712&r2=1388713&view=diff ============================================================================== --- tomcat/sandbox/trunk-resources/java/org/apache/catalina/connector/Response.java (original) +++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/connector/Response.java Fri Sep 21 22:41:41 2012 @@ -18,7 +18,6 @@ package org.apache.catalina.connector; import java.io.IOException; import java.io.PrintWriter; -import java.io.StringReader; import java.net.MalformedURLException; import java.security.AccessController; import java.security.PrivilegedAction; @@ -51,8 +50,7 @@ import org.apache.tomcat.util.buf.UEncod import org.apache.tomcat.util.http.FastHttpDateFormat; import org.apache.tomcat.util.http.MimeHeaders; import org.apache.tomcat.util.http.ServerCookie; -import org.apache.tomcat.util.http.parser.AstMediaType; -import org.apache.tomcat.util.http.parser.HttpParser; +import org.apache.tomcat.util.http.parser.MediaTypeCache; import org.apache.tomcat.util.http.parser.ParseException; import org.apache.tomcat.util.net.URL; import org.apache.tomcat.util.res.StringManager; @@ -71,6 +69,9 @@ public class Response // ----------------------------------------------------------- Constructors + private static final MediaTypeCache MEDIA_TYPE_CACHE = + new MediaTypeCache(100); + /** * Compliance with SRV.15.2.22.1. A call to Response.getWriter() if no * character encoding has been specified will result in subsequent calls to @@ -708,10 +709,9 @@ public class Response return; } - AstMediaType m = null; - HttpParser hp = new HttpParser(new StringReader(type)); + String[] m = null; try { - m = hp.MediaType(); + m = MEDIA_TYPE_CACHE.parse(type); } catch (ParseException e) { // Invalid - Assume no charset and just pass through whatever // the user provided. @@ -719,13 +719,12 @@ public class Response return; } - coyoteResponse.setContentTypeNoCharset(m.toStringNoCharset()); + coyoteResponse.setContentTypeNoCharset(m[0]); - String charset = m.getCharset(); - if (charset != null) { + if (m[1] != null) { // Ignore charset if getWriter() has already been called if (!usingWriter) { - coyoteResponse.setCharacterEncoding(charset); + coyoteResponse.setCharacterEncoding(m[1]); isCharacterEncodingSet = true; } } Added: tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/collections/ConcurrentCache.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/collections/ConcurrentCache.java?rev=1388713&view=auto ============================================================================== --- tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/collections/ConcurrentCache.java (added) +++ tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/collections/ConcurrentCache.java Fri Sep 21 22:41:41 2012 @@ -0,0 +1,59 @@ +/* + * 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.collections; + +import java.util.Map; +import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentHashMap; + +public final class ConcurrentCache<K,V> { + + private final int size; + + private final Map<K,V> eden; + + private final Map<K,V> longterm; + + public ConcurrentCache(int size) { + this.size = size; + this.eden = new ConcurrentHashMap<>(size); + this.longterm = new WeakHashMap<>(size); + } + + public V get(K k) { + V v = this.eden.get(k); + if (v == null) { + synchronized (longterm) { + v = this.longterm.get(k); + } + if (v != null) { + this.eden.put(k, v); + } + } + return v; + } + + public void put(K k, V v) { + if (this.eden.size() >= size) { + synchronized (longterm) { + this.longterm.putAll(this.eden); + } + this.eden.clear(); + } + this.eden.put(k, v); + } +} Propchange: tomcat/sandbox/trunk-resources/java/org/apache/tomcat/util/collections/ConcurrentCache.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org