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 2003/01/05 18:19:36 UTC

cvs commit: jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5 CoyoteReader.java

remm        2003/01/05 09:19:36

  Modified:    coyote/src/java/org/apache/coyote/tomcat5 CoyoteReader.java
  Log:
  - Implement readLine (but the algorithm is ugly, and not tested with long lines).
  
  Revision  Changes    Path
  1.2       +66 -2     jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5/CoyoteReader.java
  
  Index: CoyoteReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5/CoyoteReader.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CoyoteReader.java	5 Jan 2003 11:24:22 -0000	1.1
  +++ CoyoteReader.java	5 Jan 2003 17:19:36 -0000	1.2
  @@ -77,6 +77,7 @@
   
   
       private static final char[] LINE_SEP = { '\r', '\n' };
  +    private static final int MAX_LINE_LENGTH = 4096;
   
   
       // ----------------------------------------------------- Instance Variables
  @@ -85,6 +86,9 @@
       protected InputBuffer ib;
   
   
  +    protected final char[] lineBuffer = new char[MAX_LINE_LENGTH];
  +
  +
       // ----------------------------------------------------------- Constructors
   
   
  @@ -152,8 +156,68 @@
   
       public String readLine()
           throws IOException {
  -        // FIXME
  -        return "";
  +
  +        String result = null;
  +
  +        int pos = 0;
  +        int end = -1;
  +        int skip = -1;
  +        StringBuffer aggregator = null;
  +        while (end < 0) {
  +            mark(MAX_LINE_LENGTH);
  +            while ((pos < MAX_LINE_LENGTH) && (end < 0)) {
  +                int nRead = read(lineBuffer, pos, MAX_LINE_LENGTH - pos);
  +                if (nRead < 0) {
  +                    if (pos == 0) {
  +                        return null;
  +                    }
  +                    end = pos;
  +                    skip = pos;
  +                }
  +                for (int i = pos; (i < (pos + nRead)) && (end < 0); i++) {
  +                    if (lineBuffer[i] == LINE_SEP[0]) {
  +                        end = i;
  +                        skip = i + 1;
  +                        char nextchar;
  +                        if (i == (pos + nRead - 1)) {
  +                            nextchar = (char) read();
  +                        } else {
  +                            nextchar = lineBuffer[i+1];
  +                        }
  +                        if (nextchar == LINE_SEP[1]) {
  +                            skip++;
  +                        }
  +                    } else if (lineBuffer[i] == LINE_SEP[1]) {
  +                        end = i;
  +                        skip = i + 1;
  +                    }
  +                }
  +                if (nRead > 0) {
  +                    pos += nRead;
  +                }
  +            }
  +            if (end < 0) {
  +                if (aggregator == null) {
  +                    aggregator = new StringBuffer();
  +                }
  +                aggregator.append(lineBuffer);
  +                reset();
  +                skip(MAX_LINE_LENGTH);
  +            } else {
  +                reset();
  +                skip(skip);
  +            }
  +        }
  +
  +        if (aggregator == null) {
  +            result = new String(lineBuffer, 0, end);
  +        } else {
  +            aggregator.append(lineBuffer, 0, end);
  +            result = aggregator.toString();
  +        }
  +
  +        return result;
  +
       }
   
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>