FileDocCategorySizeDatePackage
CoyoteReader.javaAPI DocApache Tomcat 6.0.145253Fri Jul 20 04:20:32 BST 2007org.apache.catalina.connector

CoyoteReader

public class CoyoteReader extends BufferedReader
Coyote implementation of the buffred reader.
author
Remy Maucherat

Fields Summary
private static final char[]
LINE_SEP
private static final int
MAX_LINE_LENGTH
protected InputBuffer
ib
protected char[]
lineBuffer
Constructors Summary
public CoyoteReader(InputBuffer ib)



    // ----------------------------------------------------------- Constructors


       
        super(ib, 1);
        this.ib = ib;
    
Methods Summary
voidclear()
Clear facade.

        ib = null;
    
protected java.lang.Objectclone()
Prevent cloning the facade.

        throw new CloneNotSupportedException();
    
public voidclose()

        ib.close();
    
public voidmark(int readAheadLimit)

        ib.mark(readAheadLimit);
    
public booleanmarkSupported()

        return true;
    
public intread()

        return ib.read();
    
public intread(char[] cbuf)

        return ib.read(cbuf, 0, cbuf.length);
    
public intread(char[] cbuf, int off, int len)

        return ib.read(cbuf, off, len);
    
public java.lang.StringreadLine()


        if (lineBuffer == null) {
            lineBuffer = new char[MAX_LINE_LENGTH];
       }

        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);
                pos = 0;
            } else {
                reset();
                skip(skip);
            }
        }

        if (aggregator == null) {
            result = new String(lineBuffer, 0, end);
        } else {
            aggregator.append(lineBuffer, 0, end);
            result = aggregator.toString();
        }

        return result;

    
public booleanready()

        return ib.ready();
    
public voidreset()

        ib.reset();
    
public longskip(long n)

        return ib.skip(n);