Tika 自动检测器解析器

2024 年 8 月 29 日 | 阅读 2 分钟

Tika AutoDetectParser 是一个类,它可以自动确定文件具有哪种类型的内容,然后调用适当的解析器。

此类包含以下给出的构造函数和方法。

Tika AutoDetectParser 构造函数

构造函数描述
public AutoDetectParser()它使用默认的 Tika 配置创建一个自动检测解析器实例。
public AutoDetectParser(Detector detector)它创建一个自动检测解析器实例。
public AutoDetectParser(Parser... parsers)它使用指定的解析器集合创建一个自动检测解析器实例。
public AutoDetectParser(Detector detector, Parser... parsers)它使用指定的检测器和解析器创建一个自动检测解析器实例。
public AutoDetectParser(TikaConfig config)使用指定的 Tika 配置创建一个自动检测解析器实例。

Tika AutoDetectParser 方法

以下是 Tika AutoDetectParser 类的方法。

方法描述
public Detector getDetector()它返回此解析器用于自动检测文档类型的类型检测器。
public void setDetector(Detector detector)它设置此解析器用于自动检测文档类型的类型检测器。
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException它用于解析输入文件。
public void parse(InputStream stream, ContentHandler handler, Metadata metadata) throws IOException, SAXException, TikaException它使用空的 ParseContext 调用 Parser.parse(InputStream, ContentHandler, Metadata, ParseContext) 方法。

Tika AutoDetectParser 示例

输出

以下是提取后 hello.txt 文件的内容。

Hello Welcome to Javatpoint