tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kaz...@ingrid.org (Kazuhiro Kazama)
Subject [PATCH] charset & line terminator (Re: My patches for Tomcat 3.2 wrt mutlibyte characters)
Date Mon, 11 Dec 2000 07:40:40 GMT
From: Costin Manolache <cmanolache@yahoo.com>
Subject: Re: My patches for Tomcat 3.2 wrt mutlibyte characters
Date: Wed, 6 Dec 2000 21:55:45 -0800 (PST)
Message-ID: <20001207055545.21360.qmail@web510.mail.yahoo.com>
> The least we can do is to detect if the encoding is 
> compatible with ASCII ( or UNICODE ) and use the
> getBytes() only if it isn't. The method has a big
> impact on all VMs - try it if you don't believe me.

If getBytes() is used only one time per one HTTP request, its overhead
may be acceptable.

PrintWriter class support a continuous conversion, but it has much
synchronization overhead, you know. In fact, I have tested a modified
ServletWriterFacade.java (reducing synchronization by method
overriding ... an adhoc approach), servlet output became much faster.

> This is a very delicate subject from the point of view
> of performance, and I spent a lot of time tunning
> tomcat -> I would like to review any patch on encoding
> before it is commited.

I fixed the following problems.

1, "8859_1" isn't right charset name in MIME.
2, HTTP charset is a case insensitive.
3, getBytes() != getBytes("iso-8859-1")
(In fact, getBytes() is getBytes(CharToByteConverter.getDefault()))
4, HTTP line terminator is CRLF.

Kazuhiro Kazama (kazama@ingrid.org)		NTT Network Innovation Laboratories

--- src/share/org/apache/tomcat/core/Constants.java.orig	Mon Dec 11 14:28:06 2000
+++ src/share/org/apache/tomcat/core/Constants.java	Mon Dec 11 14:31:06 2000
@@ -120,7 +120,7 @@
     public static final String HTML = "text/html";
 
     public static final String DEFAULT_CONTENT_TYPE = "text/plain";
-    public static final String DEFAULT_CHAR_ENCODING = "8859_1";
+    public static final String DEFAULT_CHAR_ENCODING = "ISO-8859-1";
 
 
     // deprecated
--- src/share/org/apache/tomcat/facade/ServletOutputStreamFacade.java.orig	Mon Dec 11 12:05:47
2000
+++ src/share/org/apache/tomcat/facade/ServletOutputStreamFacade.java	Mon Dec 11 14:23:09
2000
@@ -127,16 +127,16 @@
 	if( !gotEnc ) {
 	    enc = resA.getCharacterEncoding();
 	    gotEnc=true;
-	    if ( Constants.DEFAULT_CHAR_ENCODING.equals(enc) )
+	    if ( Constants.DEFAULT_CHAR_ENCODING.equalsIgnoreCase(enc) )
 		enc=null;
 	}
 	if( enc==null) 
-	    b=s.getBytes();
+	    b=s.getBytes(Constants.DEFAULT_CHAR_ENCODING);
 	else 
 	    try {
 		b=s.getBytes( enc );
 	    } catch (java.io.UnsupportedEncodingException ex) {
-		b=s.getBytes();
+		b=s.getBytes(Constants.DEFAULT_CHAR_ENCODING);
 		enc=null;
 	    } 
 	
--- src/share/org/apache/tomcat/facade/ServletWriterFacade.java.orig	Mon Dec 11 12:43:55 2000
+++ src/share/org/apache/tomcat/facade/ServletWriterFacade.java	Mon Dec 11 14:43:35 2000
@@ -103,6 +103,10 @@
 	if( ACCT ) out(); 
    }
 
+    public void println() {
+	super.print("\r\n");
+    }
+
     public void println( String str ) {
 	if( ACCT ) in();
 	super.println( str );

Mime
View raw message