FileDocCategorySizeDatePackage
DefaultResponseParser.javaAPI DocAndroid 1.5 API4185Wed May 06 22:41:10 BST 2009org.apache.http.impl.conn

DefaultResponseParser

public class DefaultResponseParser extends AbstractMessageParser

Fields Summary
private final HttpResponseFactory
responseFactory
private final CharArrayBuffer
lineBuf
private final int
maxGarbageLines
Constructors Summary
public DefaultResponseParser(SessionInputBuffer buffer, LineParser parser, HttpResponseFactory responseFactory, HttpParams params)

        super(buffer, parser, params);
        if (responseFactory == null) {
            throw new IllegalArgumentException
                ("Response factory may not be null");
        }
        this.responseFactory = responseFactory;
        this.lineBuf = new CharArrayBuffer(128);
        this.maxGarbageLines = params.getIntParameter(
            ConnConnectionPNames.MAX_STATUS_LINE_GARBAGE, Integer.MAX_VALUE);
    
Methods Summary
protected org.apache.http.HttpMessageparseHead(org.apache.http.io.SessionInputBuffer sessionBuffer)

        // clear the buffer
        this.lineBuf.clear();
        //read out the HTTP status string
        int count = 0;
        ParserCursor cursor = null;
        do {
            int i = sessionBuffer.readLine(this.lineBuf);
            if (i == -1 && count == 0) {
                // The server just dropped connection on us
                throw new NoHttpResponseException("The target server failed to respond");
            }
            cursor = new ParserCursor(0, this.lineBuf.length());
            if (lineParser.hasProtocolVersion(this.lineBuf, cursor)) {
                // Got one
                break;
            } else if (i == -1 || count >= this.maxGarbageLines) {
                // Giving up
                throw new ProtocolException("The server failed to respond with a " +
                        "valid HTTP response");
            }
            count++;
        } while(true);
        //create the status line from the status string
        StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor);
        return this.responseFactory.newHttpResponse(statusline, null);