| java.lang.Object com.ibm.icu.text.CharsetDetector
CharsetDetector | public class CharsetDetector (Code) | | 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.
|
Method Summary | |
public CharsetMatch | detect() Return the charset that best matches the supplied input data. | public CharsetMatch[] | detectAll() Return an array of all charsets that appear to be plausible
matches with the input data. | public boolean | enableInputFilter(boolean filter) Enable filtering of input text. | public static String[] | getAllDetectableCharsets() Get the names of all char sets that can be recognized by the char set detector. | public Reader | getReader(InputStream in, String declaredEncoding) Autodetect the charset of an inputStream, and return a Java Reader
to access the converted input data.
This is a convenience method that is equivalent to
this.setDeclaredEncoding(declaredEncoding).setText(in).detect().getReader();
For the input stream that supplies the character data, markSupported()
must be true; the charset detection will read a small amount of data,
then return the stream to its original position via
the InputStream.reset() operation. | public String | getString(byte[] in, String declaredEncoding) Autodetect the charset of an inputStream, and return a String
containing the converted input data. | public boolean | inputFilterEnabled() Test whether or not input filtering is enabled. | public CharsetDetector | setDeclaredEncoding(String encoding) Set the declared encoding for charset detection.
The declared encoding of an input text is an encoding obtained
from an http header or xml declaration or similar source that
can be provided as additional information to the charset detector. | public CharsetDetector | setText(byte[] in) Set the input text (byte) data whose charset is to be detected. | public CharsetDetector | setText(InputStream in) Set the input text (byte) data whose charset is to be detected.
The input stream that supplies the character data must have markSupported()
== true; the charset detection process will read a small amount of data,
then return the stream to its original position via
the InputStream.reset() operation. |
fByteStats | short fByteStats(Code) | | |
fC1Bytes | boolean fC1Bytes(Code) | | |
fInputBytes | byte[] fInputBytes(Code) | | The following items are accessed by individual CharsetRecongizers during
the recognition process
|
fRawInput | byte[] fRawInput(Code) | | |
fRawLength | int fRawLength(Code) | | |
fStripTags | boolean fStripTags(Code) | | |
CharsetDetector | public CharsetDetector()(Code) | | Constructor
|
detect | public CharsetMatch detect()(Code) | | Return the charset that best matches the supplied input data.
Note though, that because the detection
only looks at the start of the input data,
there is a possibility that the returned charset will fail to handle
the full set of input data.
Raise an exception if
- no charset appears to match the data.
- no input text has been provided
a CharsetMatch object representing the best matching charset, ornull if there are no matches. |
detectAll | public CharsetMatch[] detectAll()(Code) | | Return an array of all charsets that appear to be plausible
matches with the input data. The array is ordered with the
best quality match first.
Raise an exception if
- no charsets appear to match the input data.
- no input text has been provided
An array of CharsetMatch objects representing possibly matching charsets. |
enableInputFilter | public boolean enableInputFilter(boolean filter)(Code) | | Enable filtering of input text. If filtering is enabled,
text within angle brackets ("<" and ">") will be removed
before detection.
Parameters: filter - true to enable input text filtering. The previous setting. |
getAllDetectableCharsets | public static String[] getAllDetectableCharsets()(Code) | | Get the names of all char sets that can be recognized by the char set detector.
an array of the names of all charsets that can be recognizedby the charset detector. |
getReader | public Reader getReader(InputStream in, String declaredEncoding)(Code) | | Autodetect the charset of an inputStream, and return a Java Reader
to access the converted input data.
This is a convenience method that is equivalent to
this.setDeclaredEncoding(declaredEncoding).setText(in).detect().getReader();
For the input stream that supplies the character data, markSupported()
must be true; the charset detection will read a small amount of data,
then return the stream to its original position via
the InputStream.reset() operation. The exact amount that will
be read depends on the characteristics of the data itself.
Raise an exception if no charsets appear to match the input data.
Parameters: in - The source of the byte data in the unknown charset. Parameters: declaredEncoding - A declared encoding for the data, if available,or null or an empty string if none is available. |
getString | public String getString(byte[] in, String declaredEncoding)(Code) | | Autodetect the charset of an inputStream, and return a String
containing the converted input data.
This is a convenience method that is equivalent to
this.setDeclaredEncoding(declaredEncoding).setText(in).detect().getString();
Raise an exception if no charsets appear to match the input data.
Parameters: in - The source of the byte data in the unknown charset. Parameters: declaredEncoding - A declared encoding for the data, if available,or null or an empty string if none is available. |
setDeclaredEncoding | public CharsetDetector setDeclaredEncoding(String encoding)(Code) | | Set the declared encoding for charset detection.
The declared encoding of an input text is an encoding obtained
from an http header or xml declaration or similar source that
can be provided as additional information to the charset detector.
A match between a declared encoding and a possible detected encoding
will raise the quality of that detected encoding by a small delta,
and will also appear as a "reason" for the match.
A declared encoding that is incompatible with the input data being
analyzed will not be added to the list of possible encodings.
Parameters: encoding - The declared encoding |
setText | public CharsetDetector setText(byte[] in)(Code) | | Set the input text (byte) data whose charset is to be detected.
Parameters: in - the input text of unknown encoding This CharsetDetector |
setText | public CharsetDetector setText(InputStream in) throws IOException(Code) | | Set the input text (byte) data whose charset is to be detected.
The input stream that supplies the character data must have markSupported()
== true; the charset detection process will read a small amount of data,
then return the stream to its original position via
the InputStream.reset() operation. The exact amount that will
be read depends on the characteristics of the data itself.
Parameters: in - the input text of unknown encoding This CharsetDetector |
|
|