remm 2004/11/12 02:51:49
Modified: util/java/org/apache/tomcat/util/buf MessageBytes.java
CharChunk.java ByteChunk.java
http11/src/java/org/apache/coyote/http11
InternalOutputBuffer.java Constants.java
Log:
- Move convertToBytes to ByteChunk.
- Some small optimizations.
- The recycle method of MB was called far too often (ex: when calling
setChars). This needs some testing.
Revision Changes Path
1.20 +35 -14
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/MessageBytes.java
Index: MessageBytes.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/MessageBytes.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- MessageBytes.java 29 Aug 2004 17:14:41 -0000 1.19
+++ MessageBytes.java 12 Nov 2004 10:51:49 -0000 1.20
@@ -121,14 +121,18 @@
/**
* Sets the content to the specified subarray of bytes.
*
- * @param b the ascii bytes
+ * @param b the bytes
* @param off the start offset of the bytes
* @param len the length of the bytes
*/
public void setBytes(byte[] b, int off, int len) {
- recycle(); // a new value is set, cached values must reset
- byteC.setBytes( b, off, len );
- type=T_BYTES;
+ byteC.setBytes( b, off, len );
+ type=T_BYTES;
+ hasStrValue=false;
+ hasHashCode=false;
+ hasIntValue=false;
+ hasLongValue=false;
+ hasDateValue=false;
}
/** Set the encoding. If the object was constructed from bytes[]. any
@@ -144,12 +148,21 @@
byteC.setEncoding(enc);
}
- /** Sets the content to be a char[]
+ /**
+ * Sets the content to be a char[]
+ *
+ * @param c the bytes
+ * @param off the start offset of the bytes
+ * @param len the length of the bytes
*/
public void setChars( char[] c, int off, int len ) {
- recycle();
- charC.setChars( c, off, len );
- type=T_CHARS;
+ charC.setChars( c, off, len );
+ type=T_CHARS;
+ hasStrValue=false;
+ hasHashCode=false;
+ hasIntValue=false;
+ hasLongValue=false;
+ hasDateValue=false;
}
/** Remove the cached string value. Use it after a conversion on the
@@ -165,15 +178,19 @@
}
}
- /** Set the content to be a string
+ /**
+ * Set the content to be a string
*/
public void setString( String s ) {
- recycle();
if (s == null)
return;
- strValue=s;
- hasStrValue=true;
- type=T_STR;
+ strValue=s;
+ hasStrValue=true;
+ hasHashCode=false;
+ hasIntValue=false;
+ hasLongValue=false;
+ hasDateValue=false;
+ type=T_STR;
}
// -------------------- Conversion and getters --------------------
@@ -553,7 +570,6 @@
/** Set the buffer to the representation of an int
*/
public void setInt(int i) {
- recycle();
byteC.allocate(16, 32);
int current = i;
byte[] buf = byteC.getBuffer();
@@ -571,6 +587,7 @@
current = current / 10;
buf[end++] = HexUtils.HEX[digit];
}
+ byteC.setOffset(0);
byteC.setEnd(end);
// Inverting buffer
end--;
@@ -585,7 +602,11 @@
end--;
}
intValue=i;
+ hasStrValue=false;
+ hasHashCode=false;
hasIntValue=true;
+ hasLongValue=false;
+ hasDateValue=false;
type=T_BYTES;
}
1.18 +5 -7
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/CharChunk.java
Index: CharChunk.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/CharChunk.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- CharChunk.java 18 Oct 2004 23:19:36 -0000 1.17
+++ CharChunk.java 12 Nov 2004 10:51:49 -0000 1.18
@@ -133,12 +133,10 @@
}
public void setChars( char[] c, int off, int len ) {
- recycle();
- isSet=true;
- buff=c;
- start=off;
- end=start + len;
- limit=end;
+ buff=c;
+ start=off;
+ end=start + len;
+ isSet=true;
}
/** Maximum amount of data in this buffer.
@@ -192,7 +190,7 @@
}
public int getOffset() {
- return getStart();
+ return start;
}
/**
1.23 +19 -5
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/ByteChunk.java
Index: ByteChunk.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/buf/ByteChunk.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- ByteChunk.java 18 Oct 2004 23:16:36 -0000 1.22
+++ ByteChunk.java 12 Nov 2004 10:51:49 -0000 1.23
@@ -153,10 +153,10 @@
* @param len the length of the bytes
*/
public void setBytes(byte[] b, int off, int len) {
- buff = b;
- start = off;
- end = start+ len;
- isSet=true;
+ buff = b;
+ start = off;
+ end = start+ len;
+ isSet=true;
}
public void setOptimizedWrite(boolean optimizedWrite) {
@@ -195,7 +195,7 @@
}
public int getOffset() {
- return getStart();
+ return start;
}
public void setOffset(int off) {
@@ -776,5 +776,19 @@
}
+ /**
+ * Convert specified String to a byte array.
+ *
+ * @param value to convert to byte array
+ * @return the byte array value
+ */
+ public static final byte[] convertToBytes(String value) {
+ byte[] result = new byte[value.length()];
+ for (int i = 0; i < value.length(); i++) {
+ result[i] = (byte) value.charAt(i);
+ }
+ return result;
+ }
+
}
1.25 +41 -47
jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java
Index: InternalOutputBuffer.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalOutputBuffer.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- InternalOutputBuffer.java 1 Oct 2004 23:36:15 -0000 1.24
+++ InternalOutputBuffer.java 12 Nov 2004 10:51:49 -0000 1.25
@@ -426,25 +426,26 @@
public void sendStatus() {
// Write protocol name
- write("HTTP/1.1 ");
+ write(Constants.HTTP_11_BYTES);
+ buf[pos++] = Constants.SP;
// Write status code
int status = response.getStatus();
- switch (status) {
- case 200:
- write("200");
- break;
- case 400:
- write("400");
- break;
- case 404:
- write("404");
- break;
+ switch (status) {
+ case 200:
+ write(Constants._200_BYTES);
+ break;
+ case 400:
+ write(Constants._400_BYTES);
+ break;
+ case 404:
+ write(Constants._404_BYTES);
+ break;
default:
- write(status);
- }
+ write(status);
+ }
- write(" ");
+ buf[pos++] = Constants.SP;
// Write message
String message = response.getMessage();
@@ -459,13 +460,15 @@
AccessController.doPrivileged(
new PrivilegedAction(){
public Object run(){
- write(Constants.CRLF_BYTES);
+ buf[pos++] = Constants.CR;
+ buf[pos++] = Constants.LF;
return null;
}
}
);
} else {
- write(Constants.CRLF_BYTES);
+ buf[pos++] = Constants.CR;
+ buf[pos++] = Constants.LF;
}
}
@@ -493,9 +496,11 @@
public void sendHeader(MessageBytes name, MessageBytes value) {
write(name);
- write(": ");
+ buf[pos++] = Constants.COLON;
+ buf[pos++] = Constants.SP;
write(value);
- write(Constants.CRLF_BYTES);
+ buf[pos++] = Constants.CR;
+ buf[pos++] = Constants.LF;
}
@@ -509,9 +514,11 @@
public void sendHeader(ByteChunk name, ByteChunk value) {
write(name);
- write(": ");
+ buf[pos++] = Constants.COLON;
+ buf[pos++] = Constants.SP;
write(value);
- write(Constants.CRLF_BYTES);
+ buf[pos++] = Constants.CR;
+ buf[pos++] = Constants.LF;
}
@@ -525,9 +532,11 @@
public void sendHeader(String name, String value) {
write(name);
- write(": ");
+ buf[pos++] = Constants.COLON;
+ buf[pos++] = Constants.SP;
write(value);
- write(Constants.CRLF_BYTES);
+ buf[pos++] = Constants.CR;
+ buf[pos++] = Constants.LF;
}
@@ -537,7 +546,8 @@
*/
public void endHeaders() {
- write(Constants.CRLF_BYTES);
+ buf[pos++] = Constants.CR;
+ buf[pos++] = Constants.LF;
}
@@ -656,18 +666,10 @@
// but is the only consistent approach within the current
// servlet framework. It must suffice until servlet output
// streams properly encode their output.
- if ((c & 0xff00) != 0) {
- // High order byte must be zero
- //log("Header character is not iso8859_1, " +
- //"not supported yet: " + c, Log.ERROR ) ;
- }
- if (c != 9) {
- if ((c >= 0) && (c <= 31)) {
- c = ' ';
- }
- if (c == 127) {
- c = ' ';
- }
+ if ((c <= 31) && (c != 9)) {
+ c = ' ';
+ } else if (c == 127) {
+ c = ' ';
}
buf[pos++] = (byte) c;
}
@@ -711,18 +713,10 @@
// but is the only consistent approach within the current
// servlet framework. It must suffice until servlet output
// streams properly encode their output.
- if ((c & 0xff00) != 0) {
- // High order byte must be zero
- //log("Header character is not iso8859_1, " +
- //"not supported yet: " + c, Log.ERROR ) ;
- }
- if (c != 9) {
- if ((c >= 0) && (c <= 31)) {
- c = ' ';
- }
- if (c == 127) {
- c = ' ';
- }
+ if ((c <= 31) && (c != 9)) {
+ c = ' ';
+ } else if (c == 127) {
+ c = ' ';
}
buf[pos++] = (byte) c;
}
1.25 +20 -20
jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Constants.java
Index: Constants.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Constants.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- Constants.java 1 Oct 2004 23:36:15 -0000 1.24
+++ Constants.java 12 Nov 2004 10:51:49 -0000 1.25
@@ -16,6 +16,8 @@
package org.apache.coyote.http11;
+import org.apache.tomcat.util.buf.ByteChunk;
+
/**
* Constants.
@@ -49,7 +51,8 @@
/**
* Server string.
*/
- public static final byte[] SERVER_BYTES = convertToBytes("Server:
Apache-Coyote/1.1" + CRLF);
+ public static final byte[] SERVER_BYTES =
+ ByteChunk.convertToBytes("Server: Apache-Coyote/1.1" + CRLF);
/**
@@ -119,16 +122,25 @@
/* Various constant "strings" */
- public static final byte[] CRLF_BYTES = convertToBytes(CRLF);
- public static final byte[] COLON_BYTES = convertToBytes(": ");
+ public static final byte[] CRLF_BYTES = ByteChunk.convertToBytes(CRLF);
+ public static final byte[] COLON_BYTES = ByteChunk.convertToBytes(": ");
public static final String CONNECTION = "Connection";
public static final String CLOSE = "close";
- public static final byte[] CLOSE_BYTES = convertToBytes("close");
+ public static final byte[] CLOSE_BYTES =
+ ByteChunk.convertToBytes(CLOSE);
public static final String KEEPALIVE = "keep-alive";
- public static final byte[] KEEPALIVE_BYTES =
convertToBytes("keep-alive");
+ public static final byte[] KEEPALIVE_BYTES =
+ ByteChunk.convertToBytes(KEEPALIVE);
public static final String CHUNKED = "chunked";
- public static final byte[] ACK_BYTES = convertToBytes("HTTP/1.1 100
Continue" + CRLF + CRLF);
+ public static final byte[] ACK_BYTES =
+ ByteChunk.convertToBytes("HTTP/1.1 100 Continue" + CRLF + CRLF);
public static final String TRANSFERENCODING = "Transfer-Encoding";
+ public static final byte[] _200_BYTES =
+ ByteChunk.convertToBytes("200");
+ public static final byte[] _400_BYTES =
+ ByteChunk.convertToBytes("400");
+ public static final byte[] _404_BYTES =
+ ByteChunk.convertToBytes("404");
/**
@@ -171,6 +183,8 @@
* HTTP/1.1.
*/
public static final String HTTP_11 = "HTTP/1.1";
+ public static final byte[] HTTP_11_BYTES =
+ ByteChunk.convertToBytes(HTTP_11);
/**
@@ -191,18 +205,4 @@
public static final String POST = "POST";
- /**
- * Utility method.
- *
- * @param value to convert to byte array
- * @return the byte array value
- */
- public static final byte[] convertToBytes(String value) {
- byte[] result = new byte[value.length()];
- for (int i = 0; i < value.length(); i++) {
- result[i] = (byte) value.charAt(i);
- }
- return result;
- }
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]