Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java library or text file that maps mime types to nice human friendly file types

GOAL My goal is to find a text file or library that enables me to map when given a mime type input and return a nice human friendly format.

For example given the mime type for Word (as shown below) I would like a result that is something like "Microsoft Office Word Document".

application/vnd.openxmlformats-officedocument.wordprocessingml.document

I realise I could compile my own list and use something like a Map (Java) but then it would not be comprehensive etc.

SIMPLISTIC OPTION I know I can examine and return the sub mime type and keep the last component but that is not very sophisticated as per the Word mime type above the result would be a very generic "document". I could expand and take more components but the result is still quite ugly.

KEY/VALUE FILE Another option I have tried to find is a text file with key/value pairs where the key is the mime type in full and the value being the nice human friendly text.

text/plain=Plain Text File
application/octet-stream=Unknown binary file

This seems like a nice option but I have not been able to find a definitive text file with lots of entries. It would also be nice if a source for just the media( i prefer to call it the primary mime type) the "text" in "text/plain" was present so an unknown text mime type such as "text/unknown a.b.c" would return "Unknown text file/format".

like image 707
mP. Avatar asked Oct 15 '22 00:10

mP.


1 Answers

Apache Tika supports MimeTypes. It also supports Content Detection by the way if you don't know the mime type. Anyway, it looks like you need to do:

String t = "text/plain";
org.apache.tika.mime.MimeTypes.getMimeType(t).getDescription();

Disclaimer: I didn't actually try it. Also, I don't know if it supports all mime types you need.

like image 193
Thomas Mueller Avatar answered Oct 16 '22 14:10

Thomas Mueller