MimeDetectionUtil { @SuppressWarnings("unchecked") public static String resolveMimeType(String fileName) { return getMimeType(MimeUtil.getMimeTypes(fileName)); } private  MimeDetectionUtil(); @SuppressWarnings("unchecked") static String resolveMimeType(String fileName); @SuppressWarnings("unchecked") static String resolveMimeType(byte[] data);  }
@Test public void testMimeDetection() throws IOException { byte[] gifData = FileUtils.readFileToByteArray(new File("src/test/resources/thequickbrownfox.gif")); byte[] xmlData = FileUtils.readFileToByteArray(new File("src/test/resources/some.xml")); byte[] pdfData = FileUtils.readFileToByteArray(new File("src/test/resources/test.pdf")); String mimeGif1 = MimeDetectionUtil.resolveMimeType(gifData); String mimeGif2 = MimeDetectionUtil.resolveMimeType("thequickbrownfox.gif"); String mimeXml1 = MimeDetectionUtil.resolveMimeType(xmlData); String mimeXml2 = MimeDetectionUtil.resolveMimeType("some.xml"); String mimePdf1 = MimeDetectionUtil.resolveMimeType(pdfData); String mimePdf2 = MimeDetectionUtil.resolveMimeType("test.pdf"); assertEquals("image/gif", mimeGif1); assertEquals("image/gif", mimeGif2); assertEquals("text/xml", mimeXml1); assertTrue( "text/xml".equals( mimeXml2 ) || "application/xml".equals( mimeXml2 ) ); assertEquals("application/pdf", mimePdf1); assertEquals("application/pdf", mimePdf2); }