com.vwp.net
Class DownloadCacheManager

java.lang.Object
  extended by com.vwp.net.DownloadCacheManager

public class DownloadCacheManager
extends Object

This class handles the download of data (in background) the storage of these data on disk or - if they have been already downloaded - fetching these data from the local cache on disk.


Field Summary
static int BLOCKING
          specifies that data don't have to be downloaded in background; in this case the appropriate method blocks until donwload was completed or an error occured
static int CUSTOMDATA
          specifies that the downloaded file is a custom file where its input stream has to be applied to a PlayThread class after downloading
static int SOUNDSTREAM
          specifies that the downloaded file is a soundfile which has to be applied to a soundnode after downloading
static int TEXTURE
          specifies that the downloaded file is a texture and shall be applied to a Shape3D object after downloading
static int VOLATILE
          specifies that the downloaded file don't has to be stored at the local disk cache
 
Constructor Summary
DownloadCacheManager()
          Public constructor: creates a new DownloadCacheManager object with a default location "cache/" of the directory which contains the cached data
DownloadCacheManager(String CacheIndexDir)
          Public constructor: creates a new DownloadCacheManager object with a non-default location and/or name of the directory which contains the cached data
DownloadCacheManager(String CacheIndexDir, String UserAgent, String Referer)
          Public constructor: creates a new DownloadCacheManager object with a non-default location and/or name of the directory which contains the cached data
 
Method Summary
 byte[] getFile(MessagePipe MyMsgPipe, String FileURL, int DownloadMode)
          Public interface to start loading or downloading a file from cache or network.
 byte[] getFile(MessagePipe MyMsgPipe, String FileURL, int DownloadMode, boolean useFileNameHash)
          Public interface to start loading or downloading a file from cache or network.
 byte[] getFile(MessagePipe MyMsgPipe, String FileURL, int DownloadMode, boolean peekForFile, boolean useFileNameHash)
          Public interface to start loading or downloading a file from cache or network.
 byte[] getFile(MessagePipe MyMsgPipe, String FileURL, int DownloadMode, boolean peekForFile, boolean useFileNameHash, Insets cropImage)
          Public interface to start loading or downloading a file from cache or network.
 byte[] getFile(MessagePipe MyMsgPipe, String FileURL, int DownloadMode, boolean peekForFile, boolean useFileNameHash, int numRetries, int minDlSize)
          Public interface to start loading or downloading a file from cache or network.
 byte[] getFile(MessagePipe MyMsgPipe, String FileURL, int DownloadMode, boolean useFileNameHash, int numRetries, int minDlSize)
          Public interface to start loading or downloading a file from cache or network.
 byte[] getFile(MessagePipe MyMsgPipe, String FileURL, int DownloadMode, int numRetries, int minDlSize)
          Public interface to start loading or downloading a file from cache or network.
 byte[] getFile(MessagePipe MyMsgPipe, String FileURL, int DownloadMode, Object BGObj1, Object BGObj2, Object BGObj3, double scaleImage, int Quality, boolean useFileNameHash)
          Public interface for specific background downloads.
 byte[] getFile(MessagePipe MyMsgPipe, String FileURL, int DownloadMode, Object BGObj1, Object BGObj2, Object BGObj3, double scaleImage, int Quality, boolean useFileNameHash, Insets cropTexture)
          Public interface for specific background downloads.
 byte[] getFile(MessagePipe MyMsgPipe, String FileURL, int DownloadMode, Object BGObj1, Object BGObj2, Object BGObj3, double scaleImage, int Quality, boolean useFileNameHash, Insets cropTexture, int numRetries, int minDlSize)
          Public interface for specific background downloads.
 byte[] getFile(MessagePipe MyMsgPipe, String FileURL, int DownloadMode, Object BGObj1, Object BGObj2, Object BGObj3, double scaleImage, int Quality, boolean useFileNameHash, int numRetries, int minDlSize)
          Public interface for specific background downloads.
 String getFileName(MessagePipe MyMsgPipe, String FileURL, int DownloadMode, boolean useFileNameHash)
          Public interface to start loading or downloading a file from cache or network.
 InputStream getFileStream(MessagePipe MyMsgPipe, String FileURL, int DownloadMode, boolean peekForFile, boolean useFileNameHash)
          Public interface to start loading or downloading a file from cache or network.
 InputStream getFileStream(MessagePipe MyMsgPipe, String FileURL, int DownloadMode, Object BGObj1, Object BGObj2, Object BGObj3, boolean useFileNameHash)
          Public interface for specific background downloads.
 void removeFile(String FileURL, boolean useFileNameHash)
          This method removes a file from the cache Input: FileURL - the complete URL (not URL object) of the file which has to be (down)loaded DownloadMode - the mode of the download specifies if it has to be loaded in background or directly
 void setCacheDir(String CacheIndexDir)
          Changes the location and/or the name of the directory which contains the cached data and the cache index file
 void setStorageEncryptionKey(int[] EncryptionKey)
          Sets a new encryption key which is used for a simple XOR-en/decryption of the stored data so that nobody is able to read the data in the cache.
 void setURLInformation(String UserAgent, String Referer)
          Specifies the data which have to be sent to the server the DownloadCache connects with.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLOCKING

