This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 7ae4efafadb Fixes #9392. Register Tika chardetect models and enable
native charsets
7ae4efafadb is described below
commit 7ae4efafadba9114b144be5869f9f6732f503d9d
Author: Gaƫlle Fournier <[email protected]>
AuthorDate: Wed Nov 4 17:47:23 2026 +0100
Fixes #9392. Register Tika chardetect models and enable native charsets
MojibusterEncodingDetector, brought by tika-parser-text-module, loads its
nb-bigram.bin and utf16-specialist.bin models from
org/apache/tika/ml/chardetect.
Register that directory when the detector class is present at runtime, so
builds
that exclude the text parser module do not pay for it.
The detector resolves candidate charsets by name, but native images bundle
only a
small subset of the JDK charsets by default. Request the full set with
NativeImageEnableAllCharsetsBuildItem, otherwise native plain text and XML
parsing fails with UnsupportedCharsetException: windows-1252.
Document the size cost and the fact that
quarkus.native.add-all-charsets=false
cannot turn the charsets off.
Co-authored-by: Claude Code <[email protected]>
---
.../ROOT/pages/reference/extensions/tika.adoc | 10 ++++++++++
.../component/tika/deployment/TikaProcessor.java | 20 +++++++++++++++++++-
extensions/tika/runtime/src/main/doc/usage.adoc | 9 +++++++++
3 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/docs/modules/ROOT/pages/reference/extensions/tika.adoc
b/docs/modules/ROOT/pages/reference/extensions/tika.adoc
index bcd09a59c34..5c2d4b19bb0 100644
--- a/docs/modules/ROOT/pages/reference/extensions/tika.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/tika.adoc
@@ -66,3 +66,13 @@ For other modules, use the version of
`org.apache.tika:tika-core` that `camel-ti
In native mode, the HTML, plain text and PDF modules are supported.
+[id="extensions-tika-usage-character-encodings-in-native-mode"]
+=== Character encodings in native mode
+
+`tika-parser-text-module`, brought by `camel-tika`, registers Tika's
`MojibusterEncodingDetector`.
+It matches candidate encodings by name (`windows-1252`, `ISO-8859-*`,
`Shift_JIS`, ...) at runtime, while native images bundle only a small subset of
the JDK charsets by default.
+To keep document parsing working, `camel-quarkus-tika` enables all JDK
charsets (`-H:+AddAllCharsets`) for your native build when the detector is
present.
+
+This adds a few MB to the native executable.
+Because the extension requests the charsets,
`quarkus.native.add-all-charsets=false` cannot turn them off, and there is no
need to set it to `true` yourself.
+
diff --git
a/extensions/tika/deployment/src/main/java/org/apache/camel/quarkus/component/tika/deployment/TikaProcessor.java
b/extensions/tika/deployment/src/main/java/org/apache/camel/quarkus/component/tika/deployment/TikaProcessor.java
index ef7a3b2cc60..133936489dd 100644
---
a/extensions/tika/deployment/src/main/java/org/apache/camel/quarkus/component/tika/deployment/TikaProcessor.java
+++
b/extensions/tika/deployment/src/main/java/org/apache/camel/quarkus/component/tika/deployment/TikaProcessor.java
@@ -22,6 +22,7 @@ import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.NativeImageEnableAllCharsetsBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ExcludeConfigBuildItem;
import
io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import
io.quarkus.deployment.builditem.nativeimage.NativeImageResourceDirectoryBuildItem;
@@ -42,9 +43,26 @@ class TikaProcessor {
}
@BuildStep
- void registerTikaCoreResources(BuildProducer<NativeImageResourceBuildItem>
resource) {
+ void registerTikaCoreResources(BuildProducer<NativeImageResourceBuildItem>
resource,
+ BuildProducer<NativeImageResourceDirectoryBuildItem>
resourceDirectory) {
resource.produce(new
NativeImageResourceBuildItem("org/apache/tika/mime/tika-mimetypes.xml"));
resource.produce(new
NativeImageResourceBuildItem("org/apache/tika/parser/external/tika-external-parsers.xml"));
+ // MojibusterEncodingDetector (brought by tika-parser-text-module)
loads its nb-bigram.bin and
+ // utf16-specialist.bin models with Class.getResourceAsStream
+ if
(QuarkusClassLoader.isClassPresentAtRuntime("org.apache.tika.ml.chardetect.MojibusterEncodingDetector"))
{
+ resourceDirectory.produce(new
NativeImageResourceDirectoryBuildItem("org/apache/tika/ml/chardetect"));
+ }
+ }
+
+ /**
+ * MojibusterEncodingDetector, brought by {@code tika-parser-text-module},
resolves charsets by name at runtime,
+ * while native images bundle only a small subset of the JDK charsets by
default.
+ */
+ @BuildStep
+ void
mojibusterEncodingDetectorCharsets(BuildProducer<NativeImageEnableAllCharsetsBuildItem>
enableAllCharsets) {
+ if
(QuarkusClassLoader.isClassPresentAtRuntime("org.apache.tika.ml.chardetect.MojibusterEncodingDetector"))
{
+ enableAllCharsets.produce(new
NativeImageEnableAllCharsetsBuildItem());
+ }
}
@BuildStep
diff --git a/extensions/tika/runtime/src/main/doc/usage.adoc
b/extensions/tika/runtime/src/main/doc/usage.adoc
index abb0973b281..e7a18da6244 100644
--- a/extensions/tika/runtime/src/main/doc/usage.adoc
+++ b/extensions/tika/runtime/src/main/doc/usage.adoc
@@ -15,3 +15,12 @@ The Camel Quarkus BOM manages the version of
`tika-parser-pdf-module` only.
For other modules, use the version of `org.apache.tika:tika-core` that
`camel-tika` brings.
In native mode, the HTML, plain text and PDF modules are supported.
+
+=== Character encodings in native mode
+
+`tika-parser-text-module`, brought by `camel-tika`, registers Tika's
`MojibusterEncodingDetector`.
+It matches candidate encodings by name (`windows-1252`, `ISO-8859-*`,
`Shift_JIS`, ...) at runtime, while native images bundle only a small subset of
the JDK charsets by default.
+To keep document parsing working, `camel-quarkus-tika` enables all JDK
charsets (`-H:+AddAllCharsets`) for your native build when the detector is
present.
+
+This adds a few MB to the native executable.
+Because the extension requests the charsets,
`quarkus.native.add-all-charsets=false` cannot turn them off, and there is no
need to set it to `true` yourself.