public class CharsetDetector extends Object
CharsetDetector
provides a facility for detecting the
charset or encoding of character data in an unknown format.
The input data can either be from an input stream or an array of bytes.
The result of the detection operation is a list of possibly matching
charsets, or, for simple use, you can just ask for a Java Reader that
will will work over the input data.
Character set detection is at best an imprecise operation. The detection process will attempt to identify the charset that best matches the characteristics of the byte data, but the process is partly statistical in nature, and the results can not be guaranteed to always be correct.
For best accuracy in charset detection, the input data should be primarily in a single language, and a minimum of a few hundred bytes worth of plain text in the language are needed. The detection process will attempt to ignore html or xml style markup that could otherwise obscure the content.
Constructor and Description |
---|
CharsetDetector()
Constructor
|
Modifier and Type | Method and Description |
---|---|
CharsetMatch |
detect()
Return the charset that best matches the supplied input data.
|
CharsetMatch[] |
detectAll()
Return an array of all charsets that appear to be plausible
matches with the input data.
|
boolean |
enableInputFilter(boolean filter)
Enable filtering of input text.
|
static String[] |
getAllDetectableCharsets()
Get the names of all charsets supported by
CharsetDetector class. |
String[] |
getDetectableCharsets()
Deprecated.
This API is ICU internal only.
|
Reader |
getReader(InputStream in,
String declaredEncoding)
Autodetect the charset of an inputStream, and return a Java Reader
to access the converted input data.
|
String |
getString(byte[] in,
String declaredEncoding)
Autodetect the charset of an inputStream, and return a String
containing the converted input data.
|
boolean |
inputFilterEnabled()
Test whether or not input filtering is enabled.
|
CharsetDetector |
setDeclaredEncoding(String encoding)
Set the declared encoding for charset detection.
|
CharsetDetector |
setDetectableCharset( |