Interface StreamingResponse
public interface StreamingResponse
Allows streaming a response directly, similar to
StreamingOutput
. Unlike StreamingOutput
, though,
StreamingResponse
allows HTTP headers to be set prior to streaming. Setting headers in write(javax.ws.rs.core.MultivaluedMap<java.lang.String, java.lang.Object>, java.io.OutputStream)
instead of on the Response
wrapping this StreamingResponse
, allows setting headers only if the
operations leading up to streaming bytes actually succeed.
Note that, if just-in-time headers are not needed, it's preferable to use the standard StreamingOutput
interface instead.
- Since:
- 9.5.0
-
Method Summary
Modifier and TypeMethodDescriptionvoid
write
(@NotNull javax.ws.rs.core.MultivaluedMap<String, Object> httpHeaders, @NotNull OutputStream outputStream) Writes the entity payload to the response, optionally setting additional HTTP headers first.
-
Method Details
-
write
void write(@NotNull @NotNull javax.ws.rs.core.MultivaluedMap<String, Object> httpHeaders, @NotNull @NotNull OutputStream outputStream) throws IOException, javax.ws.rs.WebApplicationExceptionWrites the entity payload to the response, optionally setting additional HTTP headers first.Additional headers must be set before the first byte is written to the provided
OutputStream
. When the first byte is written pending headers are flushed, and any subsequent headers will be ignored.- Parameters:
httpHeaders
- a mutable map of HTTP headers, allowing new headers to be set (HTTP headers can only be set prior to writing any bytes to the providedOutputStream
.)outputStream
- the stream to write the entity payload to- Throws:
IOException
- if the entity cannot be written to the streamjavax.ws.rs.WebApplicationException
- if an unexpected error occurs and the overallResponse
should be changed (The response can only be changed if this exception is thrown prior to writing any bytes to the providedOutputStream
.)
-