网站页头制作,wordpress文章格式,中国住房城乡建设厅网站,大连做网站电话目录
1、什么是Tika
2、基本特性
3、Tika可视化提取
4、Springboot集成
4.1、maven依赖
4.2、Tika配置文件
4.3、注入tika bean
4.4、Service类
4.5、测试类TikaParserDemoTest 1、什么是Tika
Tika是一款Apache开源的#xff0c;跨平台#xff0c;支持多品种文本类…目录
1、什么是Tika
2、基本特性
3、Tika可视化提取
4、Springboot集成
4.1、maven依赖
4.2、Tika配置文件
4.3、注入tika bean
4.4、Service类
4.5、测试类TikaParserDemoTest 1、什么是Tika
Tika是一款Apache开源的跨平台支持多品种文本类型的内容检测和提取工具。Apache官方的介绍如下Apache Tika™ 工具包可检测并提取一千多种不同文件类型如 PPT、XLS 和 PDF中的元数据和文本。所有这些文件类型都可以通过一个界面进行解析这使得 Tika 可用于搜索引擎索引、内容分析、翻译等。 2、基本特性
跨平台Tika 可以在多种操作系统上运行包括 Windows、Linux 和 Mac OS。
支持多种格式Tika 支持多种文件格式包括常见的文档、图片、音频和视频格式。
可扩展性Tika 的设计是模块化的允许开发者添加新的解析器来支持新的文件格式。
安全性Tika 提供了防止文件注入攻击的机制确保在处理用户上传的文件时保持安全性。
3、Tika可视化提取
Tika提供了可视化界面工具可以直接通过可视化工具手动提取我们想要的文本内容。可视化工具需要下载tika-app.jar包下载后直接执行java -jar tika-app-2.9.2.jar即可唤起程序主页面 打开我们需要提取的文本点击view - 即可提取我们想要的格式。
4、Springboot集成
4.1、maven依赖
dependenciesdependencygroupIdorg.apache.tika/groupIdartifactIdtika-core/artifactIdversion2.9.2/version/dependencydependencygroupIdorg.apache.tika/groupIdartifactIdtika-parsers-standard-package/artifactIdversion2.9.2/version/dependency/dependencies
4.2、Tika配置文件
tika-config.xml
?xml version1.0 encodingUTF-8?
propertiesencodingDetectors!-- 检测 HTML 文件的字符编码它会根据 HTML 元素如 meta 标签中的声明来判断编码。 --encodingDetector classorg.apache.tika.parser.html.HtmlEncodingDetectorparams!-- 读取的最大字节数这里是 64,000 字节用于判断编码 --param namemarkLimit typeint64000/param/params/encodingDetector!-- Tika 的通用编码检测器 --encodingDetector classorg.apache.tika.parser.txt.UniversalEncodingDetectorparamsparam namemarkLimit typeint64000/param/params/encodingDetector!-- 基于 ICU4J 库的编码检测器。ICU4J 是一个强大的国际化库能够更准确地检测多语言文本的编码。 --encodingDetector classorg.apache.tika.parser.txt.Icu4jEncodingDetectorparamsparam namemarkLimit typeint64000/param/params/encodingDetector/encodingDetectors
/properties
4.3、注入tika bean
Configuration
public class ApplicationTikaConfig {Autowiredprivate ResourceLoader resourceLoader;Beanpublic Tika tika() throws TikaException, IOException, SAXException {Resource resource resourceLoader.getResource(classpath:tika-config.xml);InputStream inputStream resource.getInputStream();TikaConfig config new TikaConfig(inputStream);Detector detector config.getDetector();Parser autoDetectParser new AutoDetectParser(config);return new Tika(detector, autoDetectParser);}
}
4.4、Service类
Service
public class TikaParserService {Autowiredprivate Tika tika;public void parser(Path srcPath) throws TikaException, IOException {String result tika.parseToString(srcPath);System.out.println(result);}}
4.5、测试类TikaParserDemoTest
SpringBootTest(classes Main.class)
RunWith(SpringRunner.class)
public class TikaParserDemoTest {Autowiredprivate TikaParserService tikaParserService;Testpublic void testTikaParser() throws TikaException, IOException {tikaParserService.parser(Paths.get(F:, Java开发手册黄山版.pdf));}}
运行结果 具体代码已上传到git需要的自取。地址GitHub - Shamee99/springboot-modules