Example usage for org.apache.http.message ParserCursor ParserCursor

List of usage examples for org.apache.http.message ParserCursor ParserCursor

Introduction

In this page you can find the example usage for org.apache.http.message ParserCursor ParserCursor.

Prototype

public ParserCursor(int i, int i2) 

Source Link

Usage

From source file:org.apache.http.impl.conn.DefaultHttpResponseParser.java

@Override
protected HttpResponse parseHead(final SessionInputBuffer sessionBuffer) throws IOException, HttpException {
    //read out the HTTP status string
    int count = 0;
    ParserCursor cursor = null;// w w w. ja v  a 2 s  . c o  m
    do {
        // clear the buffer
        this.lineBuf.clear();
        final 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 || reject(this.lineBuf, count)) {
            // Giving up
            throw new ProtocolException("The server failed to respond with a " + "valid HTTP response");
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Garbage in response: " + this.lineBuf.toString());
        }
        count++;
    } while (true);
    //create the status line from the status string
    final StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor);
    return this.responseFactory.newHttpResponse(statusline, null);
}

From source file:org.apache.http.impl.conn.DefaultResponseParser.java

@Override
protected HttpMessage parseHead(final SessionInputBuffer sessionBuffer) throws IOException, HttpException {
    //read out the HTTP status string
    int count = 0;
    ParserCursor cursor = null;/*from  w  w  w . j  a v a 2 s  .  com*/
    do {
        // clear the buffer
        this.lineBuf.clear();
        final 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");
        }
        if (this.log.isDebugEnabled()) {
            this.log.debug("Garbage in response: " + this.lineBuf.toString());
        }
        count++;
    } while (true);
    //create the status line from the status string
    final StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor);
    return this.responseFactory.newHttpResponse(statusline, null);
}