Class CharsetHolder
java.lang.Object
org.apache.tomcat.util.buf.CharsetHolder
Represents a character encoding to be used for a request or response.
Historically the Servlet API has used Strings for this information with lazy conversion to Charset. Sometimes the API required that an invalid name triggered an exception. Sometimes the invalid name was treated as if it had never been set. This resulted in classes storing both the String and, if the name was valid, the Charset with validation and conversion logic spread throughout those classes.
This class is an attempt to encapsulate that behaviour.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionReturns the Charset,nullif no Charset has been specified, ornullif the holder was created using the name of a Charset that the JRE does not recognise.static CharsetHoldergetInstance(String name) static CharsetHoldergetInstance(Charset encoding) getName()Returns the Charset ornullif no Charset has been specified.voidvalidate()Throws an exception if the instance holds a name that without a matching Charset.
-
Field Details
-
EMPTY
-
-
Method Details
-
getInstance
-
getInstance
-
getName
-
getCharset
Returns the Charset,nullif no Charset has been specified, ornullif the holder was created using the name of a Charset that the JRE does not recognise.- Returns:
- The Charset or
nullit is not set or invalid
-
getValidatedCharset
Returns the Charset ornullif no Charset has been specified.- Returns:
- The validated Charset or
nullif is not set - Throws:
UnsupportedEncodingException- if the holder was created using the name of a Charset that the JRE does not recognise
-
validate
Throws an exception if the instance holds a name that without a matching Charset.- Throws:
UnsupportedEncodingException- if the holder contains a name without a matching Charset
-