From f42b615dcbe440d9908385754948d6448a3b67ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 2 Jun 2008 16:39:26 +0200 Subject: [PATCH] add method to return a single MIME type --- src/net/pterodactylus/util/io/MimeTypes.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/net/pterodactylus/util/io/MimeTypes.java b/src/net/pterodactylus/util/io/MimeTypes.java index 449b7c1..9ba1afa 100644 --- a/src/net/pterodactylus/util/io/MimeTypes.java +++ b/src/net/pterodactylus/util/io/MimeTypes.java @@ -32,6 +32,9 @@ import java.util.Map; */ 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 mimeTypes = new ArrayList(); @@ -787,6 +790,23 @@ public class MimeTypes { 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 // @@ -801,7 +821,7 @@ public class MimeTypes { */ 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()); } -- 2.7.4