tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util DateTool.java MessageBytes.java MimeHeaders.java MimeHeaderField.java
Date Mon, 28 Aug 2000 06:08:19 GMT
costin      00/08/27 23:08:19

  Modified:    src/facade22/org/apache/tomcat/facade
                        HttpServletResponseFacade.java
               src/facade23/org/apache/tomcat/facade23
                        HttpServletResponseFacade.java
               src/share/org/apache/tomcat/core Response.java
               src/share/org/apache/tomcat/request StaticInterceptor.java
               src/share/org/apache/tomcat/service/connector
                        Ajp12ConnectionHandler.java
                        Ajp13ConnectorRequest.java
                        JNIConnectionHandler.java
               src/share/org/apache/tomcat/service/http
                        HttpRequestAdapter.java HttpResponseAdapter.java
               src/share/org/apache/tomcat/util DateTool.java
                        MessageBytes.java MimeHeaders.java
  Removed:     src/share/org/apache/tomcat/util MimeHeaderField.java
  Log:
  First step in MimeHeaders refactoring.
  
  Removed MimeHeaderFiled - MessageStrings will be used for all conversions
  ( with cashing, encoding and minimal GC)
  The internal implementation of MimeHeaders is no longer accessible
  - all code that used it is now cleaned up.
  
  The idea is to optimize the data representation ( getHeaders() and
  getHeaderNames() are in a very bad shape ), and maybe reuse it to
  store parameters ( similar requirements - it's a map with some
  special use-cases and afferent optimizations + support for charsets)
  
  Revision  Changes    Path
  1.2       +5 -11     jakarta-tomcat/src/facade22/org/apache/tomcat/facade/HttpServletResponseFacade.java
  
  Index: HttpServletResponseFacade.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/HttpServletResponseFacade.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpServletResponseFacade.java	2000/08/23 05:39:20	1.1
  +++ HttpServletResponseFacade.java	2000/08/28 06:08:15	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/HttpServletResponseFacade.java,v
1.1 2000/08/23 05:39:20 costin Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/08/23 05:39:20 $
  + * $Header: /home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/HttpServletResponseFacade.java,v
