Reputation: 700
Here is my method:
public String retrieveMimeType(InputStream stream, String filename) throws Exception {
TikaConfig config = TikaConfig.getDefaultConfig();
Detector detector = config.getDetector();
TikaInputStream streams = TikaInputStream.get(stream);
Metadata metadata = new Metadata();
metadata.add(TikaCoreProperties.RESOURCE_NAME_KEY, filename);
MediaType mediaType = null;
mediaType = detector.detect(stream, metadata);
return mediaType.toString();
}
It give me this on the log :
java.lang.NoSuchMethodError: org.apache.commons.io.IOUtils.read(Ljava/io/InputStream;[B)I
at org.apache.tika.detect.apple.BPListDetector.detect(BPListDetector.java:106)
at org.apache.tika.detect.CompositeDetector.detect(CompositeDetector.java:85)
at com.hraccess.helper.UserFileValidator.retrieveMimeType(UserFileValidator.java:313)
at com.hraccess.webclient.servlets.ServletBlob.doPost(ServletBlob.java:429)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:755)
For this line :
at com.hraccess.helper.UserFileValidator.retrieveMimeType(UserFileValidator.java:313)
here is the line 313:
mediaType = detector.detect(stream, metadata);
So what can I do? It gives this error when I added the parsers to my pom.xml . How to find why?
Upvotes: 4
Views: 14265
Reputation: 1
The stacktrace says that org.apache.commons.io.IOUtils.read
is missing. This is a static method in org.apache.commons.io.IOUtils
, which class is part of the commons-io package.
Make sure that commons-io is linked into your app (check the pom.xml, or an mvn dependency:tree
output).
Make sure it is linked in a relative newer version. V2.0 of the commons-io did not have this method yet (link), but the current one already has (link). In general, it is a good practice to use always the last stable version of everything.
Upvotes: 4