Package org.jdrupes.httpcodec.types
Class Converters
java.lang.Object
org.jdrupes.httpcodec.types.Converters
Utility methods and singletons for converters.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Used to control the generation of “Set-Cookie” header fields. -
Field Summary
Modifier and TypeFieldDescriptionstatic final MultiValueConverter<CacheControlDirectives,
Directive> A converter for cache control directives.static final Converter<List<ParameterizedValue<String>>>
A converter for a list of challenges.static final MultiValueConverter<CookieList,
HttpCookie> A converter for a list of cookies.static final Converter<ParameterizedValue<String>>
A date/time converter.static final Directive.DirectiveConverter
A converter for a directive.static final MultiValueConverter<List<Directive>,
Directive> A converter for a list of directives.static final Etag.EtagConverter
A converter for an ETag header.A converter for a language or language range.static final MultiValueConverter<List<ParameterizedValue<Locale>>,
ParameterizedValue<Locale>> A converter for a weighted list of languages.An integer converter.static final MultiValueConverter<List<Long>,
Long> An integer list converter.static final Converter<MediaRange>
A converter for a media type pair with parameters.static final MultiValueConverter<List<MediaRange>,
MediaRange> A converter for a list of media ranges.A converter for a media type pair with parameters.static final Converter<MediaBase.MediaTypePair>
A converter for the media “topLevelType/Subtype” pair.static final org.jdrupes.httpcodec.types.Converters.ProductDescriptionConverter
A converter for product descriptions as used in theUser-Agent
andServer
header fields.A converter that quotes strings.static final Converter<StringList>
static final Converter<CookieList>
A converter for set cookies.static final Map<Converters.SameSiteAttribute,
SetCookieStringConverter> Provide converters for theA converter that quotes and unquoted strings as necessary.static final Converter<StringList>
A noop converter, except that text is trimmed and unquoted when converted to a value.A noop converter, except that text is trimmed when converted to a value.A converter for a URI.static final MultiValueConverter<List<ParameterizedValue<String>>,
ParameterizedValue<String>> A converter for a weighted list of strings.static final String
Used by theEtag.EtagConverter
to unambiguously denote a decoded wildcard. -
Method Summary
Modifier and TypeMethodDescriptionstatic int
commentLength
(String text, int startPos) Determines the length of a comment in a header field.static String
Return a new string in which all characters fromtoBeQuoted
are prefixed with a backslash.static String
quoteIfNecessary
(String value) Returns the given string as double quoted string if necessary.static String
quoteString
(String value) Returns the given string as double quoted string.static int
token68Length
(String text, int startPos) Determines the length of a token68 in a header fieldstatic int
tokenLength
(String text, int startPos) Determines the length of a token in a header fieldint
unmatchedLength
(String text, int startPos, String matches) Returns the length up to one of the match chars or end of string.static String
If the string contains a char with a backslash before it, remove the backslash.static String
unquoteString
(String value) If the value is double quoted, remove the quotes and escape characters.static int
whiteSpaceLength
(String text, int startPos) Determines the length of a white space sequence in a header field.
-
Field Details
-
UNQUOTED_STRING
A noop converter, except that text is trimmed when converted to a value. -
UNQUOTE_ONLY
A noop converter, except that text is trimmed and unquoted when converted to a value. -
STRING
A converter that quotes and unquoted strings as necessary. -
STRING_LIST
-
QUOTED_STRING
A converter that quotes strings. -
QUOTED_STRING_LIST
-
LONG
An integer converter. -
LONG_LIST
An integer list converter. -
DATE_TIME
A date/time converter. -
SET_COOKIE_STRING
Provide converters for the -
SET_COOKIE
A converter for set cookies. -
COOKIE_LIST
A converter for a list of cookies.Supports the format used in the “Cookie” header.
- See Also:
-
LANGUAGE
A converter for a language or language range.Language range “
*
” is converted to a Locale with an empty language. -
LANGUAGE_LIST
public static final MultiValueConverter<List<ParameterizedValue<Locale>>,ParameterizedValue<Locale>> LANGUAGE_LISTA converter for a weighted list of languages. -
WEIGHTED_STRINGS
public static final MultiValueConverter<List<ParameterizedValue<String>>,ParameterizedValue<String>> WEIGHTED_STRINGSA converter for a weighted list of strings. -
MEDIA_TYPE_PAIR
A converter for the media “topLevelType/Subtype” pair. -
MEDIA_RANGE
A converter for a media type pair with parameters. -
MEDIA_RANGE_LIST
A converter for a list of media ranges. -
MEDIA_TYPE
A converter for a media type pair with parameters. -
DIRECTIVE
A converter for a directive. -
DIRECTIVE_LIST
A converter for a list of directives. -
CACHE_CONTROL_LIST
A converter for cache control directives. -
URI_CONV
A converter for a URI. -
PRODUCT_DESCRIPTIONS
public static final org.jdrupes.httpcodec.types.Converters.ProductDescriptionConverter PRODUCT_DESCRIPTIONSA converter for product descriptions as used in theUser-Agent
andServer
header fields. -
WILDCARD
Used by theEtag.EtagConverter
to unambiguously denote a decoded wildcard.If the result of
fromFieldValue
==WILDCARD
, the field value was an unquoted asterisk. If the resultequals("*")
, it may also have been a quoted asterisk.- See Also:
-
ETAG
A converter for an ETag header. -
ETAG_LIST
-
CHALLENGE_LIST
A converter for a list of challenges. -
CREDENTIALS
-
-
Method Details
-
unquote
If the string contains a char with a backslash before it, remove the backslash.- Parameters:
value
- the value to unquote- Returns:
- the unquoted value
- Throws:
ParseException
- if the input violates the field format- See Also:
-
unquoteString
If the value is double quoted, remove the quotes and escape characters.- Parameters:
value
- the value to unquote- Returns:
- the unquoted value
- Throws:
ParseException
- if the input violates the field format- See Also:
-
quoteIfNecessary
Returns the given string as double quoted string if necessary.- Parameters:
value
- the value to quote if necessary- Returns:
- the result
- See Also:
-
quoteString
Returns the given string as double quoted string.- Parameters:
value
- the value to quote- Returns:
- the result
-
quote
Return a new string in which all characters fromtoBeQuoted
are prefixed with a backslash.- Parameters:
value
- the stringtoBeQuoted
- the characters to be quoted- Returns:
- the result
- See Also:
-
tokenLength
Determines the length of a token in a header field- Parameters:
text
- the text to parsestartPos
- the start position- Returns:
- the length of the token
- See Also:
-
token68Length
Determines the length of a token68 in a header field- Parameters:
text
- the text to parsestartPos
- the start position- Returns:
- the length of the token
- See Also:
-
whiteSpaceLength
Determines the length of a white space sequence in a header field.- Parameters:
text
- the test to parsestartPos
- the start position- Returns:
- the length of the white space sequence
- See Also:
-
commentLength
Determines the length of a comment in a header field.- Parameters:
text
- the text to parsestartPos
- the starting position (must be the position of the opening brace)- Returns:
- the length of the comment
- See Also:
-
unmatchedLength
Returns the length up to one of the match chars or end of string.- Parameters:
text
- the textstartPos
- the start positionmatches
- the chars to match- Returns:
- the length
-