Cleaned up the logic to be less verbose

This commit is contained in:
U-BASIS\dsmyda 2019-02-11 13:35:15 -05:00
parent d28a857599
commit dd17770a05

View File

@ -147,25 +147,16 @@ final class TikaTextExtractor implements TextExtractor {
public TikaTextExtractor(Content content) { public TikaTextExtractor(Content content) {
this.content = content; this.content = content;
parser = new AutoDetectParser();
if (!(content instanceof AbstractFile)) { if (content instanceof AbstractFile) {
parser = new AutoDetectParser(); AbstractFile file = (AbstractFile) content;
return; if(file.getMIMEType() != null) {
} //Set the Tika logic to use the pre-computed mime type
parser.setDetector((InputStream inStream, Metadata metaData) ->
AbstractFile file = (AbstractFile) content; MediaType.parse(file.getMIMEType()));
if (file.getMIMEType() == null) { }
parser = new AutoDetectParser();
} else {
parser = new AutoDetectParser(new Detector() {
/**
* Set the Tika logic to use the pre-computed mime type
*/
@Override
public MediaType detect(InputStream in, Metadata mtdt) throws IOException {
return MediaType.parse(file.getMIMEType());
}
});
} }
} }