| java.lang.Object org.restlet.resource.Variant org.restlet.resource.Representation
All known Subclasses: org.restlet.resource.FileRepresentation, org.restlet.util.WrapperRepresentation, org.restlet.resource.StreamRepresentation, org.restlet.resource.ChannelRepresentation,
Representation | abstract public class Representation extends Variant (Code) | | Current or intended state of a resource. The content of a representation can
be retrieved several times if there is a stable and accessible source, like a
local file or a string. When the representation is obtained via a temporary
source like a network socket, its content can only be retrieved once. The
"transient" and "available" properties are available to help you figure out
those aspects at runtime.
For performance purpose, it is
essential that a minimal overhead occurs upon initialization. The main
overhead must only occur during invocation of content processing methods
(write, getStream, getChannel and toString).
"REST components
perform actions on a resource by using a representation to capture the
current or intended state of that resource and transferring that
representation between components. A representation is a sequence of bytes,
plus representation metadata to describe those bytes. Other commonly used but
less precise names for a representation include: document, file, and HTTP
message entity, instance, or variant." Roy T. Fielding
See Also: Source
* dissertation author: Jerome Louvel (contact@noelios.com) |
Method Summary | |
abstract public ReadableByteChannel | getChannel() Returns a channel with the representation's content. If it is
supported by a file, a read-only instance of FileChannel is returned.
This method is ensured to return a fresh channel for each invocation
unless it is a transient representation, in which case null is returned. | abstract public InputStream | getStream() Returns a stream with the representation's content. | public String | getText() Converts the representation to a string value. | public boolean | isAvailable() Indicates if some fresh content is available, without having to actually
call one of the content manipulation method like getStream() that would
actually consume it. | public boolean | isTransient() Indicates if the representation's content is transient, which means that
it can be obtained only once. | public void | setAvailable(boolean available) Indicates if some fresh content is available. | public void | setTransient(boolean isTransient) Indicates if the representation's content is transient. | abstract public void | write(OutputStream outputStream) Writes the representation to a byte stream. | abstract public void | write(WritableByteChannel writableChannel) Writes the representation to a byte channel. |
Representation | public Representation()(Code) | | Default constructor.
|
Representation | public Representation(MediaType mediaType)(Code) | | Constructor.
Parameters: mediaType - The media type. |
getChannel | abstract public ReadableByteChannel getChannel() throws IOException(Code) | | Returns a channel with the representation's content. If it is
supported by a file, a read-only instance of FileChannel is returned.
This method is ensured to return a fresh channel for each invocation
unless it is a transient representation, in which case null is returned.
A channel with the representation's content. throws: IOException - |
getStream | abstract public InputStream getStream() throws IOException(Code) | | Returns a stream with the representation's content. This method is
ensured to return a fresh stream for each invocation unless it is a
transient representation, in which case null is returned.
A stream with the representation's content. throws: IOException - |
getText | public String getText() throws IOException(Code) | | Converts the representation to a string value. Be careful when using this
method as the conversion of large content to a string fully stored in
memory can result in OutOfMemoryErrors being thrown.
The representation as a string value. |
isAvailable | public boolean isAvailable()(Code) | | Indicates if some fresh content is available, without having to actually
call one of the content manipulation method like getStream() that would
actually consume it. This is especially useful for transient
representation whose content can only be accessed once and also when the
size of the representation is not known in advance.
True if some fresh content is available. |
isTransient | public boolean isTransient()(Code) | | Indicates if the representation's content is transient, which means that
it can be obtained only once. This is often the case with representations
transmitted via network sockets for example. In such case, if you need to
read the content several times, you need to cache it first, for example
into memory or into a file.
True if the representation's content is transient. |
setAvailable | public void setAvailable(boolean available)(Code) | | Indicates if some fresh content is available.
Parameters: available - True if some fresh content is available. |
setTransient | public void setTransient(boolean isTransient)(Code) | | Indicates if the representation's content is transient.
Parameters: isTransient - True if the representation's content is transient. |
write | abstract public void write(OutputStream outputStream) throws IOException(Code) | | Writes the representation to a byte stream. This method is ensured to
write the full content for each invocation unless it is a transient
representation, in which case an exception is thrown.
Parameters: outputStream - The output stream. throws: IOException - |
write | abstract public void write(WritableByteChannel writableChannel) throws IOException(Code) | | Writes the representation to a byte channel. This method is ensured to
write the full content for each invocation unless it is a transient
representation, in which case an exception is thrown.
Parameters: writableChannel - A writable byte channel. throws: IOException - |
Fields inherited from org.restlet.resource.Variant | final public static long UNKNOWN_SIZE(Code)(Java Doc)
|
|
|