tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@locus.apache.org
Subject cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util RequestUtil.java
Date Sun, 17 Dec 2000 01:03:58 GMT
craigmcc    00/12/16 17:03:58

  Modified:    catalina/src/share/org/apache/catalina/util RequestUtil.java
  Log:
  Make the cookie parsing more efficient by dispensing with a StringTokenizer,
  and using an ArrayList instead of a Vector.
  
  Revision  Changes    Path
  1.11      +19 -14    jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/RequestUtil.java
  
  Index: RequestUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/RequestUtil.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- RequestUtil.java	2000/12/12 07:50:16	1.10
  +++ RequestUtil.java	2000/12/17 01:03:58	1.11
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/RequestUtil.java,v
1.10 2000/12/12 07:50:16 remm Exp $
  - * $Revision: 1.10 $
  - * $Date: 2000/12/12 07:50:16 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/util/RequestUtil.java,v
1.11 2000/12/17 01:03:58 craigmcc Exp $
  + * $Revision: 1.11 $
  + * $Date: 2000/12/17 01:03:58 $
    *
    * ====================================================================
    *
  @@ -67,11 +67,10 @@
   
   import java.net.URLDecoder;
   import java.text.SimpleDateFormat;
  +import java.util.ArrayList;
   import java.util.Date;
   import java.util.Map;
  -import java.util.StringTokenizer;
   import java.util.TimeZone;
  -import java.util.Vector;
   import javax.servlet.http.Cookie;
   
   
  @@ -79,7 +78,7 @@
    * General purpose request parsing and encoding utility methods.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.10 $ $Date: 2000/12/12 07:50:16 $
  + * @version $Revision: 1.11 $ $Date: 2000/12/17 01:03:58 $
    */
   
   public final class RequestUtil {
  @@ -185,25 +184,31 @@
   	if ((header == null) || (header.length() < 1))
   	    return (new Cookie[0]);
   
  -	Vector cookieJar = new Vector();
  -	StringTokenizer tokens = new StringTokenizer(header, ";");
  -	while (tokens.hasMoreTokens()) {
  +        ArrayList cookies = new ArrayList();
  +        while (header.length() > 0) {
  +            int semicolon = header.indexOf(";");
  +            if (semicolon < 0)
  +                semicolon = header.length();
  +            if (semicolon == 0)
  +                break;
  +            String token = header.substring(0, semicolon);
  +            if (semicolon < header.length())
  +                header = header.substring(semicolon + 1);
  +            else
  +                header = "";
   	    try {
  -		String token = tokens.nextToken();
   		int equals = token.indexOf("=");
   		if (equals > 0) {
   		    String name = URLDecode(token.substring(0, equals).trim());
   		    String value = URLDecode(token.substring(equals+1).trim());
  -		    cookieJar.addElement(new Cookie(name, value));
  +		    cookies.add(new Cookie(name, value));
   		}
   	    } catch (Throwable e) {
   		;
   	    }
   	}
   
  -	Cookie[] cookies = new Cookie[cookieJar.size()];
  -	cookieJar.copyInto(cookies);
  -	return (cookies);
  +        return ((Cookie[]) cookies.toArray(new Cookie[cookies.size()]));
   
       }
   
  
  
  

Mime
View raw message