Returns an optional charset for the value of the charset parameter if it is specified. @throws IllegalStateException if multiple charset values have been set for this media type @throws IllegalCharsetNameException if a charset value is present, but illegal @throws UnsupportedCharsetException if a c
()
| 713 | |
| 714 | |
| 715 | public Optional<Charset> charset() { |
| 716 | ImmutableSet<String> charsetValues = ImmutableSet.copyOf(parameters.get(CHARSET_ATTRIBUTE)); |
| 717 | switch (charsetValues.size()) { |
| 718 | case 0: |
| 719 | return Optional.absent(); |
| 720 | case 1: |
| 721 | return Optional.of(Charset.forName(Iterables.getOnlyElement(charsetValues))); |
| 722 | default: |
| 723 | throw new IllegalStateException("Multiple charset values defined: " + charsetValues); |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | /** |
| 728 | * Returns a new instance with the same type and subtype as this instance, but without any |