public static final int BLOCKING
specifies that data don't have to be downloaded in background; in this case the appropriate method blocks until donwload was completed or an error occured

See Also:
Constant Field Values

VOLATILE

public static final int VOLATILE
specifies that the downloaded file don't has to be stored at the local disk cache

See Also:
Constant Field Values

TEXTURE

public static final int TEXTURE
specifies that the downloaded file is a texture and shall be applied to a Shape3D object after downloading

See Also:
Constant Field Values

SOUNDSTREAM

public static final int SOUNDSTREAM
specifies that the downloaded file is a soundfile which has to be applied to a soundnode after downloading

See Also:
Constant Field Values

CUSTOMDATA

public static final int CUSTOMDATA
specifies that the downloaded file is a custom file where its input stream has to be applied to a PlayThread class after downloading

See Also:
Constant Field Values
Constructor Detail

DownloadCacheManager

public DownloadCacheManager(String CacheIndexDir,
                            String UserAgent,
                            String Referer)
Public constructor: creates a new DownloadCacheManager object with a non-default location and/or name of the directory which contains the cached data

Parameters:
CacheIndexDir - name of the directory which has to be used to store the downloaded data into
UserAgent - the user agents name
Referer - the referer URL

DownloadCacheManager

public DownloadCacheManager(String CacheIndexDir)
Public constructor: creates a new DownloadCacheManager object with a non-default location and/or name of the directory which contains the cached data

Parameters:
CacheIndexDir - name of the directory which has to be used to store the downloaded data into

DownloadCacheManager

public DownloadCacheManager()
Public constructor: creates a new DownloadCacheManager object with a default location "cache/" of the directory which contains the cached data

Method Detail

setURLInformation

public void setURLInformation(String UserAgent,
                              String Referer)
Specifies the data which have to be sent to the server the DownloadCache connects with.

Parameters:
UserAgent - the user agents name
Referer - the referer URL

setStorageEncryptionKey

public void setStorageEncryptionKey(int[] EncryptionKey)
Sets a new encryption key which is used for a simple XOR-en/decryption of the stored data so that nobody is able to read the data in the cache. If the EncryptionKey is set to null no encryption is performed. Please note: if encrypted data has to be read from disk, this has to be done with the same key as they have been stored with! Additional the XOR encryption is very weak and shouldn't be used for really confidential information!

Parameters:
EncryptionKey - a int-array which specifies the new key, only the lower 8 bytes of every array index are used for de/encryption

setCacheDir

public void setCacheDir(String CacheIndexDir)
Changes the location and/or the name of the directory which contains the cached data and the cache index file

Parameters:
CacheIndexDir - name/path of the new directory which has to be used to ache the data on disk

getFile

