PulpCore

pulpcore
Class Assets

java.lang.Object
  extended by pulpcore.Assets

public class Assets
extends Object

The Assets class provided a central location to retrieve game assets (images, fonts, sounds, etc.) from the jar or from zip files.


Method Summary
static boolean addCatalog(String catalogName, byte[] zipFileData)
          Adds the contents of an asset catalog (zip file) into memory.
static boolean addCatalog(String catalogName, InputStream is)
          Adds the contents of an asset catalog (zip file) into memory.
static boolean containsAsset(String assetName)
          Returns true if the specified asset in any zip file exists.
static boolean containsCatalog(String catalogName)
          Checks if the specified catalog name (zip file) is stored in memory.
static ByteArray get(String assetName)
          Gets an asset as a ByteArray.
static Iterator getAssetNames()
          Gets an iterator of the names of all assets from all zip files stored in memory.
static InputStream getAsStream(String assetName)
          Gets an asset as an InputStream.
static Iterator getCatalogs()
          Gets an iterator of catalog names (zip files) stored in memory.
static void removeAsset(String assetName)
          Removes a specific asset from memory.
static void removeCatalog(String catalogName)
          Removes all assets downloaded from the specified catalog (zip file).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addCatalog

public static boolean addCatalog(String catalogName,
                                 byte[] zipFileData)
Adds the contents of an asset catalog (zip file) into memory.

If this catalog contains an asset that has the same name as an existing asset, the old asset is replaced with the new one. If this zip file contains errors, no existing assets are affected and this method returns false.

Parameters:
zipFileData - a zip file
Returns:
true on success; false otherwise.

addCatalog

public static boolean addCatalog(String catalogName,
                                 InputStream is)
Adds the contents of an asset catalog (zip file) into memory.

If this catalog contains an asset that has the same name as an existing asset, the old asset is replaced with the new one. If this zip file contains errors, no existing assets are affected and this method returns false.

Parameters:
is - an input stream that points to the contents of a zip file.
Returns:
true on success; false otherwise.

getCatalogs

public static Iterator getCatalogs()
Gets an iterator of catalog names (zip files) stored in memory.


containsCatalog

public static boolean containsCatalog(String catalogName)
Checks if the specified catalog name (zip file) is stored in memory.


removeCatalog

public static void removeCatalog(String catalogName)
Removes all assets downloaded from the specified catalog (zip file).


getAssetNames

public static Iterator getAssetNames()
Gets an iterator of the names of all assets from all zip files stored in memory. Does not include assets in the jar file.


containsAsset

public static boolean containsAsset(String assetName)
Returns true if the specified asset in any zip file exists. Does not check the jar.


removeAsset

public static void removeAsset(String assetName)
Removes a specific asset from memory.


get

public static ByteArray get(String assetName)
Gets an asset as a ByteArray.

This method first checks the downloaded asset catalogs, then the jar file. For some platforms (Applets), the originating server is also checked if the asset is not in the zip file(s) or the jar file. Returns null if the asset was not found.

The returned ByteArray's position is set to zero.


getAsStream

public static InputStream getAsStream(String assetName)
Gets an asset as an InputStream.

This method first checks the downloaded asset catalogs, then the jar file. For some platforms (Applets), the originating server is also checked if the asset is not in the zip file(s) or the jar file. Returns null if the asset was not found.


PulpCore

Copyright © 2007-2009 Interactive Pulp, LLC.