FileDocCategorySizeDatePackage
CoyoteReader.javaAPI DocGlassfish v2 API8451Fri May 04 22:32:42 BST 2007org.apache.coyote.tomcat5

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
private static final org.apache.catalina.util.StringManager
sm
The string manager for this package.
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()

        // Disallow operation if the object has gone out of scope
        if (ib == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }
        ib.close();
    
public voidmark(int readAheadLimit)

        // Disallow operation if the object has gone out of scope
        if (ib == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }
        ib.mark(readAheadLimit);
    
public booleanmarkSupported()

        // Disallow operation if the object has gone out of scope
        if (ib == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }
        return true;
    
public intread()

        // Disallow operation if the object has gone out of scope
        if (ib == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }
        return ib.read();
    
public intread(char[] cbuf)

        // Disallow operation if the object has gone out of scope
        if (ib == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }
        return ib.read(cbuf, 0, cbuf.length);
    
public intread(char[] cbuf, int off, int len)

        // Disallow operation if the object has gone out of scope
        if (ib == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }
        return ib.read(cbuf, off, len);
    
public java.lang.StringreadLine()


        // Disallow operation if the object has gone out of scope
        if (ib == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }

        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()

        // Disallow operation if the object has gone out of scope
        if (ib == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }
        return ib.ready();
    
public voidreset()

        // Disallow operation if the object has gone out of scope
        if (ib == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }
        ib.reset();
    
public longskip(long n)

        // Disallow operation if the object has gone out of scope
        if (ib == null) {
            throw new IllegalStateException(
                sm.getString("object.invalidScope"));
        }
        return ib.skip(n);