This is my related code snippet:
for (Path path : Files.list(Paths.get(this.getClass().getClassLoader().getResource(directoryResource).getPath())).collect(Collectors.toList())) {
String mediaType = this.tikaService.getMimeType(Files.newInputStream(path));
assertEquals(Files.probeContentType(path), mediaType);
}
As you can figure out, this.tikaService.getMimeType(...)
receive an InputStream
I provide using Files.newInputStream(path)
.
Everything works fine except when path
is pointing to a zip file.
In this case, Files.newInputStream()
is pointing to the content (the embedded file) of the zip file instead of pointing to the zip file.
Any work around?
EDIT
getMimeType
code:
public String getMimeType(InputStream is) {
TikaConfig tikaConfig = TikaConfig.getDefaultConfig();
Detector detector = tikaConfig.getDetector(); //new DefaultDetector();
Metadata metadata = new Metadata();
MediaType mediaType = detector.detect(TikaInputStream.get(is), metadata);
}
EDIT 2
I've also tried disabling ZipContainerDetector
using this config file:
<?xml version="1.0" encoding="UTF-8"?>
<properties>
<detectors>
<!-- All detectors except built-in container ones -->
<detector class="org.apache.tika.detect.DefaultDetector">
<dhttps://stackoverflow.com/posts/52000097/editetector-exclude class="org.apache.tika.parser.pkg.ZipContainerDetector"/>
</detector>
</detectors>
</properties>
but the result is the same.