Class EncoderSet

java.lang.Object
org.apache.juneau.encoders.EncoderSet

public final class EncoderSet extends Object
Represents the set of encoders keyed by codings.
Description
Maintains a set of encoders and the codings that they can handle.

The getEncoderMatch(String) and getEncoder(String) methods are then used to find appropriate encoders for specific Accept-Encoding and Content-Encoding header values.

Match ordering
Encoders are matched against Accept-Encoding strings in the order they exist in this group.

Encoders are tried in the order they appear in the set. The EncoderSet.Builder.add(Class...)/EncoderSet.Builder.add(Encoder...) methods prepend the values to the list to allow them the opportunity to override encoders already in the list.

For example, calling groupBuilder.add(E1.class,E2.class).add(E3.class, E4.class) will result in the order E3, E4, E1, E2.

Example:

// Create an encoder group with support for gzip compression. EncoderSet encoders = EncoderSet .create() .add(GzipEncoder.class) .build(); // Should return "gzip" String matchedCoding = encoders.findMatch("compress;q=1.0, gzip;q=0.8, identity;q=0.5, *;q=0"); // Get the encoder Encoder encoder = encoders.getEncoder(matchedCoding);

Notes:
  • This class is thread safe and reusable.
See Also:
  • Constructor Details

  • Method Details

    • create

      public static EncoderSet.Builder create(BeanStore beanStore)
      Static creator.
      Parameters:
      beanStore - The bean store to use for creating beans.
      Returns:
      A new builder for this object.
    • create

      public static EncoderSet.Builder create()
      Static creator.
      Returns:
      A new builder for this object.
    • getEncoderMatch

      public EncoderMatch getEncoderMatch(String acceptEncoding)
      Returns the coding string for the matching encoder that can handle the specified Accept-Encoding or Content-Encoding header value.

      Returns null if no encoders can handle it.

      This method is fully compliant with the RFC2616/14.3 and 14.11 specifications.

      Parameters:
      acceptEncoding - The Accept-Encoding or Content-Encoding value.
      Returns:
      The coding value (e.g. "gzip").
    • getEncoder

      public Encoder getEncoder(String encoding)
      Returns the encoder registered with the specified coding (e.g. "gzip").
      Parameters:
      encoding - The coding string.
      Returns:
      The encoder, or null if encoder isn't registered with that coding.
    • getSupportedEncodings

      Returns the set of codings supported by all encoders in this group.
      Returns:
      An unmodifiable list of codings supported by all encoders in this group. Never null.