/** * Returns the corresponding MIME type to the given extension. * If no MIME type was found it returns <code>application/octet-stream</code> type. */ public static String getMimeType(final String ext) { String mimeType = lookupMimeType(ext); if (mimeType == null) { mimeType = MIME_APPLICATION_OCTET_STREAM; } return mimeType; }
@Test void testSimpleMime() { assertEquals("application/atom+xml", MimeTypes.getMimeType("atom")); assertEquals("audio/x-wav", MimeTypes.getMimeType("wav")); assertEquals("image/jpeg", MimeTypes.getMimeType("jpg")); assertEquals("text/x-asm", MimeTypes.getMimeType("asm")); assertEquals("video/mp4", MimeTypes.getMimeType("mp4")); assertEquals("image/jpeg", MimeTypes.lookupMimeType("jpg")); assertEquals("application/octet-stream", MimeTypes.getMimeType("xxx")); assertNull(MimeTypes.lookupMimeType("xxx")); }
/** * Returns the corresponding MIME type to the given extension. * If no MIME type was found it returns <code>application/octet-stream</code> type. */ public static String getMimeType(final String ext) { String mimeType = lookupMimeType(ext); if (mimeType == null) { mimeType = MIME_APPLICATION_OCTET_STREAM; } return mimeType; }