Apache Tika 和解析文档时的字符限制
2022-09-02 23:53:27
任何人都可以帮我整理一下吗?
可以这样完成
Tika tika = new Tika();
tika.setMaxStringLength(10*1024*1024);
但是如果你不直接使用Tika,就像这样:
ContentHandler textHandler = new BodyContentHandler();
Metadata metadata = new Metadata();
Parser parser = new AutoDetectParser();
ParseContext ps = new ParseContext();
for (InputStream is : getInputStreams()) {
parser.parse(is, textHandler, metadata, ps);
is.close();
System.out.println("Title: " + metadata.get("title"));
System.out.println("Author: " + metadata.get("Author"));
}
无法对其进行设置,因为您不与 .顺便说一句,它默认设置为默认,这意味着没有限制。但生成的限制为 100000 个字符。WriteOutContentHandler
-1
/**
* The maximum number of characters to write to the character stream.
* Set to -1 for no limit.
*/
private final int writeLimit;
/**
* Number of characters written so far.
*/
private int writeCount = 0;
private WriteOutContentHandler(Writer writer, int writeLimit) {
this.writer = writer;
this.writeLimit = writeLimit;
}
/**
* Creates a content handler that writes character events to
* the given writer.
*
* @param writer writer
*/
public WriteOutContentHandler(Writer writer) {
this(writer, -1);
}