Package 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
public abstract class AbstractMessageParser<T extends HttpMessage> extends java.lang.Object implements NHttpMessageParser<T>
AbstractNHttpMessageParserthat serves as a base for all message parser implementations.- Since:
- 4.0
-
-
Field Summary
Fields Modifier and Type Field Description private static intCOMPLETEDprivate MessageConstraintsconstraintsprivate booleanendOfStreamprivate java.util.List<CharArrayBuffer>headerBufsprivate CharArrayBufferlineBufprotected LineParserlineParserprivate Tmessageprivate static intREAD_HEAD_LINEprivate static intREAD_HEADERSprivate SessionInputBuffersessionBufferprivate intstate
-
Constructor Summary
Constructors Constructor Description AbstractMessageParser(SessionInputBuffer buffer, LineParser lineParser, MessageConstraints constraints)Creates an instance of AbstractMessageParser.AbstractMessageParser(SessionInputBuffer buffer, LineParser lineParser, HttpParams params)Deprecated.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract TcreateMessage(CharArrayBuffer buffer)CreatesHttpMessageinstance based on the content of the input buffer containing the first line of the incoming HTTP message.intfillBuffer(java.nio.channels.ReadableByteChannel channel)Fills the internal buffer of the parser with input data from the givenReadableByteChannel.Tparse()Attempts to parse a complete message head from the content of the internal buffer.private voidparseHeader()private voidparseHeadLine()voidreset()Resets the parser.
-
-
-
Field Detail
-
sessionBuffer
private final SessionInputBuffer sessionBuffer
-
READ_HEAD_LINE
private static final int READ_HEAD_LINE
- See Also:
- Constant Field Values
-
READ_HEADERS
private static final int READ_HEADERS
- See Also:
- Constant Field Values
-
COMPLETED
private static final int COMPLETED
- See Also:
- Constant Field Values
-
state
private int state
-
endOfStream
private boolean endOfStream
-
message
private T extends HttpMessage message
-
lineBuf
private CharArrayBuffer lineBuf
-
headerBufs
private final java.util.List<CharArrayBuffer> headerBufs
-
lineParser
protected final LineParser lineParser
-
constraints
private final MessageConstraints constraints
-
-
Constructor Detail
-
AbstractMessageParser
@Deprecated public AbstractMessageParser(SessionInputBuffer buffer, LineParser lineParser, HttpParams params)
Deprecated.Creates an instance of this class.- Parameters:
buffer- the session input buffer.lineParser- the line parser.params- HTTP parameters.
-
AbstractMessageParser
public AbstractMessageParser(SessionInputBuffer buffer, LineParser lineParser, MessageConstraints constraints)
Creates an instance of AbstractMessageParser.- Parameters:
buffer- the session input buffer.lineParser- the line parser. IfnullBasicLineParser.INSTANCEwill be used.constraints- Message constraints. IfnullMessageConstraints.DEFAULTwill be used.- Since:
- 4.3
-
-
Method Detail
-
reset
public void reset()
Description copied from interface:NHttpMessageParserResets the parser. The parser will be ready to start parsing another HTTP message.- Specified by:
resetin interfaceNHttpMessageParser<T extends HttpMessage>
-
fillBuffer
public int fillBuffer(java.nio.channels.ReadableByteChannel channel) throws java.io.IOExceptionDescription copied from interface:NHttpMessageParserFills the internal buffer of the parser with input data from the givenReadableByteChannel.- Specified by:
fillBufferin interfaceNHttpMessageParser<T extends HttpMessage>- Parameters:
channel- the input channel- Returns:
- number of bytes read.
- Throws:
java.io.IOException- in case of an I/O error.
-
createMessage
protected abstract T createMessage(CharArrayBuffer buffer) throws HttpException, ParseException
CreatesHttpMessageinstance 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 violationParseException- in case of a parse error.
-
parseHeadLine
private void parseHeadLine() throws HttpException, ParseException- Throws:
HttpExceptionParseException
-
parseHeader
private void parseHeader() throws java.io.IOException- Throws:
java.io.IOException
-
parse
public T parse() throws java.io.IOException, HttpException
Description copied from interface:NHttpMessageParserAttempts 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 returnnull.- Specified by:
parsein interfaceNHttpMessageParser<T extends HttpMessage>- Returns:
- HTTP message head, if available,
nullotherwise. - Throws:
java.io.IOException- in case of an I/O error.HttpException- in case the HTTP message is malformed or violates the HTTP protocol.
-
-