MimeType implements Serializable { public static String getFileExtension(final String fileName) { if (fileName == null || fileName.trim().length() == 0) { return null; } String extension = ""; int lastIndexOf = fileName.lastIndexOf('.'); if (lastIndexOf > 0) { extension = fileName.substring(lastIndexOf + 1); } return extension; } 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 getFileExtensionTest() { assertEquals("txt", MimeType.getFileExtension("test.txt")); assertEquals("pdf", MimeType.getFileExtension("pades.pdf")); assertEquals("p7s", MimeType.getFileExtension("cades.p7s")); assertEquals("P7S", MimeType.getFileExtension("CADES.P7S")); assertEquals("", MimeType.getFileExtension("binaries")); assertEquals("folder/binaries", MimeType.getFileExtension("new.folder/binaries")); assertNull(MimeType.getFileExtension("")); assertNull(MimeType.getFileExtension(null)); }