File tree 2 files changed +12
-3
lines changed
framework-docs/modules/ROOT/pages/web/webmvc/mvc-controller/ann-methods
spring-core/src/main/java/org/springframework/core/io
2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,9 @@ content of the provided resource to the response `OutputStream`. Note that the
40
40
`InputStream` should be lazily retrieved by the `Resource` handle in order to reliably
41
41
close it after it has been copied to the response. If you are using `InputStreamResource`
42
42
for such a purpose, make sure to construct it with an on-demand `InputStreamSource`
43
- (e.g. through a lambda expression that retrieves the actual `InputStream`).
43
+ (e.g. through a lambda expression that retrieves the actual `InputStream`). Also, custom
44
+ subclasses of `InputStreamResource` are only supported in combination with a custom
45
+ `contentLength()` implementation which avoids consuming the stream for that purpose.
44
46
45
47
Spring MVC supports using a single value xref:web/webmvc/mvc-ann-async.adoc#mvc-ann-async-reactive-types[reactive type]
46
48
to produce the `ResponseEntity` asynchronously, and/or single and multi-value reactive
Original file line number Diff line number Diff line change 40
40
* times. This also applies when constructed with an {@code InputStreamSource}
41
41
* which lazily obtains the stream but only allows for single access as well.
42
42
*
43
+ * <p><b>NOTE: This class does not provide an independent {@link #contentLength()}
44
+ * implementation: Any such call will consume the given {@code InputStream}!</b>
45
+ * Consider overriding {@code #contentLength()} with a custom implementation if
46
+ * possible. For any other purpose, it is not recommended to extend from this
47
+ * class; this is particularly true when used with Spring's web resource rendering
48
+ * which specifically skips {@code #contentLength()} for this exact class only.
49
+ *
43
50
* @author Juergen Hoeller
44
51
* @author Sam Brannen
45
52
* @since 28.12.2003
@@ -132,8 +139,8 @@ public boolean isOpen() {
132
139
@ Override
133
140
public InputStream getInputStream () throws IOException , IllegalStateException {
134
141
if (this .read ) {
135
- throw new IllegalStateException ("InputStream has already been read - " +
136
- "do not use InputStreamResource if a stream needs to be read multiple times" );
142
+ throw new IllegalStateException ("InputStream has already been read (possibly for early content length " +
143
+ "determination) - do not use InputStreamResource if a stream needs to be read multiple times" );
137
144
}
138
145
this .read = true ;
139
146
return this .inputStreamSource .getInputStream ();
You can’t perform that action at this time.
0 commit comments