|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.restlet.resource.Variant
org.restlet.resource.Representation
public abstract class Representation
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
Field Summary | |
---|---|
static long |
UNKNOWN_SIZE
Indicates that the size of the representation can't be known in advance. |
Constructor Summary | |
---|---|
Representation()
Default constructor. |
|
Representation(MediaType mediaType)
Constructor. |
Method Summary | |
---|---|
boolean |
checkDigest()
Check that the digest computed from the representation content and the digest declared by the representation are the same. Since this method relies on the computeDigest(String) method,
and since this method reads entirely the representation's stream, user
must take care of the content of the representation in case the latter is
transient. |
boolean |
checkDigest(java.lang.String algorithm)
Check that the digest computed from the representation content and the digest declared by the representation are the same. |
Digest |
computeDigest(java.lang.String algorithm)
Compute the representation digest according to the given algorithm. Since this method reads entirely the representation's stream, user must take care of the content of the representation in case the latter is transient. |
static Representation |
createEmpty()
Returns a new empty representation with no content. |
long |
exhaust()
Exhauts the content of the representation by reading it and silently discarding anything read. |
long |
getAvailableSize()
Returns the size effectively available. |
abstract java.nio.channels.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. |
Digest |
getDigest()
Returns the representation digest if any. |
java.lang.String |
getDownloadName()
Returns the suggested download file name for this representation. |
java.util.Date |
getExpirationDate()
Returns the future date when this representation expire. |
java.util.Date |
getModificationDate()
Returns the last date when this representation was modified. |
Range |
getRange()
Returns the range where in the full content the partial content available should be applied. |
abstract java.io.Reader |
getReader()
Returns a characters reader with the representation's content. |
long |
getSize()
Returns the size in bytes if known, UNKNOWN_SIZE (-1) otherwise. |
abstract java.io.InputStream |
getStream()
Returns a stream with the representation's content. |
Tag |
getTag()
Returns the tag. |
java.lang.String |
getText()
Converts the representation to a string value. |
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. |
boolean |
isDownloadable()
Indicates if the representation is downloadable which means that it can be obtained via a download dialog box. |
boolean |
isTransient()
Indicates if the representation's content is transient, which means that it can be obtained only once. |
void |
release()
Releases the representation's content and all associated objects like sockets, channels or files. |
void |
setAvailable(boolean available)
Indicates if some fresh content is available. |
void |
setDigest(Digest digest)
Sets the representation digest. |
void |
setDownloadable(boolean downloadable)
Indicates if the representation is downloadable which means that it can be obtained via a download dialog box. |
void |
setDownloadName(java.lang.String fileName)
Set the suggested download file name for this representation. |
void |
setExpirationDate(java.util.Date expirationDate)
Sets the future date when this representation expire. |
void |
setModificationDate(java.util.Date modificationDate)
Sets the last date when this representation was modified. |
void |
setRange(Range range)
Sets the range where in the full content the partial content available should be applied. |
void |
setSize(long expectedSize)
Sets the expected size in bytes if known, -1 otherwise. |
void |
setTag(Tag tag)
Sets the tag. |
void |
setTransient(boolean isTransient)
Indicates if the representation's content is transient. |
abstract void |
write(java.io.OutputStream outputStream)
Writes the representation to a byte stream. |
abstract void |
write(java.nio.channels.WritableByteChannel writableChannel)
Writes the representation to a byte channel. |
abstract void |
write(java.io.Writer writer)
Writes the representation to a characters writer. |
Methods inherited from class org.restlet.resource.Variant |
---|
getCharacterSet, getEncodings, getIdentifier, getLanguages, getMediaType, setCharacterSet, setEncodings, setIdentifier, setIdentifier, setLanguages, setMediaType |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long UNKNOWN_SIZE
Constructor Detail |
---|
public Representation()
public Representation(MediaType mediaType)
mediaType
- The media type.Method Detail |
---|
public static Representation createEmpty()
public boolean checkDigest()
computeDigest(String)
method,
and since this method reads entirely the representation's stream, user
must take care of the content of the representation in case the latter is
transient.
isTransient
public boolean checkDigest(java.lang.String algorithm)
computeDigest(String)
method,
and since this method reads entirely the representation's stream, user
must take care of the content of the representation in case the latter is
transient.
isTransient
algorithm
- The algorithm used to compute the digest to compare with. See
constant values in Digest
.
public Digest computeDigest(java.lang.String algorithm)
isTransient
algorithm
- The algorithm used to compute the digest. See constant values
in Digest
.
public long exhaust() throws java.io.IOException
java.io.IOException
public long getAvailableSize()
getSize()
if no range is defined, otherwise it returns the size
of the range using Range.getSize()
.
public abstract java.nio.channels.ReadableByteChannel getChannel() throws java.io.IOException
java.io.IOException
public Digest getDigest()
public java.lang.String getDownloadName()
public java.util.Date getExpirationDate()
getExpirationDate
in class Variant
public java.util.Date getModificationDate()
getModificationDate
in class Variant
public Range getRange()
public abstract java.io.Reader getReader() throws java.io.IOException
java.io.IOException
public long getSize()
getSize
in class Variant
public abstract java.io.InputStream getStream() throws java.io.IOException
java.io.IOException
public Tag getTag()
getTag
in class Variant
public java.lang.String getText() throws java.io.IOException
java.io.IOException
public boolean isAvailable()
public boolean isDownloadable()
public boolean isTransient()
public void release()
public void setAvailable(boolean available)
available
- True if some fresh content is available.public void setDigest(Digest digest)
digest
- The representation digest.public void setDownloadable(boolean downloadable)
downloadable
- True if the representation's content is downloadable.public void setDownloadName(java.lang.String fileName)
fileName
- The suggested file name.public void setExpirationDate(java.util.Date expirationDate)
setExpirationDate
in class Variant
expirationDate
- The expiration date.public void setModificationDate(java.util.Date modificationDate)
setModificationDate
in class Variant
modificationDate
- The modification date.public void setRange(Range range)
range
- The content range.public void setSize(long expectedSize)
setSize
in class Variant
expectedSize
- The expected size in bytes if known, -1 otherwise.public void setTag(Tag tag)
setTag
in class Variant
tag
- The tag.public void setTransient(boolean isTransient)
isTransient
- True if the representation's content is transient.public abstract void write(java.io.OutputStream outputStream) throws java.io.IOException
outputStream
- The output stream.
java.io.IOException
public abstract void write(java.nio.channels.WritableByteChannel writableChannel) throws java.io.IOException
writableChannel
- A writable byte channel.
java.io.IOException
public abstract void write(java.io.Writer writer) throws java.io.IOException
writer
- The characters writer.
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |