null
{@link BasicLineParser#INSTANCE}
* will be used.
* @param constraints the message constraints. If null
* {@link MessageConstraints#DEFAULT} will be used.
*
* @since 4.3
*/
public AbstractMessageParser(
final SessionInputBuffer buffer,
final LineParser lineParser,
final MessageConstraints constraints) {
super();
this.sessionBuffer = Args.notNull(buffer, "Session input buffer");
this.lineParser = lineParser != null ? lineParser : BasicLineParser.INSTANCE;
this.messageConstraints = constraints != null ? constraints : MessageConstraints.DEFAULT;
this.headerLines = new ArrayListnull
, in which case
* the default implementation of this interface will be used.
*
* @throws IOException in case of an I/O error
* @throws HttpException in case of HTTP protocol violation
*/
public static Header[] parseHeaders(
final SessionInputBuffer inbuffer,
final int maxHeaderCount,
final int maxLineLen,
final LineParser parser) throws HttpException, IOException {
final List* 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 {@link HttpMessage}. * * @param sessionBuffer the session input buffer. * @return HTTP message based on the input from the session buffer. * @throws IOException in case of an I/O error. * @throws HttpException in case of HTTP protocol violation. * @throws ParseException in case of a parse error. */ protected abstract T parseHead(SessionInputBuffer sessionBuffer) throws IOException, HttpException, ParseException; public T parse() throws IOException, HttpException { final int st = this.state; switch (st) { case HEAD_LINE: try { this.message = parseHead(this.sessionBuffer); } catch (final ParseException px) { throw new ProtocolException(px.getMessage(), px); } this.state = HEADERS; //$FALL-THROUGH$ case HEADERS: final Header[] headers = AbstractMessageParser.parseHeaders( this.sessionBuffer, this.messageConstraints.getMaxHeaderCount(), this.messageConstraints.getMaxLineLength(), this.lineParser, this.headerLines); this.message.setHeaders(headers); final T result = this.message; this.message = null; this.headerLines.clear(); this.state = HEAD_LINE; return result; default: throw new IllegalStateException("Inconsistent parser state"); } } }