abstract const classafBedSheet::Asset
sys::Obj afBedSheet::Asset
(Response Object) - An asset, such as File
, which may be sent to the client.
An Asset
instance wraps up all the information needed to send it to a client. The corresponding Asset ResponseProcessor sets the following HTTP headers:
Cache-Control
Content-Length
Content-Type
ETag
Last-Modified
Should the request headers allow, it may also respond with a 304 - Modified
response. The Asset ResponseProcessor also correctly responds to HEAD requests.
When serving up your own files and images (say, from a database), it is recommended that your Route Handler return a custom Asset
instance, from your own Asset
subclass.
You may also wish to consider returning a ClientAsset.
- contentType
abstract MimeType? contentType()
Returns the content type for the asset.
Returns
null
if asset doesn't exist.- etag
virtual Str? etag()
The ETag uniquely identifies the asset and its version. The default implementation is a hash of the modified time and the asset size.
Returns
null
if asset doesn't exist- exists
virtual Bool exists()
Returns
true
if the asset exists. (Or did at the time this class was created.)Returns
true
by default.- in
abstract InStream? in()
Creates an
InStream
to read the contents of the asset. A new stream should be created each timein()
is called.Returns
null
if asset doesn't exist, or can't be opened. (For example, if the asset is a recently deleted file resource).The caller is responsible for closing the stream. Note this can be as easy as calling
in.readAllBuf()
orin.readAllStr()
.- makeFromFile
static new makeFromFile(File file)
Creates a
Asset
for the given file.To create a
ClientAsset
use theFileHandler
orPodHandler
service:fileHandler.fromServerFile(file)
- modified
abstract DateTime? modified()
Get the modified time of the asset. Note that pod files have last modified info too!
Returns
null
if asset doesn't exist- size
abstract Int? size()
The size of the asset in bytes.
Returns
null
if asset doesn't exist