• BlackBerry Dynamics
  • Runtime library for Android applications
  • 12.0.1.79
BasicLineParser Class Reference

Basic parser for lines in the head section of an HTTP message. More...

Inheritance diagram for BasicLineParser:
LineParser

Description

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.

Author
Jeff Dever
Mike Bowler
Oleg Kalnichevski
and others

Notice

The following notice applies to the original API on which this API is based, and to its documentation. The documentation of this API has been revised from the original.

/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Public Member Functions

 BasicLineParser (ProtocolVersion proto)
 Creates a new line parser for the given HTTP-like protocol. More...
 
 BasicLineParser ()
 Creates a new line parser for HTTP.
 
ProtocolVersion parseProtocolVersion (final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException
 non-javadoc, see interface LineParser
 
boolean hasProtocolVersion (final CharArrayBuffer buffer, final ParserCursor cursor)
 Checks whether there likely is a protocol version in a line. More...
 
RequestLine parseRequestLine (final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException
 Parses a request line. More...
 
StatusLine parseStatusLine (final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException
 non-javadoc, see interface LineParser
 
Header parseHeader (CharArrayBuffer buffer) throws ParseException
 Creates a header from a line. More...
 

Static Public Member Functions

static final ProtocolVersion parseProtocolVersion (String value, LineParser parser) throws ParseException
 non-javadoc, see interface LineParser
 
static final RequestLine parseRequestLine (final String value, LineParser parser) throws ParseException
 non-javadoc, see interface LineParser
 
static final StatusLine parseStatusLine (final String value, LineParser parser) throws ParseException
 non-javadoc, see interface LineParser
 

Static Public Attributes

static final BasicLineParser DEFAULT = new BasicLineParser()
 A default instance of this class, for use as default or fallback. More...
 

Protected Member Functions

ProtocolVersion createProtocolVersion (int major, int minor)
 Creates a protocol version. More...
 
RequestLine createRequestLine (final String method, final String uri, final ProtocolVersion ver)
 Instantiates a new request line. More...
 
StatusLine createStatusLine (final ProtocolVersion ver, final int status, final String reason)
 Instantiates a new status line. More...
 
void skipWhitespace (final CharArrayBuffer buffer, final ParserCursor cursor)
 Helper to skip whitespace.
 

Protected Attributes

final ProtocolVersion protocol
 A version of the protocol to parse. More...
 

Constructor & Destructor Documentation

◆ BasicLineParser()

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

Member Function Documentation

◆ createProtocolVersion()

ProtocolVersion createProtocolVersion ( int  major,
int  minor 
)
protected

Called from parseProtocolVersion.

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

◆ hasProtocolVersion()

boolean hasProtocolVersion ( final CharArrayBuffer  buffer,
final ParserCursor  cursor 
)

This method implements a heuristic to check for a likely protocol version specification. It does not guarantee that parseProtocolVersion would not detect a parse error. This can be used to detect garbage lines before a request or status line.

Parameters
buffera buffer holding the line to inspect
cursorthe 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.
Returns
true if there is a protocol version at the argument index (possibly ignoring whitespace), false otherwise

Implements LineParser.

◆ parseRequestLine()

RequestLine parseRequestLine ( final CharArrayBuffer  buffer,
final ParserCursor  cursor 
) throws ParseException
Parameters
buffera buffer holding the line to parse
cursor
Returns
the parsed request line
Exceptions
ParseExceptionin case of a parse error

Implements LineParser.

◆ createRequestLine()

RequestLine createRequestLine ( final String  method,
final String  uri,
final ProtocolVersion  ver 
)
protected

Called from parseRequestLine.

Parameters
methodthe request method
urithe requested URI
verthe protocol version
Returns
a new status line with the given data

◆ createStatusLine()

StatusLine createStatusLine ( final ProtocolVersion  ver,
final int  status,
final String  reason 
)
protected

Called from parseStatusLine.

Parameters
verthe protocol version
statusthe status code
reasonthe reason phrase
Returns
a new status line with the given data

◆ parseHeader()

Header parseHeader ( CharArrayBuffer  buffer) throws ParseException

The full header line is expected here. Header continuation lines must be joined by the caller before invoking this method.

Parameters
buffera buffer holding the full header line. This buffer MUST NOT be re-used afterwards, since the returned object may reference the contents later.
Returns
the header in the argument buffer. The returned object MAY be a wrapper for the argument buffer. The argument buffer MUST NOT be re-used or changed afterwards.
Exceptions
ParseExceptionin case of a parse error

Implements LineParser.

Member Data Documentation

◆ DEFAULT

final BasicLineParser DEFAULT = new BasicLineParser()
static

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.

◆ protocol

final ProtocolVersion protocol
protected

The version is typically not relevant, but the protocol name.