From 1d92ac8fbb6c5c3a3be7bf477fef9251dcd3dfe2 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Mon, 23 Nov 2020 06:31:43 +0100 Subject: Add Apache Tika, remove iText7. Change-Id: I9736779cf57050a1dfd43d18625eb464a7179a9f --- pom.xml | 38 ++++++++++++++------------ src/main/java/eu/mulk/aendggner/AendGgner.java | 29 ++++++++++++++++---- src/main/java/module-info.java | 3 ++ 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/pom.xml b/pom.xml index e58f095..2bc4582 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,7 @@ 4.3.2 1.0.2 0.4.0 + 1.24.1 @@ -67,28 +68,31 @@ ${picocli.version} - + - com.itextpdf - itext7-core - ${itext7.version} - pom + org.apache.tika + tika-core + ${tika.version} - com.itextpdf - pdfocr-root - ${pdfocr.version} - pom + org.apache.tika + tika-bundle + ${tika.version} - com.itextpdf - pdfocr-api - ${pdfocr.version} - - - com.itextpdf - pdfocr-tesseract4 - ${pdfocr.version} + net.sourceforge.tess4j + tess4j + 4.5.1 + + + org.slf4j + jcl-over-slf4j + + + org.slf4j + log4j-over-slf4j + + diff --git a/src/main/java/eu/mulk/aendggner/AendGgner.java b/src/main/java/eu/mulk/aendggner/AendGgner.java index 618f36f..e510efb 100644 --- a/src/main/java/eu/mulk/aendggner/AendGgner.java +++ b/src/main/java/eu/mulk/aendggner/AendGgner.java @@ -1,7 +1,13 @@ package eu.mulk.aendggner; -import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; import java.util.concurrent.Callable; +import org.apache.tika.config.TikaConfig; +import org.apache.tika.exception.TikaException; +import org.apache.tika.io.TikaInputStream; +import org.apache.tika.metadata.Metadata; import picocli.CommandLine; import picocli.CommandLine.Command; import picocli.CommandLine.Parameters; @@ -14,10 +20,10 @@ import picocli.CommandLine.Parameters; public class AendGgner implements Callable { @Parameters(index = "0", description = "The base text to modify.") - private File baseFile; + private Path baseFile; - @Parameters(index = "1", description = "The diff relative to the base text.") - private File diffFile; + @Parameters(arity = "*", description = "The diff relative to the base text.") + private List patches; public static void main(String... args) { int exitCode = new CommandLine(new AendGgner()).execute(args); @@ -25,8 +31,19 @@ public class AendGgner implements Callable { } @Override - public final Integer call() { - System.out.println("Hi."); + public final Integer call() throws TikaException, IOException { + var tika = new TikaConfig(); + + for (var file : patches) { + var metadata = new Metadata(); + metadata.set(Metadata.RESOURCE_NAME_KEY, file.toString()); + try (var is = TikaInputStream.get(file)) { + var mimetype = tika.getDetector().detect( + TikaInputStream.get(file), metadata); + System.out.printf("File %s is %s.\n", file, mimetype); + } + } + return 0; } } diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index e7d9c77..dbe7d62 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -1,3 +1,6 @@ module aendggner { requires info.picocli; + requires org.apache.tika.core; + requires java.sql; + opens eu.mulk.aendggner; } -- cgit v1.2.1