*/
public class MimeTypes {
+ /** The default MIME type for unknown extensions. */
+ private static final String DEFAULT_CONTENT_TYPE = "application/octet-stream";
+
/** List of all MIME types. */
private static final List<String> mimeTypes = new ArrayList<String>();
return Collections.emptyList();
}
+ /**
+ * Returns a default MIME type for the given extension. If the extension
+ * does not match a MIME type the default MIME typ
+ * “application/octet-stream” is returned.
+ *
+ * @param extension
+ * The extension to get the MIME type for
+ * @return The MIME type for the extension, or the default MIME type
+ * “application/octet-stream”
+ */
+ public static String getMimeType(String extension) {
+ if (extensionMimeTypes.containsKey(extension)) {
+ return extensionMimeTypes.get(extension).get(0);
+ }
+ return DEFAULT_CONTENT_TYPE;
+ }
+
//
// PRIVATE METHODS
//
*/
private static void addMimeType(String mimeType, String... extensions) {
mimeTypes.add(mimeType);
- for (String extension: extensions) {
+ for (String extension : extensions) {
if (!mimeTypeExtensions.containsKey(mimeType)) {
mimeTypeExtensions.put(mimeType, new ArrayList<String>());
}