MimeType implements Serializable { public static String getExtension(MimeType mimeType) { Objects.requireNonNull(mimeType, "The MimeType must be provided!"); for (Entry<String, MimeType> entry : fileExtensions.entrySet()) { if (mimeType.equals(entry.getValue())) { return entry.getKey(); } } LOG.warn("The MimeType '{}' is not known or does not have a particular extension", mimeType); return null; } 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 getExtensionTest() { assertEquals("txt", MimeType.getExtension(MimeType.TEXT)); assertEquals("pdf", MimeType.getExtension(MimeType.PDF)); assertEquals("p7s", MimeType.getExtension(MimeType.PKCS7)); MimeType newMimeType = new MimeType("new/mimeType", "new"); assertEquals("new", MimeType.getExtension(newMimeType)); assertNull(MimeType.getExtension(MimeType.BINARY)); Exception exception = assertThrows(NullPointerException.class, () -> MimeType.getExtension(null)); assertEquals("The MimeType must be provided!", exception.getMessage()); }