Top Description Fields Constructors Methods
org.apache.http.message

public Class BasicHeaderValueParser

extends Object
implements HeaderValueParser
Class Inheritance
All Implemented Interfaces
org.apache.http.message.HeaderValueParser
Annotations
@Contract
threading:IMMUTABLE
Imports
java.util.ArrayList, .BitSet, .List, org.apache.http.HeaderElement, .NameValuePair, .ParseException, org.apache.http.annotation.ThreadingBehavior, .Contract, org.apache.http.util.Args, .CharArrayBuffer

Basic implementation for parsing header values into elements. Instances of this class are stateless and thread-safe. Derived classes are expected to maintain these properties.
Since
4.0

Field Summary

Modifier and TypeField and Description
public static final BasicHeaderValueParser
DEFAULT

A default instance of this class, for use as default or fallback.

private static final char
public static final BasicHeaderValueParser
private static final char
private static final BitSet
private final TokenParser
private static final BitSet

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected HeaderElement

Returns:

a header element representing the argument
createHeaderElement
(final String name, final String value, final NameValuePair[] params)

Creates a header element.

protected NameValuePair

Returns:

a name-value pair representing the arguments
createNameValuePair
(final String
the name
name
,
final String
the value, or null
value
)

Creates a name-value pair.

public static HeaderElement[]

Returns:

array holding the header elements, never null
parseElements
(final String
the header value to parse
value
,
final HeaderValueParser
the parser to use, or null for default
parser
)

Parses elements with the given parser.

public HeaderElement[]
parseElements(final CharArrayBuffer
buffer holding the header value to parse
buffer
,
final ParserCursor
the parser cursor containing the current position and the bounds within the buffer for the parsing operation
cursor
)

Implements org.apache.http.message.HeaderValueParser.parseElements.

Parses a header value into elements.
public static HeaderElement

Returns:

the parsed header element
parseHeaderElement
(final String
the header element to parse
value
,
final HeaderValueParser
the parser to use, or null for default
parser
)

Parses an element with the given parser.

public HeaderElement
parseHeaderElement(final CharArrayBuffer
buffer holding the element to parse
buffer
,
final ParserCursor
the parser cursor containing the current position and the bounds within the buffer for the parsing operation
cursor
)

Implements org.apache.http.message.HeaderValueParser.parseHeaderElement.

Parses a single header element.
public static NameValuePair

Returns:

the parsed name-value pair
parseNameValuePair
(final String
the NVP to parse
value
,
final HeaderValueParser
the parser to use, or null for default
parser
)

Parses a name-value-pair with the given parser.

public NameValuePair
parseNameValuePair(final CharArrayBuffer
the buffer holding the name-value pair to parse
buffer
,
final ParserCursor
the parser cursor containing the current position and the bounds within the buffer for the parsing operation
cursor
)

Implements org.apache.http.message.HeaderValueParser.parseNameValuePair.

Parses a name=value specification, where the = and value are optional.
public NameValuePair
parseNameValuePair(final CharArrayBuffer buffer, final ParserCursor cursor, final char[] delimiters)

public static NameValuePair[]

Returns:

array holding the parameters, never null
parseParameters
(final String
the parameter list to parse
value
,
final HeaderValueParser
the parser to use, or null for default
parser
)

Parses parameters with the given parser.

public NameValuePair[]
parseParameters(final CharArrayBuffer
buffer holding the name-value list to parse
buffer
,
final ParserCursor
the parser cursor containing the current position and the bounds within the buffer for the parsing operation
cursor
)

Implements org.apache.http.message.HeaderValueParser.parseParameters.

Parses a list of name-value pairs.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULTback to summary
public static final BasicHeaderValueParser DEFAULT

Deprecated

(4.3) use INSTANCE

A default instance of this class, for use as default or fallback. Note that BasicHeaderValueParser 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.

Annotations
@Deprecated
ELEM_DELIMITERback to summary
private static final char ELEM_DELIMITER
INSTANCEback to summary
public static final BasicHeaderValueParser INSTANCE
PARAM_DELIMITERback to summary
private static final char PARAM_DELIMITER
TOKEN_DELIMSback to summary
private static final BitSet TOKEN_DELIMS
tokenParserback to summary
private final TokenParser tokenParser
VALUE_DELIMSback to summary
private static final BitSet VALUE_DELIMS

Constructor Detail

BasicHeaderValueParserback to summary
public BasicHeaderValueParser()

Method Detail

createHeaderElementback to summary
protected HeaderElement createHeaderElement(final String name, final String value, final NameValuePair[] params)

Creates a header element. Called from parseHeaderElement.

Returns:HeaderElement

a header element representing the argument

createNameValuePairback to summary
protected NameValuePair createNameValuePair(final String name, final String value)

Creates a name-value pair. Called from parseNameValuePair.

Parameters
name:String

the name

value:String

the value, or null

Returns:NameValuePair

a name-value pair representing the arguments

