@Response public class StreamResource extends Object implements Streamable
These objects can to be returned as responses by REST methods.
The contents of the request passed into the constructor are immediately converted to read-only byte arrays.
Instances of this class can be built using StreamResource.Builder
.
Modifier and Type | Class and Description |
---|---|
static class |
StreamResource.Builder
Builder class for constructing
StreamResource objects. |
Constructor and Description |
---|
StreamResource(MediaType mediaType,
Map<String,Object> headers,
boolean cached,
Object... contents)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static StreamResource.Builder |
create()
Creates a new instance of a
StreamResource.Builder for this class. |
InputStream |
getContents()
Returns the contents of this stream resource.
|
Map<String,Object> |
getHeaders()
Get the HTTP response headers.
|
MediaType |
getMediaType()
Returns the serialized media type for this resource (e.g.
|
void |
streamTo(OutputStream os)
Serialize this object to the specified output stream.
|
public StreamResource(MediaType mediaType, Map<String,Object> headers, boolean cached, Object... contents) throws IOException
mediaType
- The resource media type.headers
- The HTTP response headers for this streamed resource.cached
- Identifies if this stream resource is cached in memory.
contents
- The resource contents.
byte []
IOException
- Thrown by underlying stream.public static StreamResource.Builder create()
StreamResource.Builder
for this class.StreamResource.Builder
.@ResponseHeader(value="*") public Map<String,Object> getHeaders()
@ResponseBody public void streamTo(OutputStream os) throws IOException
Streamable
streamTo
in interface Streamable
os
- The output stream to stream to.IOException
- Thrown by underlying stream.@ResponseHeader(value="Content-Type") public MediaType getMediaType()
Streamable
getMediaType
in interface Streamable
public InputStream getContents() throws IOException
IOException
- Thrown by underlying stream.Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.