@Response public class ReaderResource extends Object implements Writable
These objects can be returned as responses by REST methods.
The contents of the request passed into the constructor are immediately converted to read-only strings.
Instances of this class can be built using ReaderResourceBuilder
.
Constructor and Description |
---|
ReaderResource(MediaType mediaType,
Map<String,Object> headers,
VarResolverSession varSession,
Object... contents)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static ReaderResourceBuilder |
create()
Creates a new instance of a
ReaderResourceBuilder |
Map<String,Object> |
getHeaders()
Get the HTTP response headers.
|
MediaType |
getMediaType()
Returns the serialized media type for this resource (e.g.
|
String |
toCommentStrippedString()
Same as
toString() but strips comments from the text before returning it. |
String |
toString() |
Writer |
writeTo(Writer w)
Serialize this object to the specified writer.
|
public ReaderResource(MediaType mediaType, Map<String,Object> headers, VarResolverSession varSession, Object... contents) throws IOException
mediaType
- The resource media type.headers
- The HTTP response headers for this streamed resource.varSession
- Optional variable resolver for resolving variables in the string.contents
- The resource contents.
InputStream
Reader
- Converted to UTF-8 bytes.
File
CharSequence
- Converted to UTF-8 bytes.
IOException
public static ReaderResourceBuilder create()
ReaderResourceBuilder
ReaderResourceBuilder
@ResponseHeader(value="*") public Map<String,Object> getHeaders()
@ResponseBody public Writer writeTo(Writer w) throws IOException
Writable
writeTo
in interface Writable
w
- The writer to write to.IOException
@ResponseHeader(value="Content-Type") public MediaType getMediaType()
Writable
getMediaType
in interface Writable
public String toCommentStrippedString()
toString()
but strips comments from the text before returning it.
Supports stripping comments from the following media types: HTML, XHTML, XML, JSON, Javascript, CSS.
Copyright © 2018 Apache. All rights reserved.