public byte[] getFile(MessagePipe MyMsgPipe,
                      String FileURL,
                      int DownloadMode,
                      Object BGObj1,
                      Object BGObj2,
                      Object BGObj3,
                      double scaleImage,
                      int Quality,
                      boolean useFileNameHash)
Public interface for specific background downloads. It calls getFile() below directly but stores the background objects BGObj1 and BGObj2 which are used later to handle the loaded data

Parameters:
MyMsgPipe - a MessagePipe object whci hcan be used to transfer error information from the DownloadCaches background thread to the calling thread
FileURL - URL from which the specified file has to be loaded
DownloadMode -

getFile

public byte[] getFile(MessagePipe MyMsgPipe,
                      String FileURL,
                      int DownloadMode,
                      Object BGObj1,
                      Object BGObj2,
                      Object BGObj3,
                      double scaleImage,
                      int Quality,
                      boolean useFileNameHash,
                      int numRetries,
                      int minDlSize)
Public interface for specific background downloads. It calls getFile() below directly but stores the background objects BGObj1 and BGObj2 which are used later to handle the loaded data

Parameters:
MyMsgPipe - a MessagePipe object whci hcan be used to transfer error information from the DownloadCaches background thread to the calling thread
FileURL - URL from which the specified file has to be loaded
DownloadMode -
numRetries - specifies how often the loader shall try to download a file again if it fails. If 0 is given here it will be tried t oaccess the file once and if this fails, no mor donwloads are tried. Default for this value is 0.
minDlSize - the minimum size a file must have to be accepted as valid

getFile

public byte[] getFile(MessagePipe MyMsgPipe,
                      String FileURL,
                      int DownloadMode,
                      Object BGObj1,
                      Object BGObj2,
                      Object BGObj3,
                      double scaleImage,
                      int Quality,
                      boolean useFileNameHash,
                      Insets cropTexture)
Public interface for specific background downloads. It calls getFile() below directly but stores the background objects BGObj1 and BGObj2 which are used later to handle the loaded data

Parameters:
MyMsgPipe - a MessagePipe object which can be used to transfer error information from the DownloadCaches background thread to the calling thread
FileURL - URL from which the specified file has to be loaded
DownloadMode -
cropTexture - specifies which part of the texture has to be used really

getFile

public byte[] getFile(MessagePipe MyMsgPipe,
                      String FileURL,
                      int DownloadMode,
                      Object BGObj1,
                      Object BGObj2,
                      Object BGObj3,
                      double scaleImage,
                      int Quality,
                      boolean useFileNameHash,
                      Insets cropTexture,
                      int numRetries,
                      int minDlSize)
Public interface for specific background downloads. It calls getFile() below directly but stores the background objects BGObj1 and BGObj2 which are used later to handle the loaded data

Parameters:
MyMsgPipe - a MessagePipe object which can be used to transfer error information from the DownloadCaches background thread to the calling thread
FileURL - URL from which the specified file has to be loaded
DownloadMode -
cropTexture - specifies which part of the texture has to be used really
numRetries - specifies how often the loader shall try to download a file again if it fails. If 0 is given here it will be tried t oaccess the file once and if this fails, no mor donwloads are tried. Default for this value is 0.
minDlSize - the minimum size a file must have to be accepted as valid

getFileName

public String getFileName(MessagePipe MyMsgPipe,
                          String FileURL,
                          int DownloadMode,
                          boolean useFileNameHash)
Public interface to start loading or downloading a file from cache or network. Because the filename is available only when the file is stored in the cache, this method in every case is BLOCKING.

Parameters:
FileURL - the complete URL (not URL object) of the file which has to be (down)loaded
DownloadMode - the mode of the download specifies if it has to be loaded in background or directly
useFileNameHash - use a HasCode instead of a readable FileName
Returns:
the filename of the required data within the cache or null if nothing could be downloaded

getFileStream

public InputStream getFileStream(MessagePipe MyMsgPipe,
                                 String FileURL,
                                 int DownloadMode,
                                 Object BGObj1,
                                 Object BGObj2,
                                 Object BGObj3,
                                 boolean useFileNameHash)
