org.restlet.engine.http.header

## Class PreferenceReader<T extends Metadata>

- java.lang.Object
- - org.restlet.engine.http.header.HeaderReader<Preference<T>>
  - - org.restlet.engine.http.header.PreferenceReader<T>

    public class PreferenceReader<T extends Metadata>
    extends HeaderReader<Preference<T>>

Preference header reader. Works for character sets, encodings, languages or media types.

Author:
  Jerome Louvel

### Field Summary

Fields
`static int` `TYPE_CHARACTER_SET`
`static int` `TYPE_ENCODING`
`static int` `TYPE_LANGUAGE`
`static int` `TYPE_MEDIA_TYPE`

### Constructor Summary

Constructors
Constructor and Description
`PreferenceReader(int type, java.lang.String header)` Constructor.

### Method Summary

Methods
`static void` `addCharacterSets(java.lang.String acceptCharsetHeader, ClientInfo clientInfo)` Parses character set preferences from a header.
`static void` `addEncodings(java.lang.String acceptEncodingHeader, ClientInfo clientInfo)` Parses encoding preferences from a header.
`static void` `addLanguages(java.lang.String acceptLanguageHeader, ClientInfo clientInfo)` Adds language preferences from a header.
`static void` `addMediaTypes(java.lang.String acceptMediaTypeHeader, ClientInfo clientInfo)` Parses media type preferences from a header.
`protected Preference<T>` `createPreference(java.lang.CharSequence metadata, Series<Parameter> parameters)` Creates a new preference.
`protected Series<Parameter>` `extractMediaParams(Series<Parameter> parameters)` Extract the media parameters.
`protected float` `extractQuality(Series<Parameter> parameters)` Extract the quality value.
`static float` `readQuality(java.lang.String quality)` Parses a quality value. If the quality is invalid, an IllegalArgumentException is thrown.
`Preference<T>` `readValue()` Read the next preference.

### Methods inherited from class org.restlet.engine.http.header.HeaderReader

`addValues, canAdd, createParameter, createParameter, mark, peek, read, readComment, readDate, readDigits, readHeader, readHeader, readParameter, readParameterValue, readQuotedString, readRawText, readRawValue, readToken, readValues, reset, skipParameterSeparator, skipSpaces, skipValueSeparator, unread`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### TYPE_CHARACTER_SET

    public static final int TYPE_CHARACTER_SET

See Also:
  Constant Field Values

#### TYPE_ENCODING

    public static final int TYPE_ENCODING

See Also:
  Constant Field Values

#### TYPE_LANGUAGE

    public static final int TYPE_LANGUAGE

See Also:
  Constant Field Values

#### TYPE_MEDIA_TYPE

    public static final int TYPE_MEDIA_TYPE

See Also:
  Constant Field Values

### Constructor Detail

#### PreferenceReader

    public PreferenceReader(int type,
                    java.lang.String header)

Constructor.

Parameters:
  `type` - The type of metadata read.
  `header` - The header to read.

### Method Detail

#### addCharacterSets

    public static void addCharacterSets(java.lang.String acceptCharsetHeader,
                        ClientInfo clientInfo)

Parses character set preferences from a header.

Parameters:
  `acceptCharsetHeader` - The header to parse.
  `clientInfo` - The client info to update.

#### addEncodings

    public static void addEncodings(java.lang.String acceptEncodingHeader,
                    ClientInfo clientInfo)

Parses encoding preferences from a header.

Parameters:
  `acceptEncodingHeader` - The header to parse.
  `clientInfo` - The client info to update.

#### addLanguages

    public static void addLanguages(java.lang.String acceptLanguageHeader,
                    ClientInfo clientInfo)

Adds language preferences from a header.

Parameters:
  `acceptLanguageHeader` - The header to parse.
  `clientInfo` - The client info to update.

#### addMediaTypes

    public static void addMediaTypes(java.lang.String acceptMediaTypeHeader,
                     ClientInfo clientInfo)

Parses media type preferences from a header.

Parameters:
  `acceptMediaTypeHeader` - The header to parse.
  `clientInfo` - The client info to update.

#### readQuality

    public static float readQuality(java.lang.String quality)

Parses a quality value.
If the quality is invalid, an IllegalArgumentException is thrown.

Parameters:
  `quality` - The quality value as a string.
Returns:
  The parsed quality value as a float.

#### createPreference

    protected Preference<T> createPreference(java.lang.CharSequence metadata,
                                 Series<Parameter> parameters)

Creates a new preference.

Parameters:
  `metadata` - The metadata name.
  `parameters` - The parameters list.
Returns:
  The new preference.

#### extractMediaParams

    protected Series<Parameter> extractMediaParams(Series<Parameter> parameters)

Extract the media parameters. Only leave as the quality parameter if found. Modifies the parameters list.

Parameters:
  `parameters` - All the preference parameters.
Returns:
  The media parameters.

#### extractQuality

    protected float extractQuality(Series<Parameter> parameters)

Extract the quality value. If the value is not found, 1 is returned.

Parameters:
  `parameters` - The preference parameters.
Returns:
  The quality value.

#### readValue

    public Preference<T> readValue()
                                             throws java.io.IOException

Read the next preference.

Overrides:
  `readValue` in class `HeaderReader<Preference<T extends Metadata>>`
Returns:
  The next preference.
Throws:
  `java.io.IOException`