lisak lisak - 1 year ago 134
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 ?

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download