org.apache.http.impl.io
Class AbstractMessageParserHC4<T extends org.apache.http.HttpMessage>

java.lang.Object
  extended by org.apache.http.impl.io.AbstractMessageParserHC4<T>
All Implemented Interfaces:
org.apache.http.io.HttpMessageParser
Direct Known Subclasses:
DefaultHttpRequestParser, DefaultHttpResponseParser, DefaultHttpResponseParser

@NotThreadSafe
public abstract class AbstractMessageParserHC4<T extends org.apache.http.HttpMessage>
extends java.lang.Object
implements org.apache.http.io.HttpMessageParser

Abstract base class for HTTP message parsers that obtain input from an instance of SessionInputBuffer.

Since:
4.0

Field Summary
protected  org.apache.http.message.LineParser lineParser
           
 
Constructor Summary
AbstractMessageParserHC4(org.apache.http.io.SessionInputBuffer buffer, org.apache.http.message.LineParser parser, org.apache.http.params.HttpParams params)
          Deprecated. (4.3) use AbstractMessageParserHC4(SessionInputBuffer, LineParser, MessageConstraints)
AbstractMessageParserHC4(org.apache.http.io.SessionInputBuffer buffer, org.apache.http.message.LineParser lineParser, MessageConstraints constraints)
          Creates new instance of AbstractMessageParserHC4.
 
Method Summary
 T parse()
           
protected abstract  T parseHead(org.apache.http.io.SessionInputBuffer sessionBuffer)
          Subclasses must override this method to generate an instance of HttpMessage based on the initial input from the session buffer.
static org.apache.http.Header[] parseHeaders(org.apache.http.io.SessionInputBuffer inbuffer, int maxHeaderCount, int maxLineLen, org.apache.http.message.LineParser parser)
          Parses HTTP headers from the data receiver stream according to the generic format as given in Section 3.1 of RFC 822, RFC-2616 Section 4 and 19.3.
static org.apache.http.Header[] parseHeaders(org.apache.http.io.SessionInputBuffer inbuffer, int maxHeaderCount, int maxLineLen, org.apache.http.message.LineParser parser, java.util.List<org.apache.http.util.CharArrayBuffer> headerLines)
          Parses HTTP headers from the data receiver stream according to the generic format as given in Section 3.1 of RFC 822, RFC-2616 Section 4 and 19.3.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lineParser

protected final org.apache.http.message.LineParser lineParser
Constructor Detail

AbstractMessageParserHC4

@Deprecated
public AbstractMessageParserHC4(org.apache.http.io.SessionInputBuffer buffer,
                                           org.apache.http.message.LineParser parser,
                                           org.apache.http.params.HttpParams params)
Deprecated. (4.3) use AbstractMessageParserHC4(SessionInputBuffer, LineParser, MessageConstraints)

Creates an instance of AbstractMessageParserHC4.

Parameters:
buffer - the session input buffer.
parser - the line parser.
params - HTTP parameters.

AbstractMessageParserHC4

public AbstractMessageParserHC4(org.apache.http.io.SessionInputBuffer buffer,
                                org.apache.http.message.LineParser lineParser,
                                MessageConstraints constraints)
Creates new instance of AbstractMessageParserHC4.

Parameters:
buffer - the session input buffer.
lineParser - the line parser. If null BasicLineParserHC4.INSTANCE will be used.
constraints - the message constraints. If null MessageConstraints.DEFAULT will be used.
Since:
4.3
Method Detail

parseHeaders

public static org.apache.http.Header[] parseHeaders(org.apache.http.io.SessionInputBuffer inbuffer,
                                                    int maxHeaderCount,
                                                    int maxLineLen,
                                                    org.apache.http.message.LineParser parser)
                                             throws org.apache.http.HttpException,
                                                    java.io.IOException
Parses HTTP headers from the data receiver stream according to the generic format as given in Section 3.1 of RFC 822, RFC-2616 Section 4 and 19.3.

Parameters:
inbuffer - Session input buffer
maxHeaderCount - maximum number of headers allowed. If the number of headers received from the data stream exceeds maxCount value, an IOException will be thrown. Setting this parameter to a negative value or zero will disable the check.
maxLineLen - maximum number of characters for a header line, including the continuation lines. Setting this parameter to a negative value or zero will disable the check.
parser - line parser to use. Can be null, in which case the default implementation of this interface will be used.
Returns:
array of HTTP headers
Throws:
java.io.IOException - in case of an I/O error
org.apache.http.HttpException - in case of HTTP protocol violation

parseHeaders

public static org.apache.http.Header[] parseHeaders(org.apache.http.io.SessionInputBuffer inbuffer,
                                                    int maxHeaderCount,
                                                    int maxLineLen,
                                                    org.apache.http.message.LineParser parser,
                                                    java.util.List<org.apache.http.util.CharArrayBuffer> headerLines)
                                             throws org.apache.http.HttpException,
                                                    java.io.IOException
Parses HTTP headers from the data receiver stream according to the generic format as given in Section 3.1 of RFC 822, RFC-2616 Section 4 and 19.3.

Parameters:
inbuffer - Session input buffer
maxHeaderCount - maximum number of headers allowed. If the number of headers received from the data stream exceeds maxCount value, an IOException will be thrown. Setting this parameter to a negative value or zero will disable the check.
maxLineLen - maximum number of characters for a header line, including the continuation lines. Setting this parameter to a negative value or zero will disable the check.
parser - line parser to use.
headerLines - List of header lines. This list will be used to store intermediate results. This makes it possible to resume parsing of headers in case of a InterruptedIOException.
Returns:
array of HTTP headers
Throws:
java.io.IOException - in case of an I/O error
org.apache.http.HttpException - in case of HTTP protocol violation
Since:
4.1

parseHead

protected abstract T parseHead(org.apache.http.io.SessionInputBuffer sessionBuffer)
                                                            throws java.io.IOException,
                                                                   org.apache.http.HttpException,
                                                                   org.apache.http.ParseException
Subclasses must override this method to generate an instance of HttpMessage based on the initial input from the session buffer.

Usually this method is expected to read just the very first line or the very first valid from the data stream and based on the input generate an appropriate instance of HttpMessage.

Parameters:
sessionBuffer - the session input buffer.
Returns:
HTTP message based on the input from the session buffer.
Throws:
java.io.IOException - in case of an I/O error.
org.apache.http.HttpException - in case of HTTP protocol violation.
org.apache.http.ParseException - in case of a parse error.

parse

public T parse()
                                            throws java.io.IOException,
                                                   org.apache.http.HttpException
Specified by:
parse in interface org.apache.http.io.HttpMessageParser
Throws:
java.io.IOException
org.apache.http.HttpException