File tree 1 file changed +5
-3
lines changed
spring-web/src/main/java/org/springframework/http/converter 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
18
18
19
19
import java .io .IOException ;
20
20
import java .io .InputStream ;
21
-
22
21
import javax .activation .FileTypeMap ;
23
22
import javax .activation .MimetypesFileTypeMap ;
24
23
25
24
import org .springframework .core .io .ByteArrayResource ;
26
25
import org .springframework .core .io .ClassPathResource ;
26
+ import org .springframework .core .io .InputStreamResource ;
27
27
import org .springframework .core .io .Resource ;
28
28
import org .springframework .http .HttpInputMessage ;
29
29
import org .springframework .http .HttpOutputMessage ;
@@ -78,7 +78,9 @@ protected MediaType getDefaultContentType(Resource resource) {
78
78
79
79
@ Override
80
80
protected Long getContentLength (Resource resource , MediaType contentType ) throws IOException {
81
- return resource .contentLength ();
81
+ // Don't try to determine contentLength on InputStreamResource - cannot be read afterwards...
82
+ // Note: custom InputStreamResource subclasses could provide a pre-calculated content length!
83
+ return (InputStreamResource .class .equals (resource .getClass ()) ? null : resource .contentLength ());
82
84
}
83
85
84
86
@ Override
You can’t perform that action at this time.
0 commit comments