lisak lisak - 2 months ago 25
Java Question

How to get file extension from content type?

I'm using Apache Tika, and I have files (without extension) of particular content type that need to be renamed to have extension that reflect the content type.

Any idea if there is something I could use instead of programming that from scratch based on content type names ?


You want to look at file tika-mimetypes.xml -> check out tika's source code and :


     } else if (nodeElement.getTagName().equals(GLOB_TAG)) {
         boolean useRegex = Boolean.valueOf(nodeElement.getAttribute(ISREGEX_ATTR));
         types.addPattern(type, nodeElement.getAttribute(PATTERN_ATTR), useRegex);

You can then work wit


      private Patterns patterns = new Patterns(registry);