wyvern.common.tiles
Class FileCache

java.lang.Object
  extended bywyvern.common.tiles.FileCache

public class FileCache
extends java.lang.Object

Serves up image files as byte arrays, for sending to clients. Keeps an in-memory cache of files that have already been loaded.

Version:
1.0, Jul 26, 2000
Author:
Steve Yegge

Constructor Summary
FileCache()
           
 
Method Summary
static long getTimestamp(java.lang.String path)
          Retrieves the last-modified "date" for a file.
static byte[] loadFile(java.lang.String path)
          Synchronously reads the bytes of the specified file.
static byte[] readFileBytes(java.lang.String filepath)
          Until I know whether our own file cache is really necessary, I'm going to rely on the disk cache being fast.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileCache

public FileCache()
Method Detail

loadFile

public static byte[] loadFile(java.lang.String path)
                       throws java.io.IOException
Synchronously reads the bytes of the specified file.

Parameters:
path - relative path to the image file. If it starts with "wiz/", looks under the wiz dir, else looks under the default artwork dir.
Returns:
the bytes of the image, compressed, since all our images are GIFs or PNGs that are already compressed.
Throws:
java.io.IOException

readFileBytes

public static byte[] readFileBytes(java.lang.String filepath)
                            throws java.io.IOException
Until I know whether our own file cache is really necessary, I'm going to rely on the disk cache being fast.

Parameters:
filepath - the absolute path to the file
Throws:
java.io.IOException

getTimestamp

public static long getTimestamp(java.lang.String path)
Retrieves the last-modified "date" for a file. Actually, keeps a cached version that could potentially be out of date. There's a reason for that - we only re-load the file data in loadFile if the cached timestamp is different from the "current" timestamp.

Parameters:
path - the relative path to the art file
Returns:
the timestamp, or -1 if it's not found