Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoSuchMethodError: org.apache.commons.io.IOUtils.read with Tika (detect method)

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?

like image 421
Zahreddine Laidi Avatar asked Oct 23 '25 09:10

Zahreddine Laidi


1 Answers

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.

  1. Make sure that commons-io is linked into your app (check the pom.xml, or an mvn dependency:tree output).

  2. 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.

like image 142
peterh Avatar answered Oct 26 '25 00:10

peterh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!