public abstract class Representation extends RepresentationInfo
Modifier and Type | Field and Description |
---|---|
static long |
UNKNOWN_SIZE
Indicates that the size of the representation can't be known in advance.
|
Constructor and Description |
---|
Representation()
Default constructor.
|
Representation(MediaType mediaType)
Constructor.
|
Representation(MediaType mediaType,
java.util.Date modificationDate)
Constructor.
|
Representation(MediaType mediaType,
java.util.Date modificationDate,
Tag tag)
Constructor.
|
Representation(MediaType mediaType,
Tag tag)
Constructor.
|
Representation(Variant variant,
java.util.Date modificationDate)
Constructor from a variant.
|
Representation(Variant variant,
java.util.Date modificationDate,
Tag tag)
Constructor from a variant.
|
Representation(Variant variant,
Tag tag)
Constructor from a variant.
|
Modifier and Type | Method and Description |
---|---|
boolean |
checkDigest()
Deprecated.
Use a
DigesterRepresentation instead. |
boolean |
checkDigest(java.lang.String algorithm)
Deprecated.
Use a
DigesterRepresentation instead. |
Digest |
computeDigest(java.lang.String algorithm)
Deprecated.
Use a
DigesterRepresentation instead. |
static Representation |
createEmpty()
Deprecated.
Use
EmptyRepresentation instead. |
long |
exhaust()
Exhaust 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.
Note that when used with HTTP connectors, this property maps to the "Content-MD5" header. |
Disposition |
getDisposition()
Returns the disposition characteristics of the representation.
|
java.lang.String |
getDownloadName()
Deprecated.
Use the "disposition" attribute instead.
|
java.util.Date |
getExpirationDate()
Returns the future date when this representation expire.
|
Range |
getRange()
Returns the range where in the full content the partial content available
should be applied.
Note that when used with HTTP connectors, this property maps to the "Content-Range" header. |
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.
Note that when used with HTTP connectors, this property maps to the "Content-Length" header. |
abstract java.io.InputStream |
getStream()
Returns a stream with the representation's content.
|
java.lang.String |
getText()
Converts the representation to a string value.
|
boolean |
isAvailable()
Indicates if some fresh content is potentially available, without having
to actually call one of the content manipulation method like getStream()
that would actually consume it.
|
boolean |
isDownloadable()
Deprecated.
Use the "disposition" attribute instead.
|
boolean |
isTransient()
Indicates if the representation's content is transient, which means that
it can be obtained only once.
|
void |
release()
Releases the representation and all associated objects like streams,
channels or files which are used to produce its content, transient or
not.
|
void |
setAvailable(boolean available)
Indicates if some fresh content is available.
|
void |
setDigest(Digest digest)
Sets the representation digest.
Note that when used with HTTP connectors, this property maps to the "Content-MD5" header. |
void |
setDisposition(Disposition disposition)
Sets the disposition characteristics of the representation.
|
void |
setDownloadable(boolean downloadable)
Deprecated.
Use the "disposition" attribute instead.
|
void |
setDownloadName(java.lang.String fileName)
Deprecated.
Use the "disposition" attribute instead.
|
void |
setExpirationDate(java.util.Date expirationDate)
Sets the future date when this representation expire.
|
void |
setRange(Range range)
Sets the range where in the full content the partial content available
should be applied.
Note that when used with HTTP connectors, this property maps to the "Content-Range" header. |
void |
setSize(long expectedSize)
Sets the expected size in bytes if known, -1 otherwise.
Note that when used with HTTP connectors, this property maps to the "Content-Length" header. |
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.
|
getModificationDate, getTag, setModificationDate, setTag
createClientInfo, equals, getCharacterSet, getEncodings, getIdentifier, getLanguages, getLocationRef, getMediaType, includes, isCompatible, setCharacterSet, setEncodings, setIdentifier, setIdentifier, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
public static final long UNKNOWN_SIZE
public Representation()
public Representation(MediaType mediaType)
mediaType
- The media type.public Representation(MediaType mediaType, java.util.Date modificationDate)
mediaType
- The media type.modificationDate
- The modification date.public Representation(MediaType mediaType, java.util.Date modificationDate, Tag tag)
mediaType
- The media type.modificationDate
- The modification date.tag
- The tag.public Representation(MediaType mediaType, Tag tag)
mediaType
- The media type.tag
- The tag.public Representation(Variant variant, java.util.Date modificationDate)
variant
- The variant to copy.modificationDate
- The modification date.public Representation(Variant variant, java.util.Date modificationDate, Tag tag)
variant
- The variant to copy.modificationDate
- The modification date.tag
- The tag.@Deprecated public static Representation createEmpty()
EmptyRepresentation
instead.@Deprecated public boolean checkDigest()
DigesterRepresentation
instead.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
@Deprecated public boolean checkDigest(java.lang.String algorithm)
DigesterRepresentation
instead.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
.@Deprecated public Digest computeDigest(java.lang.String algorithm)
DigesterRepresentation
instead.isTransient
algorithm
- The algorithm used to compute the digest. See constant values
in Digest
.public long exhaust() throws java.io.IOException
getStream()
and closes the retrieved stream in the end.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 Disposition getDisposition()
@Deprecated public java.lang.String getDownloadName()
public java.util.Date getExpirationDate()
public Range getRange()
public abstract java.io.Reader getReader() throws java.io.IOException
java.io.IOException
public long getSize()
public abstract java.io.InputStream getStream() throws java.io.IOException
java.io.IOException
public java.lang.String getText() throws java.io.IOException
java.io.IOException
public boolean isAvailable()
@Deprecated public boolean isDownloadable()
public boolean isTransient()
public void release()
setAvailable(boolean)
method
with "false" as a value.exhaust()
method or if this
could be too costly, you should instead explicitly abort the parent
request and the underlying connections using the Request#abort()
method or a shortcut one like ServerResource#abort()
or
Response#abort()
.public void setAvailable(boolean available)
available
- True if some fresh content is available.public void setDigest(Digest digest)
digest
- The representation digest.public void setDisposition(Disposition disposition)
disposition
- The disposition characteristics of the representation.@Deprecated public void setDownloadable(boolean downloadable)
downloadable
- True if the representation's content is downloadable.@Deprecated public void setDownloadName(java.lang.String fileName)
fileName
- The suggested file name.public void setExpirationDate(java.util.Date expirationDate)
expirationDate
- The expiration date.public void setRange(Range range)
range
- The content range.public void setSize(long expectedSize)
expectedSize
- The expected size in bytes if known, -1 otherwise.public void setTransient(boolean isTransient)
isTransient
- True if the representation's content is transient.public abstract void write(java.io.Writer writer) throws java.io.IOException
Writer
after writing to it as this will be handled
by the Restlet connectors automatically.writer
- The characters writer.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.OutputStream outputStream) throws java.io.IOException
OutputStream
after writing to it as this will be handled by
the Restlet connectors automatically.outputStream
- The output stream.java.io.IOException
Copyright © 2005-2012. All Rights Reserved.