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 |
sniffEncoding(List<NameValuePair> headers,
InputStream content)
Deprecated.
as of version 4.0.0; depending on the content use
sniffEncodingFromMetaTag(InputStream) ,
sniffEncodingFromXmlDeclaration(InputStream) , or sniffEncodingFromCssDeclaration(InputStream)
instead |
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 |
sniffEncodingFromHttpHeaders(List<NameValuePair> headers)
Deprecated.
as of version 4.0.0; method will be removed without replacement
|
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 |
sniffHtmlEncoding(List<NameValuePair> headers,
InputStream content)
Deprecated.
as of version 4.0.0; depending on the content use
sniffEncodingFromMetaTag(InputStream) ,
sniffEncodingFromXmlDeclaration(InputStream) , or sniffEncodingFromCssDeclaration(InputStream)
instead |
static Charset |
sniffUnknownContentTypeEncoding(List<NameValuePair> headers,
InputStream content)
Deprecated.
as of version 4.0.0; depending on the content use
sniffEncodingFromMetaTag(InputStream) ,
sniffEncodingFromXmlDeclaration(InputStream) , or sniffEncodingFromCssDeclaration(InputStream)
instead |
static Charset |
sniffXmlEncoding(List<NameValuePair> headers,
InputStream content)
Deprecated.
as of version 4.0.0; depending on the content use
sniffEncodingFromMetaTag(InputStream) ,
sniffEncodingFromXmlDeclaration(InputStream) , or sniffEncodingFromCssDeclaration(InputStream)
instead |
static Charset |
toCharset(String charsetName)
Returns
Charset if the specified charset name is supported on this platform. |
static String |
translateEncodingLabel(Charset encodingLabel)
Deprecated.
as of version 4.0.0; method will be removed without replacement
|
static String |
translateEncodingLabel(String encodingLabel)
Translates the given encoding label into a normalized form
according to Reference.
|
@Deprecated public static Charset sniffEncoding(List<NameValuePair> headers, InputStream content) throws IOException
sniffEncodingFromMetaTag(InputStream)
,
sniffEncodingFromXmlDeclaration(InputStream)
, or sniffEncodingFromCssDeclaration(InputStream)
insteadIf the specified content is HTML content, this method sniffs encoding settings from the specified HTML content and/or the corresponding HTTP headers based on the HTML5 encoding sniffing algorithm.
If the specified content is XML content, this method sniffs encoding settings from the specified XML content and/or the corresponding HTTP headers using a custom algorithm.
Otherwise, this method sniffs encoding settings from the specified content of unknown type by looking for
Content-Type
information in the HTTP headers and
Byte Order Mark information in the content.
Note that if an encoding is found but it is not supported on the current platform, this method returns
null
, as if no encoding had been found.
headers
- the HTTP response headers sent back with the content to be sniffedcontent
- the content to be sniffednull
if the encoding could not be determinedIOException
- if an IO error occurs@Deprecated public static Charset sniffHtmlEncoding(List<NameValuePair> headers, InputStream content) throws IOException
sniffEncodingFromMetaTag(InputStream)
,
sniffEncodingFromXmlDeclaration(InputStream)
, or sniffEncodingFromCssDeclaration(InputStream)
insteadSniffs encoding settings from the specified HTML content and/or the corresponding HTTP headers based on the HTML5 encoding sniffing algorithm.
Note that if an encoding is found but it is not supported on the current platform, this method returns
null
, as if no encoding had been found.
headers
- the HTTP response headers sent back with the HTML content to be sniffedcontent
- the HTML content to be sniffednull
if the encoding could not be determinedIOException
- if an IO error occurs@Deprecated public static Charset sniffXmlEncoding(List<NameValuePair> headers, InputStream content) throws IOException
sniffEncodingFromMetaTag(InputStream)
,
sniffEncodingFromXmlDeclaration(InputStream)
, or sniffEncodingFromCssDeclaration(InputStream)
insteadSniffs encoding settings from the specified XML content and/or the corresponding HTTP headers using a custom algorithm.
Note that if an encoding is found but it is not supported on the current platform, this method returns
null
, as if no encoding had been found.
headers
- the HTTP response headers sent back with the XML content to be sniffedcontent
- the XML content to be sniffednull
if the encoding could not be determinedIOException
- if an IO error occurs@Deprecated public static Charset sniffUnknownContentTypeEncoding(List<NameValuePair> headers, InputStream content) throws IOException
sniffEncodingFromMetaTag(InputStream)
,
sniffEncodingFromXmlDeclaration(InputStream)
, or sniffEncodingFromCssDeclaration(InputStream)
insteadSniffs encoding settings from the specified content of unknown type by looking for Content-Type
information in the HTTP headers and Byte Order Mark
information in the content.
Note that if an encoding is found but it is not supported on the current platform, this method returns
null
, as if no encoding had been found.
headers
- the HTTP response headers sent back with the content to be sniffedcontent
- the content to be sniffednull
if the encoding could not be determinedIOException
- if an IO error occurs@Deprecated public static Charset sniffEncodingFromHttpHeaders(List<NameValuePair> headers)
headers
- the HTTP headers to examinenull
if the encoding
could not be determinedpublic 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 platform@Deprecated public static String translateEncodingLabel(Charset encodingLabel)
encodingLabel
- the label to translateCopyright © 2002–2024 Gargoyle Software Inc.. All rights reserved.