Class AcceptLanguage2


  • public final class AcceptLanguage2
    extends java.lang.Object
    Parser for AcceptLanguage that parses an Accept-Language header value using the deprecated Locale(String, String, String) constructor, combined with a custom BCP 47 subtag parser that maps the language tag components onto the language/country/variant triple that the deprecated constructor accepts. This is done for better efficiency.

    Known, accepted degradations compared with Locale.forLanguageTag():

    • Unicode, other and private use extensions (e.g. -u-ca-buddhist, -x-priv) are discarded rather than recorded on the Locale.
    • Script subtags (e.g. -Hant-) cannot be represented by the deprecated constructor and are mapped to the Locale variant, in upper case, instead of to the Locale script.
    • Tags that are syntactically invalid after the language subtag retain the components parsed up to that point rather than being replaced with Locale.ROOT.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.List<AcceptLanguage> parse​(java.io.StringReader input, int maxElements)
      Parses an Accept-Language header value, reading at most the specified number of entries.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • parse

        public static java.util.List<AcceptLanguage> parse​(java.io.StringReader input,
                                                           int maxElements)
                                                    throws java.io.IOException
        Parses an Accept-Language header value, reading at most the specified number of entries. See AcceptLanguage.parse(StringReader, int).
        Parameters:
        input - The StringReader containing the header value
        maxElements - The maximum number of entries to parse or -1 for no limit
        Returns:
        A list of AcceptLanguage entries. If the limit was reached, the returned list has exactly maxElements entries and any remaining entries were not parsed.
        Throws:
        java.io.IOException - If an I/O error occurs while reading the input