Class EncoderSet


public final class EncoderSet extends Object
Represents the set of encoders keyed by codings.
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.


// 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);

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

  • Method Details

    • create

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

      public static EncoderSet.Builder create()
      Static creator.
      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.

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

      public Encoder getEncoder(String encoding)
      Returns the encoder registered with the specified coding (e.g. "gzip").
      encoding - The coding string.
      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.
      An unmodifiable list of codings supported by all encoders in this group. Never null.