org.jdesktop.wonderland.client.assetmgr
Class AssetStream

java.lang.Object
  extended by org.jdesktop.wonderland.client.assetmgr.AssetStream
Direct Known Subclasses:
ModuleAssetStream, WlContentAssetStream, WlHttpAssetStream

public abstract class AssetStream
extends java.lang.Object

The AssetStream class represents a stream from which the asset manager can download data, or get an indication that the asset already exists cached within the system.

This abstract base class is subclassed by protocol-specific handlers, for example, wla (for module assets), that compute the proper checksums once the asset data is download.

For asset streams with response of STREAM_READY, the connect() method must be called first, before calls to getChecksum(), getContentLength() and getInputStream(). Calls to these methods before the connect() method is called will return invalid results. The close() method should be called when complete.

Author:
Jordan Slott

Nested Class Summary
static class AssetStream.AssetResponse
          An enumeration that indicates the status of the stream: STREAM_READY: An input stream is available to be read of the asset data ASSET_CACHED: The desired asset is already cached by the asset manager ASSET_INVALID: The repository does not contain the proper asset
 
Field Summary
protected static java.util.logging.Logger logger
           
 
Constructor Summary
protected AssetStream(AssetStream.AssetResponse response, AssetURI uri, java.lang.String baseURL)
          Constructs an AssetStream with the given response cached asset id or asset input stream
 
Method Summary
abstract  void close()
          Invoked when the user of this class is done reading data from the stream and wants the AssetStream to do any cleanup.
 AssetURI getAssetURI()
          Returns the asset uri associated with this stream.
 java.lang.String getBaseURL()
          Returns the base URL from which the asset will be downloaded, or null if the asset is not found or is alredy cached.
abstract  AssetCache.CachePolicy getCachePolicy()
          Returns the desired cache policy for the asset: whether to allow multiple copies of the same asset uri or only a single instance.
abstract  java.lang.String getChecksum()
          Returns the asset checksum (a string that identifies the asset) after the open() method has been called.
abstract  int getContentLength()
          Returns the length of the content (bytes) in the stream.
abstract  java.io.InputStream getInputStream()
          Returns an input stream suitable to read the data, or null if the asset is already cached or the repository contains invalid data.
 AssetStream.AssetResponse getResponse()
          Returns the response of the stream to creation: whether the asset is already cached (ASSET_CACHED), whether the stream is invalid (ASSET_INVALID) or whether the asset is ready to be downloaded (STREAM_READY)
abstract  void open()
          Opens the asset stream for reading.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static java.util.logging.Logger logger
Constructor Detail

AssetStream

protected AssetStream(AssetStream.AssetResponse response,
                      AssetURI uri,
                      java.lang.String baseURL)
Constructs an AssetStream with the given response cached asset id or asset input stream

Method Detail

getBaseURL

public java.lang.String getBaseURL()
Returns the base URL from which the asset will be downloaded, or null if the asset is not found or is alredy cached.

Returns:
The base URL of the asset to download

getAssetURI

public AssetURI getAssetURI()
Returns the asset uri associated with this stream.

Returns:
The AssetURI object

getResponse

public AssetStream.AssetResponse getResponse()
Returns the response of the stream to creation: whether the asset is already cached (ASSET_CACHED), whether the stream is invalid (ASSET_INVALID) or whether the asset is ready to be downloaded (STREAM_READY)

Returns:
The AssetResponse enumeration

getInputStream

public abstract java.io.InputStream getInputStream()
Returns an input stream suitable to read the data, or null if the asset is already cached or the repository contains invalid data.

Returns:
An InputStream object

open

public abstract void open()
Opens the asset stream for reading. This method must be called before getInputStream(), getChecksum(), and getContentLength() methods.


close

public abstract void close()
Invoked when the user of this class is done reading data from the stream and wants the AssetStream to do any cleanup.


getChecksum

public abstract java.lang.String getChecksum()
Returns the asset checksum (a string that identifies the asset) after the open() method has been called.

Returns:
A String checksum

getContentLength

public abstract int getContentLength()
Returns the length of the content (bytes) in the stream. Returns -1 if the content lenght is not know. This method must be called after the open() method is invoked.

Returns:
The length of content in the stream.

getCachePolicy

public abstract AssetCache.CachePolicy getCachePolicy()
Returns the desired cache policy for the asset: whether to allow multiple copies of the same asset uri or only a single instance.

Returns:
The CachePolicy


Open Wonderland - http://openwonderland.org