@Test public void testParse() { Assert.assertEquals(MediaType.VIDEO, mediaTypeUtils.parse("application/x-matroska")); Assert.assertEquals(MediaType.VIDEO, mediaTypeUtils.parse("application/x-vnd.rn-realmedia")); Assert.assertEquals(MediaType.VIDEO, mediaTypeUtils.parse("application/mp4")); Assert.assertEquals(MediaType.VIDEO, mediaTypeUtils.parse("image/gif")); Assert.assertEquals(MediaType.IMAGE, mediaTypeUtils.parse("image/jpeg")); Assert.assertEquals(MediaType.AUDIO, mediaTypeUtils.parse("audio/mpeg")); Assert.assertEquals(MediaType.UNKNOWN, mediaTypeUtils.parse("text/plain")); }
public static MediaType parse(String mimeType) { String trimmedMimeType = TextUtils.trim(mimeType); if (propertiesConfig == null) { log.warn("Media type properties could not be loaded from " + mediaTypesFile + "."); } else { String typeFromWhitelist = propertiesConfig.getString("whitelist." + mimeType); if (typeFromWhitelist != null) { log.debug("Media type found in whitelist: " + mimeType + " is " + typeFromWhitelist); MediaType type = MediaType.valueOf(typeFromWhitelist); if (type != null) { return type; } } } if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "AUDIO")) { return MediaType.AUDIO; } else if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "IMAGE")) { return MediaType.IMAGE; } else if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "VIDEO")) { return MediaType.VIDEO; } else { return MediaType.UNKNOWN; } }
MediaTypeUtils { public static MediaType parse(String mimeType) { String trimmedMimeType = TextUtils.trim(mimeType); if (propertiesConfig == null) { log.warn("Media type properties could not be loaded from " + mediaTypesFile + "."); } else { String typeFromWhitelist = propertiesConfig.getString("whitelist." + mimeType); if (typeFromWhitelist != null) { log.debug("Media type found in whitelist: " + mimeType + " is " + typeFromWhitelist); MediaType type = MediaType.valueOf(typeFromWhitelist); if (type != null) { return type; } } } if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "AUDIO")) { return MediaType.AUDIO; } else if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "IMAGE")) { return MediaType.IMAGE; } else if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "VIDEO")) { return MediaType.VIDEO; } else { return MediaType.UNKNOWN; } } }
MediaTypeUtils { public static MediaType parse(String mimeType) { String trimmedMimeType = TextUtils.trim(mimeType); if (propertiesConfig == null) { log.warn("Media type properties could not be loaded from " + mediaTypesFile + "."); } else { String typeFromWhitelist = propertiesConfig.getString("whitelist." + mimeType); if (typeFromWhitelist != null) { log.debug("Media type found in whitelist: " + mimeType + " is " + typeFromWhitelist); MediaType type = MediaType.valueOf(typeFromWhitelist); if (type != null) { return type; } } } if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "AUDIO")) { return MediaType.AUDIO; } else if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "IMAGE")) { return MediaType.IMAGE; } else if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "VIDEO")) { return MediaType.VIDEO; } else { return MediaType.UNKNOWN; } }  }
MediaTypeUtils { public static MediaType parse(String mimeType) { String trimmedMimeType = TextUtils.trim(mimeType); if (propertiesConfig == null) { log.warn("Media type properties could not be loaded from " + mediaTypesFile + "."); } else { String typeFromWhitelist = propertiesConfig.getString("whitelist." + mimeType); if (typeFromWhitelist != null) { log.debug("Media type found in whitelist: " + mimeType + " is " + typeFromWhitelist); MediaType type = MediaType.valueOf(typeFromWhitelist); if (type != null) { return type; } } } if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "AUDIO")) { return MediaType.AUDIO; } else if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "IMAGE")) { return MediaType.IMAGE; } else if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "VIDEO")) { return MediaType.VIDEO; } else { return MediaType.UNKNOWN; } }  static MediaType parse(String mimeType); }
MediaTypeUtils { public static MediaType parse(String mimeType) { String trimmedMimeType = TextUtils.trim(mimeType); if (propertiesConfig == null) { log.warn("Media type properties could not be loaded from " + mediaTypesFile + "."); } else { String typeFromWhitelist = propertiesConfig.getString("whitelist." + mimeType); if (typeFromWhitelist != null) { log.debug("Media type found in whitelist: " + mimeType + " is " + typeFromWhitelist); MediaType type = MediaType.valueOf(typeFromWhitelist); if (type != null) { return type; } } } if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "AUDIO")) { return MediaType.AUDIO; } else if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "IMAGE")) { return MediaType.IMAGE; } else if(StringUtils.startsWithIgnoreCase(trimmedMimeType, "VIDEO")) { return MediaType.VIDEO; } else { return MediaType.UNKNOWN; } }  static MediaType parse(String mimeType); static final String REF; }