Public interface for specific background downloads. It calls getFileStream() directly but stores the background objects BGObj1 and BGObj2 which are used later to handle the loaded data

Parameters:
MyMsgPipe - a MessagePipe object which can be used to transfer error information from the DownloadCaches background thread to the calling thread
FileURL - URL from which the specified file has to be loaded
DownloadMode -

getFile

public byte[] getFile(MessagePipe MyMsgPipe,
                      String FileURL,
                      int DownloadMode,
                      boolean useFileNameHash)
Public interface to start loading or downloading a file from cache or network. If this method is called directly it has to be called with the DownloadMode BLOCKING typically because no special objects are defined here to handle the downloaded data (which is required for downloads in background) Input: FileURL - the complete URL (not URL object) of the file which has to be (down)loaded DownloadMode - the mode of the download specifies if it has to be loaded in background or directly useFileNameHash - use a HasCode instead of a readable FileName Return: the memory area which contains the (down)loaded data; here null is returned if nothing could be downloaded or if the download already runs (in background mode)


getFile

public byte[] getFile(MessagePipe MyMsgPipe,
                      String FileURL,
                      int DownloadMode,
                      boolean useFileNameHash,
                      int numRetries,
                      int minDlSize)
Public interface to start loading or downloading a file from cache or network. If this method is called directly it has to be called with the DownloadMode BLOCKING typically because no special objects are defined here to handle the downloaded data (which is required for downloads in background)

Parameters:
FileURL - the complete URL (not URL object) of the file which has to be (down)loaded
DownloadMode - the mode of the download specifies if it has to be loaded in background or directly
useFileNameHash - use a HasCode instead of a readable FileName
numRetries - specifies how often the loader shall try to download a file again if it fails. If 0 is given here it will be tried t oaccess the file once and if this fails, no mor donwloads are tried. Default for this value is 0.
minDlSize - the minimum size a file must have to be accepted as valid
Returns:
the memory area which contains the (down)loaded data; here null is returned if nothing could be downloaded or if the download already runs (in background mode)

getFile

public byte[] getFile(MessagePipe MyMsgPipe,
                      String FileURL,
                      int DownloadMode)
Public interface to start loading or downloading a file from cache or network. If this method is called directly it has to be called with the DownloadMode BLOCKING typically because no special objects are defined here to handle the downloaded data (which is required for downloads in background) Input: FileURL - the complete URL (not URL object) of the file which has to be (down)loaded DownloadMode - the mode of the download specifies if it has to be loaded in background or directly Return: the memory area which contains the (down)loaded data; here null is returned if nothing could be downloaded or if the download already runs (in background mode)


getFile

public byte[] getFile(MessagePipe MyMsgPipe,
                      String FileURL,
                      int DownloadMode,
                      int numRetries,
                      int minDlSize)
Public interface to start loading or downloading a file from cache or network. If this method is called directly it has to be called with the DownloadMode BLOCKING typically because no special objects are defined here to handle the downloaded data (which is required for downloads in background)

Parameters:
FileURL - the complete URL (not URL object) of the file which has to be (down)loaded
DownloadMode - the mode of the download specifies if it has to be loaded in background or directly
numRetries - specifies how often the loader shall try to download a file again if it fails. If 0 is given here it will be tried t oaccess the file once and if this fails, no mor donwloads are tried. Default for this value is 0.
minDlSize - the minimum size a file must have to be accepted as valid
Returns:
the memory area which contains the (down)loaded data; here null is returned if nothing could be downloaded or if the download already runs (in background mode)

getFile

public byte[] getFile(MessagePipe MyMsgPipe,
                      String FileURL,
                      int DownloadMode,
                      boolean peekForFile,
                      boolean useFileNameHash)
