@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 ReaderResource.Builder
.
Modifier and Type | Class and Description |
---|---|
static class |
ReaderResource.Builder
Builder class for constructing
ReaderResource objects. |
Modifier | Constructor and Description |
---|---|
|
ReaderResource(MediaType mediaType,
Map<String,Object> headers,
boolean cached,
Object... contents)
Constructor.
|
protected |
ReaderResource(ReaderResource.Builder b)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static ReaderResource.Builder |
create()
Creates a new instance of a
ReaderResource.Builder for this class. |
Reader |
getContents()
Returns the contents of this resource.
|
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.
|
protected ReaderResource(ReaderResource.Builder b) throws IOException
b
- Builder containing values to initialize this object with.IOException
- Thrown by underlying stream.public ReaderResource(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 resource is cached in memory.
contents
- The resource contents.
IOException
- Thrown by underlying stream.public static ReaderResource.Builder create()
ReaderResource.Builder
for this class.ReaderResource.Builder
.@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
- Thrown by underlying stream.@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.
public Reader getContents()
Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.