Saturday, August 6, 2016

Getting the MIME Type based on filename

If you have worked with documents over internet (http), you must be aware of what MIME Type is.
(In case this has suddenly made you interested to read more about mime type, you can check this wiki link.)

But while doing coding in java, the traditional approach or at least how I had been working with so far is, to have a hash/map of mime types and then get it based on the file extension.

Now, here is what Java provides an interesting feature to remove your worries. :-)
There is this interesting feature since I guess, java 1.7,  in java.nio.Files -> probeContentType which gives you content type. here is small test to demo the same.



Prototype

Prototype is another creation pattern. Intent:  - Intent is to create objects by cloning existing instance  - Specify the kinds of obj...