java.lang.Object
org.htmlunit.util.EncodingSniffer
Sniffs encoding settings from HTML, XML or other content. The HTML encoding sniffing algorithm is based on the
HTML5
encoding sniffing algorithm.
- Author:
- Daniel Gredler, Ahmed Ashour, Ronald Brill, Lai Quang Duong
-
Method Summary
Modifier and TypeMethodDescriptionstatic CharsetExtracts an encoding from the specifiedContent-Typevalue using the IETF algorithm; if no encoding is found, returnsnull.static CharsetParses and returns the charset declaration at the start of a CSS file if present, otherwise returnsnull.static CharsetAttempts to sniff an encoding from an HTMLmetatag in the specified input stream.static CharsetSearches the specified XML content for an XML declaration and returns the encoding if found, otherwise returnsnull.static CharsetReturns theCharsetfor the specified charset name if it is supported on this platform, ornullif it is not.static StringtranslateEncodingLabel(String encodingLabel) Translates the given encoding label into a normalized form according to the WHATWG Encoding specification.
-
Method Details
-
sniffEncodingFromMetaTag
Attempts to sniff an encoding from an HTMLmetatag in the specified input stream.- Parameters:
is- the content stream to check for an HTMLmetatag- Returns:
- the encoding sniffed from the stream, or
nullif it could not be determined - Throws:
IOException- if an I/O error occurs
-
extractEncodingFromContentType
Extracts an encoding from the specifiedContent-Typevalue using the IETF algorithm; if no encoding is found, returnsnull.- Parameters:
s- theContent-Typevalue to search for an encoding- Returns:
- the encoding found in the specified value, or
nullif none was found
-
sniffEncodingFromXmlDeclaration
Searches the specified XML content for an XML declaration and returns the encoding if found, otherwise returnsnull.- Parameters:
is- the content stream to check for a charset declaration- Returns:
- the encoding of the specified XML content, or
nullif it could not be determined - Throws:
IOException- if an I/O error occurs
-
sniffEncodingFromCssDeclaration
Parses and returns the charset declaration at the start of a CSS file if present, otherwise returnsnull. e.g.@charset "UTF-8"- Parameters:
is- the input stream to parse- Returns:
- the charset found at the start of the CSS file, or
nullif none - Throws:
IOException- if an I/O error occurs
-
toCharset
Returns theCharsetfor the specified charset name if it is supported on this platform, ornullif it is not.- Parameters:
charsetName- the charset name to look up- Returns:
- the
Charsetfor the given name, ornullif unsupported
-
translateEncodingLabel
Translates the given encoding label into a normalized form according to the WHATWG Encoding specification.- Parameters:
encodingLabel- the label to translate- Returns:
- the normalized encoding name, or
nullif not found
-