You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2001/01/12 07:51:58 UTC
cvs commit: jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/connector/http SocketInputStream.java
remm 01/01/11 22:51:58
Modified: catalina/src/share/org/apache/catalina/connector/http
SocketInputStream.java
Log:
- Merge with some code inspired from code from BufferedInputStream.
- Removed some unnecessary synchronization (to be confirmed). If the
sync was necessary, I suggest doing it in the RequestInputStream.read()
instead.
Revision Changes Path
1.6 +107 -10 jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/connector/http/SocketInputStream.java
Index: SocketInputStream.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/connector/http/SocketInputStream.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SocketInputStream.java 2001/01/04 19:49:20 1.5
+++ SocketInputStream.java 2001/01/12 06:51:58 1.6
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/connector/http/SocketInputStream.java,v 1.5 2001/01/04 19:49:20 remm Exp $
- * $Revision: 1.5 $
- * $Date: 2001/01/04 19:49:20 $
+ * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/connector/http/SocketInputStream.java,v 1.6 2001/01/12 06:51:58 remm Exp $
+ * $Revision: 1.6 $
+ * $Date: 2001/01/12 06:51:58 $
*
* ====================================================================
*
@@ -65,18 +65,17 @@
package org.apache.catalina.connector.http;
import java.io.IOException;
-import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.EOFException;
import org.apache.catalina.util.StringManager;
/**
- * Extends BufferedInputStream to be more efficient reading lines during HTTP
+ * Extends InputStream to be more efficient reading lines during HTTP
* header processing.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
*/
-public class SocketInputStream extends BufferedInputStream {
+public class SocketInputStream extends InputStream {
// -------------------------------------------------------------- Constants
@@ -112,6 +111,30 @@
private static final int LC_OFFSET = 'A' - 'a';
+ /**
+ * Internal buffer.
+ */
+ protected byte buf[];
+
+
+ /**
+ * Last valid byte.
+ */
+ protected int count;
+
+
+ /**
+ * Position in the buffer.
+ */
+ protected int pos;
+
+
+ /**
+ * Underlying input stream.
+ */
+ protected InputStream is;
+
+
// ----------------------------------------------------------- Constructors
@@ -124,7 +147,8 @@
*/
public SocketInputStream(InputStream is, int bufferSize) {
- super(is, bufferSize);
+ this.is = is;
+ buf = new byte[bufferSize];
}
@@ -174,9 +198,7 @@
if (chr == -1)
throw new EOFException
(sm.getString("requestStream.readline.error"));
- if ((chr != CR) || (chr != LF)) {
- pos--;
- }
+ pos--;
// Reading the method name
@@ -484,6 +506,81 @@
header.valueEnd = readCount;
+ }
+
+
+ /**
+ * Read byte.
+ */
+ public int read()
+ throws IOException {
+ if (pos >= count) {
+ fill();
+ if (pos >= count)
+ return -1;
+ }
+ return buf[pos++] & 0xff;
+ }
+
+
+ /**
+ *
+ */
+ /*
+ public int read(byte b[], int off, int len)
+ throws IOException {
+
+ }
+ */
+
+
+ /**
+ *
+ */
+ /*
+ public long skip(long n)
+ throws IOException {
+
+ }
+ */
+
+
+ /**
+ * Returns the number of bytes that can be read from this input
+ * stream without blocking.
+ */
+ public int available()
+ throws IOException {
+ return (count - pos) + is.available();
+ }
+
+
+ /**
+ * Close the input stream.
+ */
+ public void close()
+ throws IOException {
+ if (is == null)
+ return;
+ is.close();
+ is = null;
+ buf = null;
+ }
+
+
+ // ------------------------------------------------------ Protected Methods
+
+
+ /**
+ * Fill the internal buffer using data from the undelying input stream.
+ */
+ protected void fill()
+ throws IOException {
+ pos = 0;
+ count = 0;
+ int nRead = is.read(buf, 0, buf.length);
+ if (nRead > 0)
+ count = nRead;
}
Re: cvs commit: jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/connector/http SocketInputStream.java
Posted by Remy Maucherat <re...@apache.org>.
> I think you should subclass FilterInputStream, because it will provide
> you default implementations for the read(xxx) methods by calling the
> read() method.
InputStream.read(b[], off, len) and skip(n), which are the two that I didn't
implement (yet) look good enough to me (they both will end up calling
read()).
Or am I again making asumptions on how the InputStream class behaves ?
Remy
Re: cvs commit: jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/connector/http SocketInputStream.java
Posted by Thomas Butter <th...@i.rule-the.net>.
remm@apache.org wrote:
> remm 01/01/11 22:51:58
>
> Modified: catalina/src/share/org/apache/catalina/connector/http
> SocketInputStream.java
> Log:
> - Merge with some code inspired from code from BufferedInputStream.
> - Removed some unnecessary synchronization (to be confirmed). If the
> sync was necessary, I suggest doing it in the RequestInputStream.read()
> instead.
>
>
> */
> -public class SocketInputStream extends BufferedInputStream {
> +public class SocketInputStream extends InputStream {
>
I think you should subclass FilterInputStream, because it will provide
you default implementations for the read(xxx) methods by calling the
read() method.
--
Thomas Butter <th...@i.rule-the.net> ICQ: 891617
"Unix IS user friendly, it is just selective about who his friends are."