提交 0c825621 编写于 作者: R Rossen Stoyanchev

Avoid use of Optional wrapper to get List<MediaType>

See gh-26170
上级 e7b0b652
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -112,10 +112,12 @@ public final class MediaTypeFactory {
* @return the corresponding media types, or an empty list if none found
*/
public static List<MediaType> getMediaTypes(@Nullable String filename) {
return Optional.ofNullable(StringUtils.getFilenameExtension(filename))
.map(s -> s.toLowerCase(Locale.ENGLISH))
.map(fileExtensionToMediaTypes::get)
.orElse(Collections.emptyList());
List<MediaType> mediaTypes = null;
String ext = StringUtils.getFilenameExtension(filename);
if (ext != null) {
mediaTypes = fileExtensionToMediaTypes.get(ext.toLowerCase(Locale.ENGLISH));
}
return (mediaTypes != null ? mediaTypes : Collections.emptyList());
}
}
......@@ -736,7 +736,10 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
mediaType = this.mediaTypes.get(ext.toLowerCase(Locale.ENGLISH));
}
if (mediaType == null) {
mediaType = MediaTypeFactory.getMediaType(filename).orElse(null);
List<MediaType> mediaTypes = MediaTypeFactory.getMediaTypes(filename);
if (!CollectionUtils.isEmpty(mediaTypes)) {
mediaType = mediaTypes.get(0);
}
}
if (mediaType != null) {
result = mediaType;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册