org.apache.http.message
Class BasicLineParserHC4

java.lang.Object
  extended by org.apache.http.message.BasicLineParserHC4
All Implemented Interfaces:
org.apache.http.message.LineParser

@Immutable
public class BasicLineParserHC4
extends java.lang.Object
implements org.apache.http.message.LineParser

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.

Since:
4.0

Field Summary
static BasicLineParserHC4 DEFAULT
          Deprecated. (4.3) use INSTANCE
static BasicLineParserHC4 INSTANCE
           
protected  org.apache.http.ProtocolVersion protocol
          A version of the protocol to parse.
 
Constructor Summary
BasicLineParserHC4()
          Creates a new line parser for HTTP.
BasicLineParserHC4(org.apache.http.ProtocolVersion proto)
          Creates a new line parser for the given HTTP-like protocol.
 
Method Summary
protected  org.apache.http.ProtocolVersion createProtocolVersion(int major, int minor)
          Creates a protocol version.
protected  org.apache.http.RequestLine createRequestLine(java.lang.String method, java.lang.String uri, org.apache.http.ProtocolVersion ver)
          Instantiates a new request line.
protected  org.apache.http.StatusLine createStatusLine(org.apache.http.ProtocolVersion ver, int status, java.lang.String reason)
          Instantiates a new status line.
 boolean hasProtocolVersion(org.apache.http.util.CharArrayBuffer buffer, org.apache.http.message.ParserCursor cursor)
           
 org.apache.http.Header parseHeader(org.apache.http.util.CharArrayBuffer buffer)
           
static org.apache.http.Header parseHeader(java.lang.String value, org.apache.http.message.LineParser parser)
           
 org.apache.http.ProtocolVersion parseProtocolVersion(org.apache.http.util.CharArrayBuffer buffer, org.apache.http.message.ParserCursor cursor)
           
static org.apache.http.ProtocolVersion parseProtocolVersion(java.lang.String value, org.apache.http.message.LineParser parser)
           
 org.apache.http.RequestLine parseRequestLine(org.apache.http.util.CharArrayBuffer buffer, org.apache.http.message.ParserCursor cursor)
          Parses a request line.
static org.apache.http.RequestLine parseRequestLine(java.lang.String value, org.apache.http.message.LineParser parser)
           
 org.apache.http.StatusLine parseStatusLine(org.apache.http.util.CharArrayBuffer buffer, org.apache.http.message.ParserCursor cursor)
           
static org.apache.http.StatusLine parseStatusLine(java.lang.String value, org.apache.http.message.LineParser parser)
           
protected  void skipWhitespace(org.apache.http.util.CharArrayBuffer buffer, org.apache.http.message.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

DEFAULT

@Deprecated
public static final BasicLineParserHC4 DEFAULT
Deprecated. (4.3) use INSTANCE
A default instance of this class, for use as default or fallback. Note that 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.


INSTANCE

public static final BasicLineParserHC4 INSTANCE

protocol

protected final org.apache.http.ProtocolVersion protocol
A version of the protocol to parse. The version is typically not relevant, but the protocol name.

Constructor Detail

BasicLineParserHC4

public BasicLineParserHC4(org.apache.http.ProtocolVersion proto)
Creates a new line parser for the given HTTP-like protocol.

Parameters:
proto - a version of the protocol to parse, or null for HTTP. The actual version is not relevant, only the protocol name.

BasicLineParserHC4

public BasicLineParserHC4()
Creates a new line parser for HTTP.

Method Detail

parseProtocolVersion

public static org.apache.http.ProtocolVersion parseProtocolVersion(java.lang.String value,
                                                                   org.apache.http.message.LineParser parser)
                                                            throws org.apache.http.ParseException
Throws:
org.apache.http.ParseException

parseProtocolVersion

public org.apache.http.ProtocolVersion parseProtocolVersion(org.apache.http.util.CharArrayBuffer buffer,
                                                            org.apache.http.message.ParserCursor cursor)
                                                     throws org.apache.http.ParseException
Specified by:
parseProtocolVersion in interface org.apache.http.message.LineParser
Throws:
org.apache.http.ParseException

createProtocolVersion

protected org.apache.http.ProtocolVersion createProtocolVersion(int major,
                                                                int minor)
Creates a protocol version. Called from parseProtocolVersion(java.lang.String, org.apache.http.message.LineParser).

Parameters:
major - the major version number, for example 1 in HTTP/1.0
minor - the minor version number, for example 0 in HTTP/1.0
Returns:
the protocol version

hasProtocolVersion

public boolean hasProtocolVersion(org.apache.http.util.CharArrayBuffer buffer,
                                  org.apache.http.message.ParserCursor cursor)
Specified by:
hasProtocolVersion in interface org.apache.http.message.LineParser

parseRequestLine

public static org.apache.http.RequestLine parseRequestLine(java.lang.String value,
                                                           org.apache.http.message.LineParser parser)
                                                    throws org.apache.http.ParseException
Throws:
org.apache.http.ParseException

parseRequestLine

public org.apache.http.RequestLine parseRequestLine(org.apache.http.util.CharArrayBuffer buffer,
                                                    org.apache.http.message.ParserCursor cursor)
                                             throws org.apache.http.ParseException
Parses a request line.

Specified by:
parseRequestLine in interface org.apache.http.message.LineParser
Parameters:
buffer - a buffer holding the line to parse
Returns:
the parsed request line
Throws:
org.apache.http.ParseException - in case of a parse error

createRequestLine

protected org.apache.http.RequestLine createRequestLine(java.lang.String method,
                                                        java.lang.String uri,
                                                        org.apache.http.ProtocolVersion ver)
Instantiates a new request line. Called from parseRequestLine(java.lang.String, org.apache.http.message.LineParser).

Parameters:
method - the request method
uri - the requested URI
ver - the protocol version
Returns:
a new status line with the given data

parseStatusLine

public static org.apache.http.StatusLine parseStatusLine(java.lang.String value,
                                                         org.apache.http.message.LineParser parser)
                                                  throws org.apache.http.ParseException
Throws:
org.apache.http.ParseException

parseStatusLine

public org.apache.http.StatusLine parseStatusLine(org.apache.http.util.CharArrayBuffer buffer,
                                                  org.apache.http.message.ParserCursor cursor)
                                           throws org.apache.http.ParseException
Specified by:
parseStatusLine in interface org.apache.http.message.LineParser
Throws:
org.apache.http.ParseException

createStatusLine

protected org.apache.http.StatusLine createStatusLine(org.apache.http.ProtocolVersion ver,
                                                      int status,
                                                      java.lang.String reason)
Instantiates a new status line. Called from parseStatusLine(java.lang.String, org.apache.http.message.LineParser).

Parameters:
ver - the protocol version
status - the status code
reason - the reason phrase
Returns:
a new status line with the given data

parseHeader

public static org.apache.http.Header parseHeader(java.lang.String value,
                                                 org.apache.http.message.LineParser parser)
                                          throws org.apache.http.ParseException
Throws:
org.apache.http.ParseException

parseHeader

public org.apache.http.Header parseHeader(org.apache.http.util.CharArrayBuffer buffer)
                                   throws org.apache.http.ParseException
Specified by:
parseHeader in interface org.apache.http.message.LineParser
Throws:
org.apache.http.ParseException

skipWhitespace

protected void skipWhitespace(org.apache.http.util.CharArrayBuffer buffer,
                              org.apache.http.message.ParserCursor cursor)
Helper to skip whitespace.