MimeType implements Serializable { public static MimeType fromFileName(final String fileName) { final String fileExtension = getFileExtension(fileName); if (fileExtension != null) { final String lowerCaseExtension = fileExtension.toLowerCase(); final MimeType mimeType = fileExtensions.get(lowerCaseExtension); if (mimeType != null) { return mimeType; } } return BINARY; } MimeType(); private  MimeType(final String mimeTypeString);  MimeType(final String mimeTypeString, final String extension); String getMimeTypeString(); void setMimeTypeString(String mimeTypeString); static MimeType fromFileName(final String fileName); static String getExtension(MimeType mimeType); static String getFileExtension(final String fileName); static MimeType fromFile(final File file); static MimeType fromMimeTypeString(final String mimeTypeString); void defineFileExtension(final String extension); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static final MimeType BINARY; static final MimeType XML; static final MimeType HTML; static final MimeType PDF; static final MimeType PKCS7; static final MimeType TST; static final MimeType ASICS; static final MimeType ASICE; static final MimeType ODT; static final MimeType ODS; static final MimeType ODP; static final MimeType ODG; static final MimeType TEXT; static final MimeType CRL; static final MimeType CER; static final MimeType PNG; static final MimeType JPEG; static final MimeType SVG; }
@Test public void fromFileNameTest() { assertEquals(MimeType.TEXT, MimeType.fromFileName("test.txt")); assertEquals(MimeType.PDF, MimeType.fromFileName("pades.pdf")); assertEquals(MimeType.PKCS7, MimeType.fromFileName("cades.p7s")); assertEquals(MimeType.PKCS7, MimeType.fromFileName("CADES.P7S")); assertEquals(MimeType.BINARY, MimeType.fromFileName("binaries")); assertEquals(MimeType.BINARY, MimeType.fromFileName("new.folder/binaries")); assertEquals(MimeType.BINARY, MimeType.fromFileName("")); assertEquals(MimeType.BINARY, MimeType.fromFileName(null)); }