|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.tika.parser.txt.CharsetDetector
public class CharsetDetector
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.
Constructor Summary | |
---|---|
CharsetDetector()
Constructor |
Method Summary | |
---|---|
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 char sets that can be recognized by the char set detector. |
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 |
setText(byte[] in)
Set the input text (byte) data whose charset is to be detected. |
CharsetDetector |
setText(InputStream in)
Set the input text (byte) data whose charset is to be detected. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CharsetDetector()
Method Detail |
---|
public CharsetDetector setDeclaredEncoding(String encoding)
encoding
- The declared encodingpublic CharsetDetector setText(byte[] in)
in
- the input text of unknown encoding
public CharsetDetector setText(InputStream in) throws IOException
in
- the input text of unknown encoding
IOException
public CharsetMatch detect()
null
if there are no matches.public CharsetMatch[] detectAll()
public Reader getReader(InputStream in, String declaredEncoding)
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.
in
- The source of the byte data in the unknown charset.declaredEncoding
- A declared encoding for the data, if available,
or null or an empty string if none is available.public String getString(byte[] in, String declaredEncoding)
this.setDeclaredEncoding(declaredEncoding).setText(in).detect().getString();
Raise an exception if no charsets appear to match the input data.
in
- The source of the byte data in the unknown charset.declaredEncoding
- A declared encoding for the data, if available,
or null or an empty string if none is available.public static String[] getAllDetectableCharsets()
public boolean inputFilterEnabled()
true
if input text will be filtered.enableInputFilter(boolean)
public boolean enableInputFilter(boolean filter)
filter
- true
to enable input text filtering.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |