Package org.restlet.util
Class WrapperRepresentation
java.lang.Object
org.restlet.representation.Variant
org.restlet.representation.RepresentationInfo
org.restlet.representation.Representation
org.restlet.util.WrapperRepresentation
- Direct Known Subclasses:
BufferingRepresentation,DecodeRepresentation,DigesterRepresentation,EncodeRepresentation,RangeRepresentation
Representation wrapper. Useful for application developer who need to enrich
the representation with application related properties and behavior.
- Author:
- Jerome Louvel
- See Also:
-
Field Summary
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongexhaust()Exhaust the content of the representation by reading it and silently discarding anything read.longReturns the size effectively available.Returns the character set or null if not applicable.Returns the representation digest if any.
Note that when used with HTTP connectors, this property maps to the "Content-MD5" header.Returns the disposition characteristics of the representation.Returns the modifiable list of encodings applied to the entity-body.Returns the future date when this representation expire.Returns the modifiable list of languages.Returns an optional location reference.Returns the media type.
Note that when used with HTTP connectors, this property maps to the "Content-Type" header.Returns the last date when this representation was modified.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.Returns a character reader with the representation's content.longgetSize()Returns the total size in bytes if known, UNKNOWN_SIZE (-1) otherwise.Returns a stream with the representation's content.getTag()Returns the tag.
Note that when used with HTTP connectors, this property maps to the "ETag" header.getText()Converts the representation to a string value.Returns the wrapped representation.booleanIndicates 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.booleanIndicates if the representation's content is transient, which means that it can be obtained only once.voidrelease()Releases the representation and all associated objects like streams, channels or files which are used to produce its content, transient or not.voidsetAvailable(boolean isAvailable) Indicates if some fresh content is available.voidsetCharacterSet(CharacterSet characterSet) Sets the character set or null if not applicable.
Note that when used with HTTP connectors, this property maps to the "Content-Type" header.voidSets the representation digest.
Note that when used with HTTP connectors, this property maps to the "Content-MD5" header.voidsetDisposition(Disposition disposition) Sets the disposition characteristics of the representation.voidsetEncodings(List<Encoding> encodings) Sets the list of encodings applied to the entity-body.
Note that when used with HTTP connectors, this property maps to the "Content-Encoding" header.voidsetExpirationDate(Date expirationDate) Sets the future date when this representation expire.voidsetLanguages(List<Language> languages) Sets the list of languages.
Note that when used with HTTP connectors, this property maps to the "Content-Language" header.voidsetLocationRef(String locationUri) Sets the identifier from a URI string.
Note that when used with HTTP connectors, this property maps to the "Content-Location" header.voidsetLocationRef(Reference location) Sets the optional identifier.voidsetMediaType(MediaType mediaType) Sets the media type.
Note that when used with HTTP connectors, this property maps to the "Content-Type" header.voidsetModificationDate(Date modificationDate) Sets the last date when this representation was modified.voidSets 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.voidsetSize(long expectedSize) Sets the expected size in bytes if known, -1 otherwise.voidSets the tag.
Note that when used with HTTP connectors, this property maps to the "ETag" header.voidsetTransient(boolean isTransient) Indicates if the representation's content is transient.voidwrite(OutputStream outputStream) Writes the representation to a byte stream.voidWrites the representation to a characters writer.Methods inherited from class org.restlet.representation.Representation
append, hasKnownSize, isEmptyMethods inherited from class org.restlet.representation.Variant
createClientInfo, equals, hashCode, includes, isCompatible, toString
-
Constructor Details
-
WrapperRepresentation
Constructor.- Parameters:
wrappedRepresentation- The wrapped representation.
-
-
Method Details
-
exhaust
Description copied from class:RepresentationExhaust the content of the representation by reading it and silently discarding anything read. By default, it relies onRepresentation.getStream()and closes the retrieved stream in the end.- Overrides:
exhaustin classRepresentation- Returns:
- The number of bytes consumed or -1 if unknown.
- Throws:
IOException
-
getAvailableSize
public long getAvailableSize()Description copied from class:RepresentationReturns the size effectively available. This returns the same value asRepresentation.getSize()if no range is defined, otherwise it returns the size of the range usingRange.getSize().- Overrides:
getAvailableSizein classRepresentation- Returns:
- The available size.
-
getCharacterSet
Description copied from class:VariantReturns the character set or null if not applicable. Note that when used with HTTP connectors, this property maps to the "Content-Type" header.- Overrides:
getCharacterSetin classVariant- Returns:
- The character set or null if not applicable.
-
getDigest
Description copied from class:RepresentationReturns the representation digest if any.
Note that when used with HTTP connectors, this property maps to the "Content-MD5" header.- Overrides:
getDigestin classRepresentation- Returns:
- The representation digest or null.
-
getDisposition
Description copied from class:RepresentationReturns the disposition characteristics of the representation.- Overrides:
getDispositionin classRepresentation- Returns:
- The disposition characteristics of the representation.
-
getEncodings
Description copied from class:VariantReturns the modifiable list of encodings applied to the entity-body. Creates a new instance if no one has been set. An "IllegalArgumentException" exception is thrown when adding a null encoding to this list.
Note that when used with HTTP connectors, this property maps to the "Content-Encoding" header.- Overrides:
getEncodingsin classVariant- Returns:
- The list of encodings applied to the entity-body.
-
getExpirationDate
Description copied from class:RepresentationReturns the future date when this representation expire. If this information is not known, returns null.
Note that when used with HTTP connectors, this property maps to the "Expires" header.- Overrides:
getExpirationDatein classRepresentation- Returns:
- The expiration date.
-
getLanguages
Description copied from class:VariantReturns the modifiable list of languages. Creates a new instance if no one has been set. An "IllegalArgumentException" exception is thrown when adding a null language to this list.
Note that when used with HTTP connectors, this property maps to the "Content-Language" header.- Overrides:
getLanguagesin classVariant- Returns:
- The list of languages.
-
getLocationRef
Description copied from class:VariantReturns an optional location reference. This is useful when the representation is accessible from a location separate from the representation's resource URI, for example when content negotiation occurs.
Note that when used with HTTP connectors, this property maps to the "Content-Location" header.- Overrides:
getLocationRefin classVariant- Returns:
- The identifier.
-
getMediaType
Description copied from class:VariantReturns the media type.
Note that when used with HTTP connectors, this property maps to the "Content-Type" header.- Overrides:
getMediaTypein classVariant- Returns:
- The media type.
-
getModificationDate
Description copied from class:RepresentationInfoReturns the last date when this representation was modified. If this information is not known, returns null.
Note that when used with HTTP connectors, this property maps to the "Last-Modified" header.- Overrides:
getModificationDatein classRepresentationInfo- Returns:
- The modification date.
-
getRange
Description copied from class:RepresentationReturns 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.- Overrides:
getRangein classRepresentation- Returns:
- The content range or null if the full content is available.
-
getReader
Description copied from class:RepresentationReturns a character reader with the representation's content. This method is ensured to return a fresh reader for each invocation unless it is a transient representation, in which case null is returned. If the representation has no character set defined, the system's default one will be used.- Specified by:
getReaderin classRepresentation- Returns:
- A reader with the representation's content.
- Throws:
IOException
-
getSize
public long getSize()Description copied from class:RepresentationReturns the total size in bytes if known, UNKNOWN_SIZE (-1) otherwise. When ranges are used, this might not be the actual size available. For this purpose, you can use theRepresentation.getAvailableSize()method.
Note that when used with HTTP connectors, this property maps to the "Content-Length" header.- Overrides:
getSizein classRepresentation- Returns:
- The size in bytes if known, UNKNOWN_SIZE (-1) otherwise.
- See Also:
-
getStream
Description copied from class:RepresentationReturns 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.- Specified by:
getStreamin classRepresentation- Returns:
- A stream with the representation's content.
- Throws:
IOException
-
getTag
Description copied from class:RepresentationInfoReturns the tag.
Note that when used with HTTP connectors, this property maps to the "ETag" header.- Overrides:
getTagin classRepresentationInfo- Returns:
- The tag.
-
getText
Description copied from class:RepresentationConverts 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.- Overrides:
getTextin classRepresentation- Returns:
- The representation as a string value.
- Throws:
IOException
-
getWrappedRepresentation
Returns the wrapped representation.- Returns:
- The wrapped representation.
-
isAvailable
public boolean isAvailable()Description copied from class:RepresentationIndicates 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. Note that when the size of a representation is 0 is a not considered available. However, sometimes the size isn't known until a read attempt is made, so availability doesn't guarantee a non empty content.
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.- Overrides:
isAvailablein classRepresentation- Returns:
- True if some fresh content is available.
-
isTransient
public boolean isTransient()Description copied from class:RepresentationIndicates 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.- Overrides:
isTransientin classRepresentation- Returns:
- True if the representation's content is transient.
-
release
public void release()Description copied from class:RepresentationReleases the representation and all associated objects like streams, channels or files which are used to produce its content, transient or not. This method must be systematically called when the representation is no longer intended to be used. The framework automatically calls back this method via its connectors on the server-side when sending responses with an entity and on the client-side when sending a request with an entity. By default, it calls theRepresentation.setAvailable(boolean)method with "false" as a value.
Note that for transient socket-bound representations, calling this method after consuming the whole content shouldn't prevent the reuse of underlying socket via persistent connections for example. However, if the content hasn't been read, or has been partially read, the impact should be to discard the remaining content and to close the underlying connections.
Therefore, if you are not interested in the content, or in the remaining content, you should first call theRepresentation.exhaust()method or if this could be too costly, you should instead explicitly abort the parent request and the underlying connections using theRequest.abort()method or a shortcut one likeServerResource.abort()orResponse.abort().- Overrides:
releasein classRepresentation
-
setAvailable
public void setAvailable(boolean isAvailable) Description copied from class:RepresentationIndicates if some fresh content is available.- Overrides:
setAvailablein classRepresentation- Parameters:
isAvailable- True if some fresh content is available.
-
setCharacterSet
Description copied from class:VariantSets the character set or null if not applicable.
Note that when used with HTTP connectors, this property maps to the "Content-Type" header.- Overrides:
setCharacterSetin classVariant- Parameters:
characterSet- The character set or null if not applicable.
-
setDigest
Description copied from class:RepresentationSets the representation digest.
Note that when used with HTTP connectors, this property maps to the "Content-MD5" header.- Overrides:
setDigestin classRepresentation- Parameters:
digest- The representation digest.
-
setDisposition
Description copied from class:RepresentationSets the disposition characteristics of the representation.- Overrides:
setDispositionin classRepresentation- Parameters:
disposition- The disposition characteristics of the representation.
-
setEncodings
Description copied from class:VariantSets the list of encodings applied to the entity-body.
Note that when used with HTTP connectors, this property maps to the "Content-Encoding" header.- Overrides:
setEncodingsin classVariant- Parameters:
encodings- The list of encodings applied to the entity-body.
-
setExpirationDate
Description copied from class:RepresentationSets the future date when this representation expire. If this information is not known, pass null.
Note that when used with HTTP connectors, this property maps to the "Expires" header.- Overrides:
setExpirationDatein classRepresentation- Parameters:
expirationDate- The expiration date.
-
setLanguages
Description copied from class:VariantSets the list of languages.
Note that when used with HTTP connectors, this property maps to the "Content-Language" header.- Overrides:
setLanguagesin classVariant- Parameters:
languages- The list of languages.
-
setLocationRef
Description copied from class:VariantSets the optional identifier. This is useful when the representation is accessible from a location separate from the representation's resource URI, for example when content negotiation occurs.
Note that when used with HTTP connectors, this property maps to the "Content-Location" header.- Overrides:
setLocationRefin classVariant- Parameters:
location- The location reference.
-
setLocationRef
Description copied from class:VariantSets the identifier from a URI string.
Note that when used with HTTP connectors, this property maps to the "Content-Location" header.- Overrides:
setLocationRefin classVariant- Parameters:
locationUri- The location URI to parse.
-
setMediaType
Description copied from class:VariantSets the media type.
Note that when used with HTTP connectors, this property maps to the "Content-Type" header.- Overrides:
setMediaTypein classVariant- Parameters:
mediaType- The media type.
-
setModificationDate
Description copied from class:RepresentationInfoSets the last date when this representation was modified. If this information is not known, pass null.
Note that when used with HTTP connectors, this property maps to the "Last-Modified" header.- Overrides:
setModificationDatein classRepresentationInfo- Parameters:
modificationDate- The modification date.
-
setRange
Description copied from class:RepresentationSets 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.- Overrides:
setRangein classRepresentation- Parameters:
range- The content range.
-
setSize
public void setSize(long expectedSize) Description copied from class:RepresentationSets the expected size in bytes if known, -1 otherwise. For this purpose, you can use theRepresentation.getAvailableSize()method.
Note that when used with HTTP connectors, this property maps to the "Content-Length" header.- Overrides:
setSizein classRepresentation- Parameters:
expectedSize- The expected size in bytes if known, -1 otherwise.
-
setTag
Description copied from class:RepresentationInfoSets the tag.
Note that when used with HTTP connectors, this property maps to the "ETag" header.- Overrides:
setTagin classRepresentationInfo- Parameters:
tag- The tag.
-
setTransient
public void setTransient(boolean isTransient) Description copied from class:RepresentationIndicates if the representation's content is transient.- Overrides:
setTransientin classRepresentation- Parameters:
isTransient- True if the representation's content is transient.
-
write
Description copied from class:RepresentationWrites 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.
Note that the class implementing this method shouldn't flush or close the givenOutputStreamafter writing to it as this will be handled by the Restlet connectors automatically.- Specified by:
writein classRepresentation- Parameters:
outputStream- The output stream.- Throws:
IOException
-
write
Description copied from class:RepresentationWrites the representation to a characters writer. 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.
Note that the class implementing this method shouldn't flush or close the givenWriterafter writing to it as this will be handled by the Restlet connectors automatically.- Specified by:
writein classRepresentation- Parameters:
writer- The characters writer.- Throws:
IOException
-