parseElementsback to summary
public static HeaderElement[] parseElements(final String value, final HeaderValueParser parser) throws ParseException

Parses elements with the given parser.

Parameters
value:String

the header value to parse

parser:HeaderValueParser

the parser to use, or null for default

Returns:HeaderElement[]

array holding the header elements, never null

Exceptions
ParseException:
in case of a parsing error
parseElementsback to summary
public HeaderElement[] parseElements(final CharArrayBuffer buffer, final ParserCursor cursor)

Implements org.apache.http.message.HeaderValueParser.parseElements.

Doc from org.apache.http.message.HeaderValueParser.parseElements.

Parses a header value into elements. Parse errors are indicated as RuntimeException.

Some HTTP headers (such as the set-cookie header) have values that can be decomposed into multiple elements. In order to be processed by this parser, such headers must be in the following form:

header  = [ element ] *( "," [ element ] )
element = name [ "=" [ value ] ] *( ";" [ param ] )
param   = name [ "=" [ value ] ]

name    = token
value   = ( token | quoted-string )

token         = 1*<any char except "=", ",", ";", <"> and
                      white space>
quoted-string = <"> *( text | quoted-char ) <">
text          = any char except <">
quoted-char   = "\" char

Any amount of white space is allowed between any part of the header, element or param and is ignored. A missing value in any element or param will be stored as the empty String; if the "=" is also missing null will be stored instead.

Note that this parser does not apply to list-typed HTTP header fields in general; it is only suitable for fields that use the syntax described above. Counter-examples are "Link" (RFC 8288), "If-None-Match" (RFC 7232) or "Dav" (RFC 4918).

Parameters
buffer:CharArrayBuffer

buffer holding the header value to parse

cursor:ParserCursor

the parser cursor containing the current position and the bounds within the buffer for the parsing operation

Returns:HeaderElement[]

an array holding all elements of the header value

Annotations
@Override
parseHeaderElementback to summary
public static HeaderElement parseHeaderElement(final String value, final HeaderValueParser parser) throws ParseException

Parses an element with the given parser.

Parameters
value:String

the header element to parse

parser:HeaderValueParser

the parser to use, or null for default

Returns:HeaderElement

the parsed header element

parseHeaderElementback to summary
public HeaderElement parseHeaderElement(final CharArrayBuffer buffer, final ParserCursor cursor)

Implements org.apache.http.message.HeaderValueParser.parseHeaderElement.

Doc from org.apache.http.message.HeaderValueParser.parseHeaderElement.

Parses a single header element. A header element consist of a semicolon-separate list of name=value definitions.

Parameters
buffer:CharArrayBuffer

buffer holding the element to parse

cursor:ParserCursor

the parser cursor containing the current position and the bounds within the buffer for the parsing operation

Returns:HeaderElement

the parsed element

Annotations
@Override
parseNameValuePairback to summary
public static NameValuePair parseNameValuePair(final String value, final HeaderValueParser parser) throws ParseException

Parses a name-value-pair with the given parser.

Parameters
value:String

the NVP to parse

parser:HeaderValueParser

the parser to use, or null for default

Returns:NameValuePair

the parsed name-value pair

parseNameValuePairback to summary
public NameValuePair parseNameValuePair(final CharArrayBuffer buffer, final ParserCursor cursor)

Implements org.apache.http.message.HeaderValueParser.parseNameValuePair.

Doc from org.apache.http.message.HeaderValueParser.parseNameValuePair.

Parses a name=value specification, where the = and value are optional.

Parameters
buffer:CharArrayBuffer

the buffer holding the name-value pair to parse

cursor:ParserCursor

the parser cursor containing the current position and the bounds within the buffer for the parsing operation

Returns:NameValuePair

the name-value pair, where the value is null if no value is specified

Annotations
@Override
parseNameValuePairback to summary
public NameValuePair parseNameValuePair(final CharArrayBuffer buffer, final ParserCursor cursor, final char[] delimiters)
Annotations
@Deprecated
parseParametersback to summary
public static NameValuePair[] parseParameters(final String value, final HeaderValueParser parser) throws ParseException

Parses parameters with the given parser.

Parameters
value:String

the parameter list to parse

parser:HeaderValueParser

the parser to use, or null for default

Returns:NameValuePair[]

array holding the parameters, never null

parseParametersback to summary
public NameValuePair[] parseParameters(final CharArrayBuffer buffer, final ParserCursor cursor)

Implements org.apache.http.message.HeaderValueParser.parseParameters.

Doc from org.apache.http.message.HeaderValueParser.parseParameters.

Parses a list of name-value pairs. These lists are used to specify parameters to a header element. Parse errors are indicated as ParseException.

Parameters
buffer:CharArrayBuffer

buffer holding the name-value list to parse

cursor:ParserCursor

the parser cursor containing the current position and the bounds within the buffer for the parsing operation

Returns:NameValuePair[]

an array holding all items of the name-value list

Annotations
@Override