@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 StreamResourceBuilder
.
Constructor and Description |
---|
StreamResource(MediaType mediaType,
Map<String,Object> headers,
Object... contents)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static StreamResourceBuilder |
create()
Creates a new instance of a
StreamResourceBuilder |
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, Object... contents) throws IOException
mediaType
- The resource media type.headers
- The HTTP response headers for this streamed resource.contents
- The resource contents.
byte []
InputStream
Reader
- Converted to UTF-8 bytes.
File
CharSequence
- Converted to UTF-8 bytes.
IOException
public static StreamResourceBuilder create()
StreamResourceBuilder
StreamResourceBuilder
@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
@ResponseHeader(value="Content-Type") public MediaType getMediaType()
Streamable
getMediaType
in interface Streamable
Copyright © 2018 Apache. All rights reserved.