Tika uses a chain of encoding detectors to determine the character encoding
of plain text and HTML content. DefaultEncodingDetector loads detectors
via the Java service-provider interface (SPI) and runs them in registration
order. See Charset Detection Pipeline
for design details.
With the stock dependencies on the classpath:
| Step | Detector | Returns non-null when… |
|---|---|---|
1 |
|
A UTF-8, UTF-16 LE/BE, or UTF-32 LE/BE byte-order mark is present. Emits DECLARATIVE. |
2 |
|
A |
3 |
|
A structural UTF-32 check, structural UTF-16 specialist, UTF-8 grammar gate, and 33-class byte-bigram Naive Bayes classifier. STRUCTURAL for structural hits; STATISTICAL for NB predictions. |
4 |
|
An HTML |
5 |
|
|
|
Note
|
junk-filter-encoding-detector is supplied by tika-ml-junkdetect
and SPI-loads when the module jar is on the classpath. Omit it for plain
first-match-wins — see Strict first-match-wins (no JunkFilter arbitration).
|
All detectors implement org.apache.tika.detect.EncodingDetector and can be
referenced by their SPI name in JSON configuration.
| Name | Module | Description |
|---|---|---|
|
|
Reads the first 4 bytes for BOM signatures. In the default chain. |
|
|
Reads declarative hints ( |
|
|
Byte-bigram Naive Bayes classifier plus structural detectors for UTF-32 and UTF-16 and a UTF-8 grammar gate. 33 classes including CJK multi-byte, EBCDIC variants, DOS code pages, Cyrillic, Windows single-byte, ISO-8859-3/16, Mac, and UTF-8. In the default chain. See the design doc. |
|
|
Fast lenient regex matcher for |
|
|
Spec-strict WHATWG prescan algorithm. Not in the default chain — opt in explicitly if you need strict WHATWG tokenisation (e.g. ignoring charset declarations inside comments or other contexts the lenient regex may match). |
|
|
Text-quality arbitrator ( |
|
|
Wraps ICU4J |
|
|
State-machine structural prober (juniversalchardet fork). Not auto-registered; opt in if you specifically need it. |
{
"encoding-detectors": [
{
"default-encoding-detector": {
"exclude": ["bom-detector"]
}
}
]
}Omit JunkFilter to get plain first-match-wins (each base detector’s top result wins in registration order):
{
"encoding-detectors": [
{"bom-detector": {}},
{"metadata-charset-detector": {}},
{"html-encoding-detector": {}},
{"mojibuster-encoding-detector": {}}
]
}Trade-off: lying declarations propagate unfiltered, and Mojibuster’s statistical guess wins ties without any text-quality cross-check. See the design doc.
html-encoding-detector reads up to 65 536 bytes by default when
scanning for the <meta charset> tag. Raise it if your documents embed
large <script> blocks before the meta tag (TIKA-2485):
{
"encoding-detectors": [
{"bom-detector": {}},
{"metadata-charset-detector": {}},
{
"html-encoding-detector": {
"markLimit": 131072
}
},
{"mojibuster-encoding-detector": {}},
{"junk-filter-encoding-detector": {}}
]
}Not recommended — the NB pipeline is strictly better on accuracy and latency — but available for regression testing or comparison:
{
"encoding-detectors": [
{"bom-detector": {}},
{"metadata-charset-detector": {}},
{"html-encoding-detector": {}},
{"icu4j-encoding-detector": {}},
{"universal-encoding-detector": {}}
]
}