Class CharsetDetector
java.lang.Object
org.archive.format.text.charset.CharsetDetector
- Direct Known Subclasses:
RotatingCharsetDetector,StandardCharsetDetector
Abstract class containing common methods for determining the character
encoding of a text Resource, most of which should be refactored into a
Util package.
- Author:
- brad
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringcontentTypeToCharset(String contentType) static StringfindMetaContentType(String pageSample) abstract StringgetCharset(byte[] buffer, int len, HttpHeaders headers) protected StringgetCharsetFromBytes(byte[] buffer, int len) Attempts to figure out the character set of the document using the excellent juniversalchardet library.protected StringgetCharsetFromHeaders(HttpHeaders headers) Attempt to divine the character encoding of the document from the Content-Type HTTP header (with a "charset=")protected StringgetCharsetFromMeta(byte[] buffer, int len) Attempt to find a META tag in the HTML that hints at the character set used to write the document.protected booleanisCharsetSupported(String charsetName) protected StringmapCharset(String orig)
-
Field Details
-
MAX_CHARSET_READAHEAD
protected static final int MAX_CHARSET_READAHEAD- See Also:
-
CHARSET_TOKEN
- See Also:
-
HTTP_CONTENT_TYPE_HEADER
- See Also:
-
DEFAULT_CHARSET
the default charset name to use when giving up
-
-
Constructor Details
-
CharsetDetector
public CharsetDetector()
-
-
Method Details
-
isCharsetSupported
-
mapCharset
-
contentTypeToCharset
-
getCharsetFromHeaders
Attempt to divine the character encoding of the document from the Content-Type HTTP header (with a "charset=")- Returns:
- String character set found or null if the header was not present
- Throws:
IOException
-
getCharsetFromMeta
Attempt to find a META tag in the HTML that hints at the character set used to write the document.- Returns:
- String character set found from META tags in the HTML
- Throws:
IOException
-
findMetaContentType
-
getCharsetFromBytes
Attempts to figure out the character set of the document using the excellent juniversalchardet library.- Returns:
- String character encoding found, or null if nothing looked good.
- Throws:
IOException
-
getCharset
- Returns:
- String charset name for the Resource
- Throws:
IOException- if there are problems reading the Resource
-