public final class EncodingSniffer extends Object
Modifier and Type | Method and Description |
---|---|
static Charset |
extractEncodingFromContentType(String s)
Extracts an encoding from the specified
Content-Type value using
the IETF algorithm; if
no encoding is found, this method returns null . |
static Charset |
sniffEncodingFromCssDeclaration(InputStream is)
Parses and returns the charset declaration at the start of a css file if any, otherwise returns
null . |
static Charset |
sniffEncodingFromMetaTag(InputStream is)
Attempts to sniff an encoding from an HTML
meta tag in the specified byte array. |
static Charset |
sniffEncodingFromXmlDeclaration(InputStream is)
Searches the specified XML content for an XML declaration and returns the encoding if found,
otherwise returns
null . |
static Charset |
toCharset(String charsetName)
Returns
Charset if the specified charset name is supported on this platform. |
static String |
translateEncodingLabel(String encodingLabel)
Translates the given encoding label into a normalized form
according to Reference.
|
public static Charset sniffEncodingFromMetaTag(InputStream is) throws IOException
meta
tag in the specified byte array.is
- the content stream to check for an HTML meta
tagnull
if the encoding
could not be determinedIOException
- if an IO error occurspublic static Charset extractEncodingFromContentType(String s)
Content-Type
value using
the IETF algorithm; if
no encoding is found, this method returns null
.s
- the Content-Type
value to search for an encodingContent-Type
value, or null
if no
encoding was foundpublic static Charset sniffEncodingFromXmlDeclaration(InputStream is) throws IOException
null
.is
- the content stream to check for the charset declarationnull
if it could not be determinedIOException
- if an IO error occurspublic static Charset sniffEncodingFromCssDeclaration(InputStream is) throws IOException
null
.
e.g.
@charset "UTF-8"
is
- the input stream to parsenull
.IOException
- if an IO error occurspublic static Charset toCharset(String charsetName)
Charset
if the specified charset name is supported on this platform.charsetName
- the charset name to checkCharset
if the specified charset name is supported on this platformCopyright © 2002–2025 Gargoyle Software Inc.. All rights reserved.