Java tutorial
package org.apache.http.impl.io; import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat; import java.io.IOException; import org.apache.http.HttpException; import org.apache.http.HttpResponse; import org.apache.http.HttpResponseFactory; import org.apache.http.NoHttpResponseException; import org.apache.http.ParseException; import org.apache.http.annotation.NotThreadSafe; import org.apache.http.config.MessageConstraints; import org.apache.http.impl.DefaultHttpResponseFactory; import org.apache.http.io.SessionInputBuffer; import org.apache.http.message.LineParser; import org.apache.http.message.ParserCursor; import org.apache.http.params.HttpParams; import org.apache.http.util.Args; import org.apache.http.util.CharArrayBuffer; @NotThreadSafe public class DefaultHttpResponseParser extends AbstractMessageParser<HttpResponse> { private final CharArrayBuffer lineBuf; private final HttpResponseFactory responseFactory; @Deprecated public DefaultHttpResponseParser(SessionInputBuffer sessionInputBuffer, LineParser lineParser, HttpResponseFactory httpResponseFactory, HttpParams httpParams) { super(sessionInputBuffer, lineParser, httpParams); this.responseFactory = (HttpResponseFactory) Args.notNull(httpResponseFactory, "Response factory"); this.lineBuf = new CharArrayBuffer(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } public DefaultHttpResponseParser(SessionInputBuffer sessionInputBuffer, LineParser lineParser, HttpResponseFactory httpResponseFactory, MessageConstraints messageConstraints) { super(sessionInputBuffer, lineParser, messageConstraints); if (httpResponseFactory == null) { httpResponseFactory = DefaultHttpResponseFactory.INSTANCE; } this.responseFactory = httpResponseFactory; this.lineBuf = new CharArrayBuffer(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } public DefaultHttpResponseParser(SessionInputBuffer sessionInputBuffer, MessageConstraints messageConstraints) { this(sessionInputBuffer, null, null, messageConstraints); } public DefaultHttpResponseParser(SessionInputBuffer sessionInputBuffer) { this(sessionInputBuffer, null, null, MessageConstraints.DEFAULT); } protected HttpResponse parseHead(SessionInputBuffer sessionInputBuffer) throws IOException, HttpException, ParseException { this.lineBuf.clear(); if (sessionInputBuffer.readLine(this.lineBuf) == -1) { throw new NoHttpResponseException("The target server failed to respond"); } return this.responseFactory.newHttpResponse( this.lineParser.parseStatusLine(this.lineBuf, new ParserCursor(0, this.lineBuf.length())), null); } }