## org.apache.http.impl.nio.codecs
Class AbstractMessageParser<T extends HttpMessage>

    java.lang.Object
      org.apache.http.impl.nio.codecs.AbstractMessageParser<T>

All Implemented Interfaces:
  NHttpMessageParser<T>

Direct Known Subclasses:
  DefaultHttpRequestParser, DefaultHttpResponseParser, HttpRequestParser, HttpResponseParser

    @NotThreadSafe
    public abstract class AbstractMessageParser<T extends HttpMessage>

extends Object
implements NHttpMessageParser<T>

Abstract `NHttpMessageParser` that serves as a base for all message parser implementations.

The following parameters can be used to customize the behavior of this class:

- `CoreConnectionPNames.MAX_HEADER_COUNT`
- `CoreConnectionPNames.MAX_LINE_LENGTH`

Since:
  4.0

Field Summary
`protected LineParser` `lineParser`

Constructor Summary
`AbstractMessageParser(SessionInputBuffer buffer, LineParser parser, HttpParams params)` Creates an instance of this class.

Method Summary
`protected abstract T` `createMessage(CharArrayBuffer buffer)` Creates `HttpMessage` instance based on the content of the input buffer containing the first line of the incoming HTTP message.
`int` `fillBuffer(ReadableByteChannel channel)` Fills the internal buffer of the parser with input data from the given `ReadableByteChannel`.
`T` `parse()` Attempts to parse a complete message head from the content of the internal buffer.
`void` `reset()` Resets the parser.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### lineParser

    protected final LineParser lineParser

Constructor Detail

### AbstractMessageParser

    public AbstractMessageParser(SessionInputBuffer buffer,
                                 LineParser parser,
                                 HttpParams params)

  Creates an instance of this class.

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

Method Detail

### reset

    public void reset()

  Description copied from interface: `NHttpMessageParser`
  Resets the parser. The parser will be ready to start parsing another HTTP message.

  Specified by:
    `reset` in interface `NHttpMessageParser<T extends HttpMessage>`

### fillBuffer

    public int fillBuffer(ReadableByteChannel channel)
                   throws IOException

  Description copied from interface: `NHttpMessageParser`
  Fills the internal buffer of the parser with input data from the given `ReadableByteChannel`.

  Specified by:
    `fillBuffer` in interface `NHttpMessageParser<T extends HttpMessage>`
  Parameters:
    `channel` - the input channel
  Returns:
    number of bytes read.
  Throws:
    `IOException` - in case of an I/O error.

### createMessage

    protected abstract T createMessage(CharArrayBuffer buffer)
                                                    throws HttpException,
                                                           ParseException

  Creates `HttpMessage` instance based on the content of the input buffer containing the first line of the incoming HTTP message.

  Parameters:
    `buffer` - the line buffer.
  Returns:
    HTTP message.
  Throws:
    `HttpException` - in case of HTTP protocol violation
    `ParseException` - in case of a parse error.

### parse

    public T parse()
                                throws IOException,
                                       HttpException

  Description copied from interface: `NHttpMessageParser`
  Attempts to parse a complete message head from the content of the internal buffer. If the message in the input buffer is incomplete this method will return `null`.

  Specified by:
    `parse` in interface `NHttpMessageParser<T extends HttpMessage>`
  Returns:
    HTTP message head, if available, `null` otherwise.
  Throws:
    `IOException` - in case of an I/O error.
    `HttpException` - in case the HTTP message is malformed or violates the HTTP protocol.

Copyright © 2005-2013 The Apache Software Foundation. All Rights Reserved.