Utils { public static String getExtension(final String mimeType) { if (mimeType == null || mimeType.isEmpty()) return null; final MimeTypes allTypes = MimeTypes.getDefaultMimeTypes(); MimeType tikaMimeType = null; try { tikaMimeType = allTypes.forName(mimeType); } catch (final MimeTypeException ex) { return null; } return tikaMimeType.getExtension(); }  static String toXMLDateTime(final Date date); static Date fromXMLDateTime(final String xmlDateTimeString); static String detectMimeType(final File f); static String getExtension(final String mimeType); static Path createFileWithUniqueName(final String baseName); static void sortFiles(final File array[]); static String getKeyByValue(final Map<String, String> map, final String value); static int compareStrings(final String s, final String p); static String getValue(final String value, final String defaultValue); static boolean isNullOrEmpty(final String s); static boolean isNullOrEmpty(final Collection<?> c); static boolean isNullOrEmpty(final Map<?,?> m); static boolean isNullOrEmpty(final Iterator<?> i); static Throwable getRootCause(final Throwable t); static List<Throwable> getCauses(final Throwable t); static String getExceptionTrace(final Throwable t); static boolean nullSafeEqual(final T o1, final T o2); static boolean nullSafeEqualIgnoreCase(final String s1, final String s2); static boolean isValidURI(final String uri); static boolean isTrue(String value);  }
@Test public void testGetExtension() { assertNull(Utils.getExtension(null)); assertNull(Utils.getExtension("")); final MimeTypes allTypes = MimeTypes.getDefaultMimeTypes(); SortedSet<MediaType> mTypes = allTypes.getMediaTypeRegistry().getTypes(); for(MediaType type : mTypes) { MimeType mimeType = null; String mediaTypeName = type.toString(); String mimeTypeName = null; try { mimeType = allTypes.getRegisteredMimeType(mediaTypeName); mimeTypeName = mimeType.getName(); } catch (MimeTypeException e) { fail(e.getMessage()); } assertEquals(mediaTypeName,mimeTypeName); String mimeTypeExtension = mimeType.getExtension(); assertEquals(mimeTypeExtension, Utils.getExtension(mimeTypeName)); } }