|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.http.message.BasicLineParser
@Contract(threading=IMMUTABLE) public class BasicLineParser
Basic parser for lines in the head section of an HTTP message. There are individual methods for parsing a request line, a status line, or a header line. The lines to parse are passed in memory, the parser does not depend on any specific IO mechanism. Instances of this class are stateless and thread-safe. Derived classes MUST maintain these properties.
Note: This class was created by refactoring parsing code located in various other classes. The author tags from those other classes have been replicated here, although the association with the parsing code taken from there has not been traced.
Field Summary | |
---|---|
static BasicLineParser |
DEFAULT
Deprecated. (4.3) use INSTANCE |
static BasicLineParser |
INSTANCE
|
protected ProtocolVersion |
protocol
A version of the protocol to parse. |
Constructor Summary | |
---|---|
BasicLineParser()
Creates a new line parser for HTTP. |
|
BasicLineParser(ProtocolVersion proto)
Creates a new line parser for the given HTTP-like protocol. |
Method Summary | |
---|---|
protected ProtocolVersion |
createProtocolVersion(int major,
int minor)
Creates a protocol version. |
protected RequestLine |
createRequestLine(String method,
String uri,
ProtocolVersion ver)
Instantiates a new request line. |
protected StatusLine |
createStatusLine(ProtocolVersion ver,
int status,
String reason)
Instantiates a new status line. |
boolean |
hasProtocolVersion(CharArrayBuffer buffer,
ParserCursor cursor)
Checks whether there likely is a protocol version in a line. |
Header |
parseHeader(CharArrayBuffer buffer)
Creates a header from a line. |
static Header |
parseHeader(String value,
LineParser parser)
|
ProtocolVersion |
parseProtocolVersion(CharArrayBuffer buffer,
ParserCursor cursor)
Parses the textual representation of a protocol version. |
static ProtocolVersion |
parseProtocolVersion(String value,
LineParser parser)
|
RequestLine |
parseRequestLine(CharArrayBuffer buffer,
ParserCursor cursor)
Parses a request line. |
static RequestLine |
parseRequestLine(String value,
LineParser parser)
|
StatusLine |
parseStatusLine(CharArrayBuffer buffer,
ParserCursor cursor)
Parses a status line. |
static StatusLine |
parseStatusLine(String value,
LineParser parser)
|
protected void |
skipWhitespace(CharArrayBuffer buffer,
ParserCursor cursor)
Helper to skip whitespace. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
@Deprecated public static final BasicLineParser DEFAULT
INSTANCE
BasicLineParser
is not a singleton, there can
be many instances of the class itself and of derived classes.
The instance here provides non-customized, default behavior.
public static final BasicLineParser INSTANCE
protected final ProtocolVersion protocol
Constructor Detail |
---|
public BasicLineParser(ProtocolVersion proto)
proto
- a version of the protocol to parse, or
null
for HTTP. The actual version
is not relevant, only the protocol name.public BasicLineParser()
Method Detail |
---|
public static ProtocolVersion parseProtocolVersion(String value, LineParser parser) throws ParseException
ParseException
public ProtocolVersion parseProtocolVersion(CharArrayBuffer buffer, ParserCursor cursor) throws ParseException
LineParser
parseProtocolVersion
in interface LineParser
buffer
- a buffer holding the protocol version to parsecursor
- the parser cursor containing the current position and
the bounds within the buffer for the parsing operation
ParseException
- in case of a parse errorprotected ProtocolVersion createProtocolVersion(int major, int minor)
parseProtocolVersion(java.lang.String, org.apache.http.message.LineParser)
.
major
- the major version number, for example 1 in HTTP/1.0minor
- the minor version number, for example 0 in HTTP/1.0
public boolean hasProtocolVersion(CharArrayBuffer buffer, ParserCursor cursor)
LineParser
LineParser.parseProtocolVersion(org.apache.http.util.CharArrayBuffer, org.apache.http.message.ParserCursor)
would not
detect a parse error.
This can be used to detect garbage lines before a request
or status line.
hasProtocolVersion
in interface LineParser
buffer
- a buffer holding the line to inspectcursor
- the cursor at which to check for a protocol version, or
negative for "end of line". Whether the check tolerates
whitespace before or after the protocol version is
implementation dependent.
true
if there is a protocol version at the
argument index (possibly ignoring whitespace),
false
otherwisepublic static RequestLine parseRequestLine(String value, LineParser parser) throws ParseException
ParseException
public RequestLine parseRequestLine(CharArrayBuffer buffer, ParserCursor cursor) throws ParseException
parseRequestLine
in interface LineParser
buffer
- a buffer holding the line to parsecursor
- the parser cursor containing the current position and
the bounds within the buffer for the parsing operation
ParseException
- in case of a parse errorprotected RequestLine createRequestLine(String method, String uri, ProtocolVersion ver)
parseRequestLine(java.lang.String, org.apache.http.message.LineParser)
.
method
- the request methoduri
- the requested URIver
- the protocol version
public static StatusLine parseStatusLine(String value, LineParser parser) throws ParseException
ParseException
public StatusLine parseStatusLine(CharArrayBuffer buffer, ParserCursor cursor) throws ParseException
LineParser
parseStatusLine
in interface LineParser
buffer
- a buffer holding the line to parsecursor
- the parser cursor containing the current position and
the bounds within the buffer for the parsing operation
ParseException
- in case of a parse errorprotected StatusLine createStatusLine(ProtocolVersion ver, int status, String reason)
parseStatusLine(java.lang.String, org.apache.http.message.LineParser)
.
ver
- the protocol versionstatus
- the status codereason
- the reason phrase
public static Header parseHeader(String value, LineParser parser) throws ParseException
ParseException
public Header parseHeader(CharArrayBuffer buffer) throws ParseException
LineParser
parseHeader
in interface LineParser
buffer
- a buffer holding the full header line.
This buffer MUST NOT be re-used afterwards, since
the returned object may reference the contents later.
ParseException
- in case of a parse errorprotected void skipWhitespace(CharArrayBuffer buffer, ParserCursor cursor)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |