Purple Code

com.purpletech.io
Class URLCache

java.lang.Object
  |
  +--com.purpletech.io.URLCache

public class URLCache
extends java.lang.Object

Maintains a cache of files on disk.


Nested Class Summary
protected  class URLCache.DefaultFetcher
           
static class URLCache.Error
           
static interface URLCache.Fetcher
           
 
Constructor Summary
URLCache(java.lang.String dir)
           
URLCache(java.lang.String dir, long msec)
           
 
Method Summary
static void debug(java.lang.String x)
           
 java.io.File get(java.lang.String source)
          Takes an http: URL, a file: URL, or a raw file system pathname.
 java.io.File get(java.lang.String source, URLCache.Fetcher fetcher)
           
 URLCache.Fetcher getDefaultFetcher()
           
 URLCache.Error getError(java.lang.String source)
           
static boolean isDiff(java.io.File a, java.io.File b)
           
static boolean isDiff(java.io.InputStream a, java.io.InputStream b)
           
static void main(java.lang.String[] args)
           
static java.lang.String mapName(java.lang.String in)
          convert a name to a filesystem-safe name.
 void setAllowEmpty(boolean allow)
          do we allow empty files to replace non-empty cache files?
 void setAllowLocal(boolean allow)
          do we allow local file access or just HTTP?
 void setCacheDir(java.lang.String dirname)
           
static void setDebug(boolean f)
           
 void setDownloadTimeout(long msec)
          number of milliseconds we attempt to download something before failing
protected  void setError(java.lang.String source, java.lang.Throwable exception)
           
 void setTimeout(long msec)
          number of milliseconds we keep something in the cache before refetching
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLCache

public URLCache(java.lang.String dir)
         throws java.io.IOException

URLCache

public URLCache(java.lang.String dir,
                long msec)
         throws java.io.IOException
Method Detail

setDebug

public static void setDebug(boolean f)

setCacheDir

public void setCacheDir(java.lang.String dirname)
                 throws java.io.IOException
java.io.IOException

setAllowLocal

public void setAllowLocal(boolean allow)
do we allow local file access or just HTTP?


setAllowEmpty

public void setAllowEmpty(boolean allow)
do we allow empty files to replace non-empty cache files?


setTimeout

public void setTimeout(long msec)
number of milliseconds we keep something in the cache before refetching


setDownloadTimeout

public void setDownloadTimeout(long msec)
number of milliseconds we attempt to download something before failing


getDefaultFetcher

public URLCache.Fetcher getDefaultFetcher()

get

public java.io.File get(java.lang.String source)
Takes an http: URL, a file: URL, or a raw file system pathname. Returns a file, whose LastModified date represents the last time it was downloaded and was new.

Is not thread-safe. Todo: make a thread-safe Map of currently-downloading files. Compare the source to the contents of that map and block until it's free. Then when it comes out it will check the timestamp and probably notice that it was just downloaded.


get

public java.io.File get(java.lang.String source,
                        URLCache.Fetcher fetcher)

mapName

public static java.lang.String mapName(java.lang.String in)
convert a name to a filesystem-safe name. The current algorithm is a little flawed, and will occasionally map two files to the same name. This should be fixed.


isDiff

public static boolean isDiff(java.io.File a,
                             java.io.File b)
                      throws java.io.IOException
java.io.IOException

isDiff

public static boolean isDiff(java.io.InputStream a,
                             java.io.InputStream b)
                      throws java.io.IOException
java.io.IOException

debug

public static void debug(java.lang.String x)

getError

public URLCache.Error getError(java.lang.String source)

setError

protected void setError(java.lang.String source,
                        java.lang.Throwable exception)

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
java.io.IOException

Documentation generated March 5 2003