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:[EMAIL PROTECTED]">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;
       }
   
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to