1.2 2000/08/28 06:08:15 costin Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/08/28 06:08:15 $
    *
    * ====================================================================
    *
  @@ -249,18 +249,12 @@
   
       public void setDateHeader(String name, long date) {
   	MimeHeaders headers=response.getMimeHeaders();
  -	MimeHeaderField headerF=headers.find( name );
  -	if( headerF == null )
  -	    headerF=headers.putHeader();
  -	headerF.setName( name );
  -	headerF.setDateValue( date );
  +	headers.setDateHeader( name, date );
       }
   
       public void addDateHeader(String name, long value) {
   	MimeHeaders headers=response.getMimeHeaders();
  -	MimeHeaderField headerF=headers.putHeader();
  -	headerF.setName( name );
  -	headerF.setDateValue( value );
  +	headers.addDateHeader( name, value );
       }
   
       public void setHeader(String name, String value) {
  
  
  
  1.2       +5 -11     jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/HttpServletResponseFacade.java
  
  Index: HttpServletResponseFacade.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/HttpServletResponseFacade.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpServletResponseFacade.java	2000/08/23 04:06:42	1.1
  +++ HttpServletResponseFacade.java	2000/08/28 06:08:15	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/HttpServletResponseFacade.java,v
1.1 2000/08/23 04:06:42 costin Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/08/23 04:06:42 $
  + * $Header: /home/cvs/jakarta-tomcat/src/facade23/org/apache/tomcat/facade23/HttpServletResponseFacade.java,v
1.2 2000/08/28 06:08:15 costin Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/08/28 06:08:15 $
    *
    * ====================================================================
    *
  @@ -247,18 +247,12 @@
   
       public void setDateHeader(String name, long date) {
   	MimeHeaders headers=response.getMimeHeaders();
  -	MimeHeaderField headerF=headers.find( name );
  -	if( headerF == null )
  -	    headerF=headers.putHeader();
  -	headerF.setName( name );
  -	headerF.setDateValue( date );
  +	headers.setDateHeader( name, date);
       }
   
       public void addDateHeader(String name, long value) {
   	MimeHeaders headers=response.getMimeHeaders();
  -	MimeHeaderField headerF=headers.putHeader();
  -	headerF.setName( name );
  -	headerF.setDateValue( value );
  +	headers.addDateHeader( name, value );
       }
   
       public void setHeader(String name, String value) {
  
  
  
  1.32      +7 -7      jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java
  
  Index: Response.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- Response.java	2000/08/27 20:37:29	1.31
  +++ Response.java	2000/08/28 06:08:15	1.32
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v 1.31
2000/08/27 20:37:29 costin Exp $
  - * $Revision: 1.31 $
  - * $Date: 2000/08/27 20:37:29 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java,v 1.32
2000/08/28 06:08:15 costin Exp $
  + * $Revision: 1.32 $
  + * $Date: 2000/08/28 06:08:15 $
    *
    * ====================================================================
    *
  @@ -245,7 +245,7 @@
   	    if( checkSpecialHeader(name, value) )
   		return;
   	}
  -	headers.putHeader(name, value);
  +	headers.setHeader(name, value);
       }
   
       public void addHeader(String name, String value) {
  @@ -430,7 +430,7 @@
           setContentType(newType);
   
   	// only one header !
  -	headers.putHeader("Content-Language", contentLanguage);
  +	headers.setHeader("Content-Language", contentLanguage);
       }
   
       public String getCharacterEncoding() {
  @@ -444,7 +444,7 @@
           if (encoding != null) {
   	    characterEncoding = encoding;
           }
  -	headers.putHeader("Content-Type", contentType);
  +	headers.setHeader("Content-Type", contentType);
       }
   
       public String getContentType() {
  @@ -454,7 +454,7 @@
       public void setContentLength(int contentLength) {
           if( included ) return;
   	this.contentLength = contentLength;
  -	headers.putIntHeader("Content-Length", contentLength);
  +	headers.setIntHeader("Content-Length", contentLength);
       }
   
       public int getContentLength() {
  
  
  
  1.15      +1 -5      jakarta-tomcat/src/share/org/apache/tomcat/request/StaticInterceptor.java
  
  Index: StaticInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/StaticInterceptor.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- StaticInterceptor.java	2000/08/24 21:11:42	1.14
  +++ StaticInterceptor.java	2000/08/28 06:08:16	1.15
  @@ -290,11 +290,7 @@
   
       static void setDateHeader( Response res, String name, long value ) {
   	MimeHeaders headers=res.getMimeHeaders();
  -	MimeHeaderField headerF=headers.find( name );
  -	if( headerF == null )
  -	    headerF=headers.putHeader();
  -	headerF.setName( name );
  -	headerF.setDateValue( value );
  +	headers.setDateHeader( name, value );
       }
   
       /** All path checks that were part of DefaultServlet
  
  
  
  1.35      +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp12ConnectionHandler.java
  
  Index: Ajp12ConnectionHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp12ConnectionHandler.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- Ajp12ConnectionHandler.java	2000/08/14 21:54:23	1.34
  +++ Ajp12ConnectionHandler.java	2000/08/28 06:08:17	1.35
  @@ -365,7 +365,7 @@
   		case 3: // Header
   		    token1 = readString(ajpin, null);
   		    token2 = readString(ajpin, "");
  -		    headers.putHeader(token1.toLowerCase(), token2);
  +		    headers.addHeader(token1.toLowerCase(), token2);
   		    break;
   
   		case 254: // Signal
  
  
  
  1.10      +4 -4      jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectorRequest.java
  
  Index: Ajp13ConnectorRequest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectorRequest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Ajp13ConnectorRequest.java	2000/08/12 04:55:47	1.9
  +++ Ajp13ConnectorRequest.java	2000/08/28 06:08:17	1.10
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectorRequest.java,v
1.9 2000/08/12 04:55:47 costin Exp $
  - * $Revision: 1.9 $
  - * $Date: 2000/08/12 04:55:47 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectorRequest.java,v
1.10 2000/08/28 06:08:17 costin Exp $
  + * $Revision: 1.10 $
  + * $Date: 2000/08/28 06:08:17 $
    *
    * ====================================================================
    *
  @@ -166,7 +166,7 @@
               }
   
               String hValue = msg.getString();
  -            headers.putHeader( hName , hValue );
  +            headers.addHeader( hName , hValue );
               //log( "Head: " + hName + "=" + hValue);
           }
   
  
  
  
  1.16      +6 -7      jakarta-tomcat/src/share/org/apache/tomcat/service/connector/JNIConnectionHandler.java
  
  Index: JNIConnectionHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/JNIConnectionHandler.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- JNIConnectionHandler.java	2000/08/27 20:37:30	1.15
  +++ JNIConnectionHandler.java	2000/08/28 06:08:17	1.16
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/JNIConnectionHandler.java,v
1.15 2000/08/27 20:37:30 costin Exp $
  - * $Revision: 1.15 $
  - * $Date: 2000/08/27 20:37:30 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/JNIConnectionHandler.java,v
1.16 2000/08/28 06:08:17 costin Exp $
  + * $Revision: 1.16 $
  + * $Date: 2000/08/28 06:08:17 $
    *
    * ====================================================================
    *
  @@ -300,7 +300,7 @@
               String []values = new String[nheaders];
               if(h.readHeaders(s, l, names, values) > 0) {
                   for(i = 0 ; i < nheaders ; i++) {
  -                    headers.putHeader(names[i].toLowerCase(), values[i]);
  +                    headers.addHeader(names[i].toLowerCase(), values[i]);
                   }
               } else {
                   throw new IOException("Error: JNI implementation error");
  @@ -366,9 +366,8 @@
           headerValues = new String[hcnt];
   
           for(int i = 0; i < hcnt; i++) {
  -            MimeHeaderField h = headers.getField(i);
  -            headerNames[i] = h.getName();
  -            headerValues[i] = h.getValue();
  +            headerNames[i] = headers.getName(i).toString();
  +            headerValues[i] = headers.getValue(i).toString();
           }
   
           if(h.startReasponse(s, l, status, RequestUtil.getMessage(status), headerNames,
headerValues, hcnt) <= 0) {
  
  
  
  1.27      +14 -10    jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java
  
  Index: HttpRequestAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- HttpRequestAdapter.java	2000/08/22 06:56:55	1.26
  +++ HttpRequestAdapter.java	2000/08/28 06:08:17	1.27
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java,v
1.26 2000/08/22 06:56:55 costin Exp $
  - * $Revision: 1.26 $
  - * $Date: 2000/08/22 06:56:55 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java,v
1.27 2000/08/28 06:08:17 costin Exp $
  + * $Revision: 1.27 $
  + * $Date: 2000/08/28 06:08:17 $
    *
    * ====================================================================
    *
  @@ -221,8 +221,7 @@
   	    
   	    // XXX this does not currently handle headers which
   	    // are folded to take more than one line.
  -	    MimeHeaderField mhf=headers.putHeader();
  -	    if( ! parseHeaderFiled(mhf, buf, start, off - start) ) {
  +	    if( ! parseHeaderFiled(headers, buf, start, off - start) ) {
   		// error parsing header
   		return;
   	    }
  @@ -236,7 +235,8 @@
        * @param len the length of the bytes
        * @exception IllegalArgumentException if the header format was invalid
        */
  -    public boolean parseHeaderFiled(MimeHeaderField mhf, byte[] b, int off, int len)
  +    public boolean parseHeaderFiled(MimeHeaders headers, byte[] b, int off,
  +				    int len)
       {
   	int start = off;
   	byte c;
  @@ -248,21 +248,25 @@
   	    }
   	}
   
  -	mhf.setName(b, start, off - start - 1);
  +	int nS=start;
  +	int nE=off - start - 1;
   
   	while (c == ' ') {
   	    c = b[off++];
   	}
   
   	if (c != ':') {
  -	    loghelper.log("Parse error, missing : in  " + new String( b, off, len ), Logger.ERROR);
  -	    loghelper.log("Full  " + new String( b, 0, b.length ), Logger.ERROR);
  +	    loghelper.log("Parse error, missing : in  " +
  +			  new String( b, off, len ), Logger.ERROR);
  +	    loghelper.log("Full  " + new String( b, 0, b.length ),
  +			  Logger.ERROR);
   	    return false;
   	}
   
   	while ((c = b[off++]) == ' ');
   
  -	mhf.setValue(b, off - 1, len - (off - start - 1));
  +	headers.addBytesHeader( b, nS, nE,
  +				off-1, len - (off - start - 1));
   	return true;
       }
   
  
  
  
  1.18      +7 -13     jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java
  
  Index: HttpResponseAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- HttpResponseAdapter.java	2000/08/27 20:37:31	1.17
  +++ HttpResponseAdapter.java	2000/08/28 06:08:18	1.18
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v
1.17 2000/08/27 20:37:31 costin Exp $
  - * $Revision: 1.17 $
  - * $Date: 2000/08/27 20:37:31 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v
