Skip to content

Commit cc33d3f

Browse files
committed
Polishing
1 parent bb5b5d5 commit cc33d3f

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public TypeDescriptor(Property property) {
117117
* constructor is used internally and may also be used by subclasses that support
118118
* non-Java languages with extended type systems.
119119
* @param resolvableType the resolvable type
120-
* @param type the backing type or {@code null} if should be resolved
120+
* @param type the backing type (or {@code null} if it should get resolved)
121121
* @param annotations the type annotations
122122
*/
123123
protected TypeDescriptor(ResolvableType resolvableType, Class<?> type, Annotation[] annotations) {
@@ -333,8 +333,8 @@ public TypeDescriptor getElementTypeDescriptor() {
333333
if (this.resolvableType.isArray()) {
334334
return new TypeDescriptor(this.resolvableType.getComponentType(), null, this.annotations);
335335
}
336-
if (streamAvailable && StreamHelper.isStream(this.type)) {
337-
return StreamHelper.getStreamElementType(this);
336+
if (streamAvailable && StreamDelegate.isStream(this.type)) {
337+
return StreamDelegate.getStreamElementType(this);
338338
}
339339
return getRelatedIfResolvable(this, this.resolvableType.asCollection().getGeneric());
340340
}
@@ -691,17 +691,18 @@ private static TypeDescriptor getRelatedIfResolvable(TypeDescriptor source, Reso
691691
return new TypeDescriptor(type, null, source.annotations);
692692
}
693693

694+
694695
/**
695696
* Inner class to avoid a hard dependency on Java 8.
696697
*/
697698
@UsesJava8
698-
private static class StreamHelper {
699+
private static class StreamDelegate {
699700

700-
private static boolean isStream(Class<?> type) {
701+
public static boolean isStream(Class<?> type) {
701702
return Stream.class.isAssignableFrom(type);
702703
}
703704

704-
private static TypeDescriptor getStreamElementType(TypeDescriptor source) {
705+
public static TypeDescriptor getStreamElementType(TypeDescriptor source) {
705706
return getRelatedIfResolvable(source, source.resolvableType.as(Stream.class).getGeneric());
706707
}
707708
}

spring-web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,8 +44,8 @@
4444
*/
4545
public class ResourceHttpMessageConverter extends AbstractHttpMessageConverter<Resource> {
4646

47-
private static final boolean jafPresent =
48-
ClassUtils.isPresent("javax.activation.FileTypeMap", ResourceHttpMessageConverter.class.getClassLoader());
47+
private static final boolean jafPresent = ClassUtils.isPresent(
48+
"javax.activation.FileTypeMap", ResourceHttpMessageConverter.class.getClassLoader());
4949

5050

5151
public ResourceHttpMessageConverter() {
@@ -103,7 +103,7 @@ protected void writeInternal(Resource resource, HttpOutputMessage outputMessage)
103103

104104

105105
/**
106-
* Inner class to avoid hard-coded JAF dependency.
106+
* Inner class to avoid a hard-coded JAF dependency.
107107
*/
108108
private static class ActivationMediaTypeFactory {
109109

@@ -114,7 +114,7 @@ private static class ActivationMediaTypeFactory {
114114
}
115115

116116
private static FileTypeMap loadFileTypeMapFromContextSupportModule() {
117-
// see if we can find the extended mime.types from the context-support module
117+
// See if we can find the extended mime.types from the context-support module...
118118
Resource mappingLocation = new ClassPathResource("org/springframework/mail/javamail/mime.types");
119119
if (mappingLocation.exists()) {
120120
InputStream inputStream = null;
@@ -140,11 +140,14 @@ private static FileTypeMap loadFileTypeMapFromContextSupportModule() {
140140
}
141141

142142
public static MediaType getMediaType(Resource resource) {
143-
if (resource.getFilename() == null) {
144-
return null;
143+
String filename = resource.getFilename();
144+
if (filename != null) {
145+
String mediaType = fileTypeMap.getContentType(filename);
146+
if (StringUtils.hasText(mediaType)) {
147+
return MediaType.parseMediaType(mediaType);
148+
}
145149
}
146-
String mediaType = fileTypeMap.getContentType(resource.getFilename());
147-
return (StringUtils.hasText(mediaType) ? MediaType.parseMediaType(mediaType) : null);
150+
return null;
148151
}
149152
}
150153

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -83,12 +83,13 @@
8383
*/
8484
public class ResourceHttpRequestHandler extends WebContentGenerator implements HttpRequestHandler, InitializingBean {
8585

86-
private final static Log logger = LogFactory.getLog(ResourceHttpRequestHandler.class);
86+
private static final String CONTENT_ENCODING = "Content-Encoding";
8787

88-
private static final boolean jafPresent =
89-
ClassUtils.isPresent("javax.activation.FileTypeMap", ResourceHttpRequestHandler.class.getClassLoader());
88+
private static final Log logger = LogFactory.getLog(ResourceHttpRequestHandler.class);
89+
90+
private static final boolean jafPresent = ClassUtils.isPresent(
91+
"javax.activation.FileTypeMap", ResourceHttpRequestHandler.class.getClassLoader());
9092

91-
private static final String CONTENT_ENCODING = "Content-Encoding";
9293

9394
private final List<Resource> locations = new ArrayList<Resource>(4);
9495

@@ -422,8 +423,9 @@ public String toString() {
422423
getLocations() + ", resolvers=" + getResourceResolvers() + "]";
423424
}
424425

426+
425427
/**
426-
* Inner class to avoid hard-coded JAF dependency.
428+
* Inner class to avoid a hard-coded JAF dependency.
427429
*/
428430
private static class ActivationMediaTypeFactory {
429431

@@ -434,7 +436,7 @@ private static class ActivationMediaTypeFactory {
434436
}
435437

436438
private static FileTypeMap loadFileTypeMapFromContextSupportModule() {
437-
// see if we can find the extended mime.types from the context-support module
439+
// See if we can find the extended mime.types from the context-support module...
438440
Resource mappingLocation = new ClassPathResource("org/springframework/mail/javamail/mime.types");
439441
if (mappingLocation.exists()) {
440442
InputStream inputStream = null;
@@ -465,4 +467,4 @@ public static MediaType getMediaType(String filename) {
465467
}
466468
}
467469

468-
}
470+
}

0 commit comments

Comments
 (0)