/** * A utility method for predicting media type from a file name. If the file * name extension is not recognised it will return {@link MediaType} for * "*\/*", it will also return the same if the file is {@code null}. * Currently supported file extensions can be found at {@link CommonMediaTypes}. * * @param fileName the file name from which to predict the {@link MediaType} * @return the {@link MediaType} for the give file; {@code null} - if file * is null; "application/octet-stream" if extension not recognized. */ public static MediaType getMediaTypeFromFileName(final String fileName) { if (fileName == null) { return null; } CommonMediaTypes[] types = CommonMediaTypes.values(); if (types != null && types.length > 0) { for (CommonMediaTypes type : types) { if (fileName.toLowerCase().endsWith(type.getExtension())) { return type.getMediaType(); } } } return MediaType.APPLICATION_OCTET_STREAM_TYPE; } }
/** * A utility method for predicting media type from a file name. If the file * name extension is not recognised it will return {@link MediaType} for * "*\/*", it will also return the same if the file is {@code null}. * Currently supported file extensions can be found at {@link CommonMediaTypes}. * * @param fileName the file name from which to predict the {@link MediaType} * @return the {@link MediaType} for the give file; {@code null} - if file * is null; "application/octet-stream" if extension not recognized. */ public static MediaType getMediaTypeFromFileName(final String fileName) { if (fileName == null) { return null; } CommonMediaTypes[] types = CommonMediaTypes.values(); if (types != null && types.length > 0) { for (CommonMediaTypes type : types) { if (fileName.toLowerCase().endsWith(type.getExtension())) { return type.getMediaType(); } } } return MediaType.APPLICATION_OCTET_STREAM_TYPE; } }
/** * A utility method for predicting media type from a file name. If the file * name extension is not recognised it will return {@link MediaType} for * "*\/*", it will also return the same if the file is {@code null}. * Currently supported file extensions can be found at {@link CommonMediaTypes}. * * @param fileName the file name from which to predict the {@link MediaType} * @return the {@link MediaType} for the give file; {@code null} - if file * is null; "application/octet-stream" if extension not recognized. */ public static MediaType getMediaTypeFromFileName(final String fileName) { if (fileName == null) { return null; } CommonMediaTypes[] types = CommonMediaTypes.values(); if (types != null && types.length > 0) { for (CommonMediaTypes type : types) { if (fileName.toLowerCase().endsWith(type.getExtension())) { return type.getMediaType(); } } } return MediaType.APPLICATION_OCTET_STREAM_TYPE; } }
/** * A utility method for predicting media type from a file name. If the file * name extension is not recognised it will return {@link MediaType} for * "*\/*", it will also return the same if the file is {@code null}. * Currently supported file extensions can be found at {@link CommonMediaTypes}. * * @param fileName the file name from which to predict the {@link MediaType} * @return the {@link MediaType} for the give file; {@code null} - if file * is null; "application/octet-stream" if extension not recognized. */ public static MediaType getMediaTypeFromFileName(final String fileName) { if (fileName == null) { return null; } CommonMediaTypes[] types = CommonMediaTypes.values(); if (types != null && types.length > 0) { for (CommonMediaTypes type : types) { if (fileName.toLowerCase().endsWith(type.getExtension())) { return type.getMediaType(); } } } return MediaType.APPLICATION_OCTET_STREAM_TYPE; } }
/** * A utility method for predicting media type from a file name. If the file * name extension is not recognised it will return {@link MediaType} for * "*\/*", it will also return the same if the file is {@code null}. * Currently supported file extensions can be found at {@link CommonMediaTypes}. * * @param fileName the file name from which to predict the {@link MediaType} * @return the {@link MediaType} for the give file; {@code null} - if file * is null; "application/octet-stream" if extension not recognized. */ public static MediaType getMediaTypeFromFileName(final String fileName) { if (fileName == null) { return null; } CommonMediaTypes[] types = CommonMediaTypes.values(); if (types != null && types.length > 0) { for (CommonMediaTypes type : types) { if (fileName.toLowerCase().endsWith(type.getExtension())) { return type.getMediaType(); } } } return MediaType.APPLICATION_OCTET_STREAM_TYPE; } }