1.18 2000/08/28 06:08:18 costin Exp $
  + * $Revision: 1.18 $
  + * $Date: 2000/08/28 06:08:18 $
    *
    * ====================================================================
    *
  @@ -112,13 +112,12 @@
   
   	int count=headers.size();
   	for( int i=0; i<count; i++ ) {
  -	    MimeHeaderField field=headers.getField( i );
   	    // response headers are set by the servlet, so probably we have only
   	    // Strings.
   	    // XXX date, cookies, etc shoud be extracted from response
  -	    printHead( field.getName() );
  +	    printHead( headers.getName( i ).toString() );
   	    printHead(": ");
  -	    printHead( field.getValue() );
  +	    printHead( headers.getValue( i ).toString() );
   	    printHead("\r\n");
   	}
   	
  @@ -154,13 +153,8 @@
   	// for any of those ( instead the server will generate the date )
   	// This avoids redundant setting of date ( very expensive ).
   	// XXX XXX Check if IIS, NES do generate the date
  -	MimeHeaderField dateH= headers.find( "Date" );
  -	if( false && dateH == null ) {
  -	    // no date header set by user
  -	    dateH=headers.putHeader();
  -	    dateH.setName("Date");
  -	    dateH.setDateValue(System.currentTimeMillis());
  -	    // will reuse the HttpDate instance
  +	if( false ) {
  +	    headers.setDateHeader(  "Date", System.currentTimeMillis());
   	}
   	
   	// Servlet Engine header will be set per/adapter - smarter adapters will
  
  
  
  1.6       +28 -3     jakarta-tomcat/src/share/org/apache/tomcat/util/DateTool.java
  
  Index: DateTool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/DateTool.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DateTool.java	2000/08/14 21:54:31	1.5
  +++ DateTool.java	2000/08/28 06:08:18	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/DateTool.java,v 1.5
2000/08/14 21:54:31 costin Exp $
  - * $Revision: 1.5 $
  - * $Date: 2000/08/14 21:54:31 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/DateTool.java,v 1.6
2000/08/28 06:08:18 costin Exp $
  + * $Revision: 1.6 $
  + * $Date: 2000/08/28 06:08:18 $
    *
    * ====================================================================
    *
  @@ -126,5 +126,30 @@
   	rfc1036Format.setTimeZone(GMT_ZONE);
   	asctimeFormat.setTimeZone(GMT_ZONE);
       }
  + 
  +    private static StringManager sm =
  +        StringManager.getManager("org.apache.tomcat.resources");
       
  +    public static long parseDate( MessageBytes value ) {
  +	String dateString=value.toString();
  +	Date date=null;
  +        try {
  +            date = DateTool.rfc1123Format.parse(dateString);
  +	    return date.getTime();
  +	} catch (ParseException e) { }
  +	
  +        try {
  +	    date = DateTool.rfc1036Format.parse(dateString);
  +	    return date.getTime();
  +	} catch (ParseException e) { }
  +	
  +        try {
  +            date = DateTool.asctimeFormat.parse(dateString);
  +	    return date.getTime();
  +        } catch (ParseException pe) {
  +        }
  +	String msg = sm.getString("httpDate.pe", dateString);
  +	throw new IllegalArgumentException(msg);
  +    }
  +
   }
  
  
  
  1.7       +109 -8    jakarta-tomcat/src/share/org/apache/tomcat/util/MessageBytes.java
  
  Index: MessageBytes.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/MessageBytes.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MessageBytes.java	2000/08/11 06:14:19	1.6
  +++ MessageBytes.java	2000/08/28 06:08:18	1.7
  @@ -80,6 +80,10 @@
       public static final int T_BYTES = 2;
       public static final int T_CHARS = 3;
   
  +    // support for efficient int and date parsing/formating
  +    public static final int T_INT = 4;
  +    public static final int T_DATE = 5;
  +
       private int hashCode=0;
       private boolean hasHashCode=false;
   
  @@ -103,6 +107,12 @@
       // String
       private String strValue;
       private boolean hasStrValue=false;
  +
  +    // efficient int and date
  +    private int intValue;
  +    private boolean hasIntValue=false;
  +    private Date dateValue;
  +    private boolean hasDateValue=false;
       
       /**
        * Creates a new, uninitialized MessageBytes object.
  @@ -139,6 +149,8 @@
   	hasStrValue=false;
   	hasCharValue=false;
   	hasHashCode=false;
  +	hasIntValue=false;
  +	hasDateValue=false;	
       }
   
   
  @@ -174,14 +186,29 @@
   	type=T_STR;
       }
   
  +    public void setTime(long t) {
  +	if( dateValue==null)
  +	    dateValue=new Date(t);
  +	else
  +	    dateValue.setTime(t);
  +	type = T_DATE;
  +	hasDateValue=true;
  +    }
  +
  +    public void setInt(int i) {
  +	intValue = i;
  +	type = T_INT;
  +	hasIntValue=true;
  +    }
  +
       // -------------------- Conversion and getters --------------------
       public String toString() {
   	if( hasStrValue ) return strValue;
  -	
  +	hasStrValue=true;
  +
   	switch (type) {
   	case T_CHARS:
   	    strValue=new String( chars, charsOff, charsLen);
  -	    hasStrValue=true;
   	    return strValue;
   	case T_BYTES:
   	    try {
  @@ -189,14 +216,18 @@
   		    strValue=toStringUTF8();
   		else
   		    strValue=new String(bytes, bytesOff, bytesLen, enc);
  -		hasStrValue=true;
   		return strValue;
   	    } catch (java.io.UnsupportedEncodingException e) {
   		return null;  // can't happen
   	    }
  -	default:
  -	    return null;
  +	case T_DATE:
  +	    strValue=DateTool.rfc1123Format.format(dateValue);
  +	    return strValue;
  +	case T_INT:
  +	    strValue=String.valueOf(intValue);
  +	    return strValue;
   	}
  +	return null;
       }
   
       private String toStringUTF8() {
  @@ -217,6 +248,39 @@
   	return new String( chars, 0, bytesLen);
       }
   
  +    public long getTime()
  +    {
  +	if( hasDateValue ) {
  +	    if( dateValue==null) return -1;
  +	    return dateValue.getTime();
  +	}
  +
  +	long l=DateTool.parseDate( this );
  +	if( dateValue==null)
  +	    dateValue=new Date(l);
  +	else
  +	    dateValue.setTime(l);
  +	hasDateValue=true;
  +	return l;
  +    }
  +
  +    public int getInt()
  +    {
  +	if( hasIntValue )
  +	    return intValue;
  +	
  +	switch (type) {
  +	case T_BYTES:
  +	    intValue=Ascii.parseInt(bytes, bytesOff,
  +				    bytesLen);
  +	    break;
  +	default:
  +	    intValue=Integer.parseInt(toString());
  +	}
  +	hasIntValue=true;
  +	return intValue;
  +    }
  +    
       //----------------------------------------
       public int getType() {
   	return type;
  @@ -250,7 +314,8 @@
   	    return charsLen;
   	if(type==T_STR)
   	    return strValue.length();
  -	return 0;
  +	toString();
  +	return strValue.length();
       }
   
       // -------------------- equals --------------------
  @@ -264,7 +329,12 @@
   	if( ! caseSensitive )
   	    return equalsIgnoreCase( s );
   	switch (type) {
  +	case T_INT:
  +	case T_DATE:
  +	    toString();
  +	    // now strValue is valid
   	case T_STR:
  +	    if( strValue==null && s!=null) return false;
   	    return strValue.equals( s );
   	case T_CHARS:
   	    char[] c = chars;
  @@ -304,7 +374,11 @@
        */
       public boolean equalsIgnoreCase(String s) {
   	switch (type) {
  +	case T_INT:
  +	case T_DATE:
  +	    toString(); // now strValue is set
   	case T_STR:
  +	    if( strValue==null && s!=null) return false;
   	    return strValue.equalsIgnoreCase( s );
   	case T_CHARS:
   	    char[] c = chars;
  @@ -339,15 +413,23 @@
   
       public boolean equals(MessageBytes mb) {
   	switch (type) {
  +	case T_INT:
  +	case T_DATE:
  +	    toString(); // now strValue is set
   	case T_STR:
   	    return mb.equals( strValue );
   	}
   
  -	if( mb.type != T_CHARS && mb.type!= T_BYTES ) {
  +	if( mb.type != T_CHARS &&
  +	    mb.type!= T_BYTES ) {
   	    // it's a string or int/date string value
   	    return equals( mb.toString() );
   	}
   
  +	// mb is either CHARS or BYTES.
  +	// this is either CHARS or BYTES
  +	// Deal with the 4 cases ( in fact 3, one is simetric)
  +	
   	if( mb.type == T_CHARS && type==T_CHARS ) {
   	    char b1[]=chars;
   	    char b2[]=mb.chars;
  @@ -442,6 +524,11 @@
   		}
   	    }
   	    return true;
  +	case T_INT:
  +	case T_DATE:
  +	    String s1=toString();
  +	    if( s1==null && s!=null) return false;
  +	    return s1.startsWith( s );
   	default:
   	    return false;
   	}
  @@ -467,6 +554,10 @@
       private int hash() {
   	int code=0;
   	switch (type) {
  +	case T_INT:
  +	case T_DATE:
  +	    String s1=toString();
  +	    // continue with T_STR - it now have a strValue
   	case T_STR:
   	    for (int i = 0; i < strValue.length(); i++) {
   		code = code * 37 + strValue.charAt( i );
  @@ -488,6 +579,10 @@
       private int hashIgnoreCase() {
   	int code=0;
   	switch (type) {
  +	case T_INT:
  +	case T_DATE:
  +	    String s1=toString();
  +	    // continue with T_STR - it now have a strValue
   	case T_STR:
   	    for (int i = 0; i < strValue.length(); i++) {
   		code = code * 37 + Ascii.toLower(strValue.charAt( i ));
  @@ -515,7 +610,9 @@
   	return code;
       }
   
  -    private static int hashBytesIC( byte bytes[], int bytesOff, int bytesLen ) {
  +    private static int hashBytesIC( byte bytes[], int bytesOff,
  +				    int bytesLen )
  +    {
   	int max=bytesOff+bytesLen;
   	byte bb[]=bytes;
   	int code=0;
  @@ -531,6 +628,10 @@
        */
       public int indexOf(char c) {
   	switch (type) {
  +	case T_INT:
  +	case T_DATE:
  +	    String s1=toString();
  +	    // continue with T_STR - it now have a strValue
   	case T_STR:
   	    return strValue.indexOf( c );
   	case T_CHARS:
  
  
  
  1.11      +94 -114   jakarta-tomcat/src/share/org/apache/tomcat/util/MimeHeaders.java
  
  Index: MimeHeaders.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/MimeHeaders.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- MimeHeaders.java	2000/08/11 21:20:55	1.10
  +++ MimeHeaders.java	2000/08/28 06:08:19	1.11
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/MimeHeaders.java,v
1.10 2000/08/11 21:20:55 costin Exp $
  - * $Revision: 1.10 $
  - * $Date: 2000/08/11 21:20:55 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/MimeHeaders.java,v
1.11 2000/08/28 06:08:19 costin Exp $
  + * $Revision: 1.11 $
  + * $Date: 2000/08/28 06:08:19 $
    *
    * ====================================================================
    *
  @@ -64,13 +64,9 @@
   
   package org.apache.tomcat.util;
   
  -import java.io.IOException;
  -import java.io.OutputStream;
  -import java.io.PrintStream;
  -import java.util.Enumeration;
  -import java.util.Hashtable;
  -import java.util.Vector;
  -import java.util.NoSuchElementException;
  +import java.io.*;
  +import java.util.*;
  +import java.text.*;
   
   /* XXX XXX XXX Need a major rewrite  !!!!
    */
  @@ -147,7 +143,7 @@
        */
       public void clear() {
   	for (int i = 0; i < count; i++) {
  -	    headers[i].reset();
  +	    headers[i].recycle();
   	}
   	count = 0;
       }
  @@ -160,22 +156,29 @@
       }
   
       /**
  -     * Returns the Nth header field, or null if there is no such header.
  +     * Returns the Nth header name, or null if there is no such header.
        * This may be used to iterate through all header fields.
        */
  -    public MimeHeaderField getField(int n) {
  -	return n >= 0 && n < count ? headers[n] : null;
  +    public MessageBytes getName(int n) {
  +	return n >= 0 && n < count ? headers[n].getName() : null;
       }
   
  -    
  +    /**
  +     * Returns the Nth header value, or null if there is no such header.
  +     * This may be used to iterate through all header fields.
  +     */
  +    public MessageBytes getValue(int n) {
  +	return n >= 0 && n < count ? headers[n].getValue() : null;
  +    }
  +
       /**
        * Finds and returns a header field with the given name.  If no such
        * field exists, null is returned.  If more than one such field is
        * in the header, an arbitrary one is returned.
        */
  -    public MimeHeaderField find(String name) {
  +    private MimeHeaderField find(String name) {
           for (int i = 0; i < count; i++) {
  -	    if (headers[i].nameEquals(name)) {
  +	    if (headers[i].getName().equalsIgnoreCase(name)) {
                   return headers[i];
               }
           }
  @@ -186,7 +189,7 @@
        * Adds a partially constructed field to the header.  This
        * field has not had its name or value initialized.
        */
  -    public MimeHeaderField putHeader() {
  +    private MimeHeaderField createHeader() {
   	MimeHeaderField mh;
   	int len = headers.length;
   	if (count >= len) {
  @@ -202,32 +205,7 @@
   	return mh;
       }
   
  -
  -    
  -    
  -    // -------------------- 
  -    // Please avoid using any of the methods following this line. 
  -    // ( most of them will generate GC, or are http sepecific )
  -    // ------------------------------------------------------------
  -    private static StringManager sm =
  -        StringManager.getManager("org.apache.tomcat.resources");
  -    int bufSize=512; // default
  -    /**
  -     * A buffer used when parsing headers.
  -     */
  -    private byte[] buf=null;
  -
  -    
       /**
  -     * Creates a new MimeHeaders object using the specified buffer size.
  -     * @param len the buffer size initially used for parsing headers
  -     */
  -    public MimeHeaders(int len) {
  -	bufSize=len;
  -	// buf = new byte[len];
  -    }
  -
  -    /**
        * Returns an enumeration of strings representing the header field names.
        * Field names may appear multiple times in this enumeration, indicating
        * that multiple fields with that name exist in this header.
  @@ -240,17 +218,28 @@
       // be renamed to put/get "field" !!!  This object is
       // the header, and its components are called fields.
   
  +    public void addBytesHeader(byte b[], int startN, int endN,
  +			       int startV, int endV)
  +    {
  +	MimeHeaderField mhf=createHeader();
  +	mhf.getName().setBytes(b, startN, endN);
  +	mhf.getValue().setBytes(b, startV, endV);
  +    }
  +    
       /**
        * Creates a new header field whose value is the specified string.
        * @param name the header name
        * @param s the header field string value
        */
  -    public void putHeader(String name, String s) {
  -	putHeader(name).setValue(s);
  +    public void setHeader(String name, String s) {
  +	MimeHeaderField headerF= find( name );
  +	if( headerF != null )
  +	    headerF=addHeader( name );
  +	headerF.getValue().setString(s);
       }
   
       public void addHeader(String name, String s) {
  -        addHeader(name).setValue(s);
  +        addHeader(name).getValue().setString(s);
       }
   
       /**
  @@ -258,12 +247,15 @@
        * @param name the header name
        * @param i the header field integer value
        */
  -    public void putIntHeader(String name, int i) {
  -	putHeader(name).setIntValue(i);
  +    public void setIntHeader(String name, int i) {
  +	MimeHeaderField headerF= find( name );
  +	if( headerF != null )
  +	    headerF=addHeader( name );
  +	headerF.getValue().setInt(i);
       }
   
       public void addIntHeader(String name, int i) {
  -        addHeader(name).setIntValue(i);
  +        addHeader(name).getValue().setInt(i);
       }
   
       /**
  @@ -272,12 +264,15 @@
        * @param name the header name
        * @param t the time in number of milliseconds since the epoch
        */
  -    public void putDateHeader(String name, long t) {
  -	putHeader(name).setDateValue(t);
  +    public void setDateHeader(String name, long t) {
  +	MimeHeaderField headerF= find( name );
  +	if( headerF != null )
  +	    headerF=addHeader( name );
  +	headerF.getValue().setTime(t);
       }
   
       public void addDateHeader(String name, long t) {
  -        addHeader(name).setDateValue(t);
  +        addHeader(name).getValue().setTime(t);
       }
   
       /**
  @@ -290,7 +285,7 @@
       public String getHeader(String name) {
   	MimeHeaderField mh = find(name);
   
  -	return mh != null ? mh.getValue() : null;
  +	return mh != null ? mh.getValue().toString() : null;
       }
   
       /**
  @@ -301,6 +296,7 @@
        * @return array values of the fields, or null if none found
        */
       public String[] getHeaders(String name) {
  +	// XXX XXX XXX XXX XXX XXX
   	Vector values = getHeadersVector(name);
   
   	if (values.size() > 0) {
  @@ -313,14 +309,15 @@
   	return null;
       }
   
  +    // XXX XXX XXX XXX XXX XXX 
       /** Same as getHeaders, return a Vector - avoid Vector-[]-Vector conversion
        */
       public Vector getHeadersVector(String name) {
   	Vector values = new Vector();
   
   	for (int i = 0; i < count; i++) {
  -	    if (headers[i].nameEquals(name))
  -		values.addElement(headers[i].getValue());
  +	    if (headers[i].getName().equalsIgnoreCase(name))
  +		values.addElement(headers[i].getValue().toString());
   	}
   
   	return values;
  @@ -337,7 +334,7 @@
       public int getIntHeader(String name) throws NumberFormatException {
   	MimeHeaderField mh = find(name);
   
  -	return mh != null ? mh.getIntValue() : -1;
  +	return mh != null ? mh.getValue().getInt() : -1;
       }
   
       /**
  @@ -350,7 +347,7 @@
       public long getDateHeader(String name) throws IllegalArgumentException {
   	MimeHeaderField mh = find(name);
   
  -	return mh != null ? mh.getDateValue() : -1;
  +	return mh != null ? mh.getValue().getTime() : -1;
       }
   
       /**
  @@ -359,7 +356,8 @@
        * through all the fields in the header.
        */
       public String getHeaderName(int n) {
  -	return n >= 0 && n < count ? headers[n].getName() : null;
  +	return n >= 0 && n < count ? headers[n].getName().toString()
  +	    : null;
       }
   
       /**
  @@ -368,7 +366,8 @@
        * with getHeaderName to iterate through all the fields in the header.
        */
       public String getHeader(int n) {
  -	return n >= 0 && n < count ? headers[n].getValue() : null;
  +	return n >= 0 && n < count ? headers[n].getValue().toString()
  +	    : null;
       }
   
       /**
  @@ -378,7 +377,7 @@
   	int retval = 0;
   
   	for (int i = 0; i < count; i++)
  -	    if (headers [i].nameEquals (name))
  +	    if (headers [i].getName().equalsIgnoreCase(name))
   		retval++;
   
   	return retval;
  @@ -394,11 +393,11 @@
           // warning: rather sticky code; heavily tuned
   
           for (int i = 0; i < count; i++) {
  -	    if (headers[i].nameEquals(name)) {
  +	    if (headers[i].getName().equalsIgnoreCase(name)) {
   	        // reset and swap with last header
   	        MimeHeaderField mh = headers[i];
   
  -		mh.reset();
  +		mh.recycle();
   		headers[i] = headers[count - 1];
   		headers[count - 1] = mh;
   
  @@ -418,50 +417,20 @@
       }
   
   
  -    /**
  -     * Finds a header field given name.  If the header doesn't exist,
  -     * it will create a new one.
  -     * @param name the header field name
  -     * @return the new field
  -     */
  -    protected MimeHeaderField putHeader(String name) {
  -        if (containsHeader(name)) {
  -	    removeHeader(name);
  -	}
  -
  -	return addHeader(name);
  -    }
  -
       protected MimeHeaderField addHeader(String name) {
  - 	MimeHeaderField mh = putHeader();
  + 	MimeHeaderField mh = createHeader();
   
  -	mh.setName(name);
  +	mh.getName().setString(name);
   
   	return mh;
       }
       
       /**
  -     * Creates a new header with given name, and add it to the headers.
  -     * @param name the header field name
  -     * @param s the header value
  -     * @return the new field
  -     */
  -    public void appendHeader(String name, String s) {
  -	MimeHeaderField mh = putHeader();
  -
  -	mh.setName(name);
  -	mh.setValue(s);
  -    }
  -    
  -    
  -    /**
        * Returns a lengthly string representation of the current header fields.
        */
       public String toString() {
   	StringBuffer sb = new StringBuffer();
  -
   	sb.append("{");
  -
   	for (int i = 0; i < count; i++) {
   	    sb.append("{");
   	    sb.append(headers[i].toString());
  @@ -471,26 +440,14 @@
   		sb.append(",");
   	    }
   	}
  -
   	sb.append("}");
   
   	return sb.toString();
       }
  -
  -    /**
  -     * Dumps current headers to specified PrintStream for debugging.
  -     */
  -
  -    public void dump(PrintStream out) {
  -	for (int i = 0; i < count; i++) {
  -	    out.println(headers[i]);
  -	}
  -    }
   }
   
  +// XXX XXX XXX XXX Must be rewritten !!!
   class MimeHeadersEnumerator implements Enumeration {
  -    private static StringManager sm =
  -        StringManager.getManager("org.apache.tomcat.resources");
       private Hashtable hash;
       private Enumeration delegate;
   
  @@ -510,13 +467,36 @@
       }
   
       public Object nextElement() {
  -        try {
  -            return delegate.nextElement();
  -        }
  -        catch (NoSuchElementException e) {
  -            String msg = sm.getString("mimeHeaderEnumerator.next.nse");
  -	    throw new NoSuchElementException(msg);
  -	}
  +	return delegate.nextElement();
       }
   }
   
  +class MimeHeaderField {
  +    // multiple headers with same name - a linked list will
  +    // speed up name enumerations and search ( both cpu and
  +    // GC)
  +    MimeHeaderField next; 
  +    
  +    protected final MessageBytes nameB = new MessageBytes();
  +    protected final MessageBytes valueB = new MessageBytes();
  +
  +    /**
  +     * Creates a new, uninitialized header field.
  +     */
  +    public MimeHeaderField() {
  +    }
  +
  +    public void recycle() {
  +	nameB.recycle();
  +	valueB.recycle();
  +	next=null;
  +    }
  +
  +    public MessageBytes getName() {
  +	return nameB;
  +    }
  +
  +    public MessageBytes getValue() {
  +	return valueB;
  +    }
  +}
  
  
  

Mime
View raw message