Public interface to start loading or downloading a file from cache or network. If this method is called directly it has to be called with the DownloadMode BLOCKING typically because no special objects are defined here to handle the downloaded data (which is required for downloads in background) Input: FileURL - the complete URL (not URL object) of the file which has to be (down)loaded DownloadMode - the mode of the download specifies if it has to be loaded in background or directly peekForFile - is this value is set to true we only look if this file exists in the cache; this is neccessary e.g. in cases where it is unknown which special format a file has (.jpg, .gif, .png) and we do not want to establish a URL-connection for every try when it already exists in cache useFileNameHash - use a HasCode instead of a readable FileName Return: the memory area which contains the (down)loaded data; here null is returned if nothing could be downloaded or if the download already runs (in background mode)


getFile

public byte[] getFile(MessagePipe MyMsgPipe,
                      String FileURL,
                      int DownloadMode,
                      boolean peekForFile,
                      boolean useFileNameHash,
                      int numRetries,
                      int minDlSize)
Public interface to start loading or downloading a file from cache or network. If this method is called directly it has to be called with the DownloadMode BLOCKING typically because no special objects are defined here to handle the downloaded data (which is required for downloads in background)

Parameters:
FileURL - the complete URL (not URL object) of the file which has to be (down)loaded DownloadMode - the mode of the download specifies if it has to be loaded in background or directly
peekForFile - - is this value is set to true we only look if this file exists in the cache; this is neccessary e.g. in cases where it is unknown which special format a file has (.jpg, .gif, .png) and we do not want to establish a URL-connection for every try when it already exists in cache
useFileNameHash - - use a HasCode instead of a readable FileName
numRetries - specifies how often the loader shall try to download a file again if it fails. If 0 is given here it will be tried t oaccess the file once and if this fails, no mor donwloads are tried. Default for this value is 0.
minDlSize - the minimum size a file must have to be accepted as valid
Returns:
the memory area which contains the (down)loaded data; here null is returned if nothing could be downloaded or if the download already runs (in background mode)

getFile

public byte[] getFile(MessagePipe MyMsgPipe,
                      String FileURL,
                      int DownloadMode,
                      boolean peekForFile,
                      boolean useFileNameHash,
                      Insets cropImage)
Public interface to start loading or downloading a file from cache or network. If this method is called directly it has to be called with the DownloadMode BLOCKING typically because no special objects are defined here to handle the downloaded data (which is required for downloads in background)

Parameters:
FileURL - the complete URL (not URL object) of the file which has to be (down)loaded
DownloadMode - the mode of the download specifies if it has to be loaded in background or directly
peekForFile - is this value is set to true we only look if this file exists in the cache; this is neccessary e.g. in cases where it is unknown which special format a file has (.jpg, .gif, .png) and we do not want to establish a URL-connection for every try when it already exists in cache
useFileNameHash - use a HasCode instead of a readable FileName
cropImage - specifies if a downloaded texture has to be cropped, this param can be set to null if no image has to be downloaded or if the image doesn'T has to be cropped
Returns:
the memory area which contains the (down)loaded data; here null is returned if nothing could be downloaded or if the download already runs (in background mode)

getFileStream

public InputStream getFileStream(MessagePipe MyMsgPipe,
                                 String FileURL,
                                 int DownloadMode,
                                 boolean peekForFile,
                                 boolean useFileNameHash)
Public interface to start loading or downloading a file from cache or network. If this method is called directly it has to be called with the DownloadMode BLOCKING typically because no special objects are defined here to handle the downloaded data (which is required for downloads in background) Input: FileURL - the complete URL (not URL object) of the file which has to be (down)loaded DownloadMode - the mode of the download specifies if it has to be loaded in background or directly peekForFile - is this value is set to true we only look if this file exists in the cache; this is neccessary e.g. in cases where it is unknown which special format a file has (.jpg, .gif, .png) and we do not want to establish a URL-connection for every try when it already exists in cache useFileNameHash - use a HasCode instead of a readable FileName Return: the InputStream to the file with the downloaded data; here null is returned if nothing could be downloaded or if the download already runs (in background mode)


removeFile

public void removeFile(String FileURL,
                       boolean useFileNameHash)
This method removes a file from the cache Input: FileURL - the complete URL (not URL object) of the file which has to be (down)loaded DownloadMode - the mode of the download specifies if it has to be loaded in background or directly