org.apache.jetspeed.cache.disk
Class JetspeedDiskCacheEntry

java.lang.Object
  extended byorg.apache.jetspeed.cache.disk.JetspeedDiskCacheEntry
All Implemented Interfaces:
DiskCacheEntry

public class JetspeedDiskCacheEntry
extends java.lang.Object
implements DiskCacheEntry

A cache entry represents a data source that can be stored locally for efficiency.

It can deliver a string with its contents, but the preferred way to access to the entry contents is through a Reader that will get characters from it.

There are two kinds of entries:

Remote entries can be in the following states:

TODO: Some data sources need to be written (i. e., are writable). For those, a mechanism need to be provided to write back the resource. We currently think about HTTP PUT as a mechanism.

Version:
$Id: JetspeedDiskCacheEntry.java,v 1.33 2004/02/23 02:45:29 jford Exp $
Author:
Kevin A. Burton, Santiago Gala

Constructor Summary
protected JetspeedDiskCacheEntry(java.io.File file)
          Build a DiskCacheEntry that is based on a cached filesystem entry
  JetspeedDiskCacheEntry(java.lang.String url)
          Build a DiskCacheEntry that is based on a remote URL and may be (or not) backed on disk.
 
Method Summary
 java.lang.String getData()
          Open this URL and read its data, then return it as a string
 long getExpirationTime()
          Set the expiration date of this entry.
 java.io.File getFile()
          Get the File that this URL obtains within the cache.
 java.io.InputStream getInputStream()
          Get an input stream from this entry
 long getLastModified()
          Return the last modified date of this entry.
 java.io.Reader getReader()
          Get a Reader from this entry.
 java.lang.String getSourceURL()
          Reconstruct the original URL based on this URL.
 java.lang.String getURL()
          Get the URL that was cached.
 java.io.Writer getWriter()
          Get a Writer to update this entry.
 boolean hasExpired()
          Test if the entry is expired
 void init()
          Initialize the file variable, if it is null & the url is not local
 boolean isLocal()
          Test if the entry is a Local (fake) disk cache entry
 void setExpirationTime(long time)
          Set the expiration date of this entry.
 void setFile(java.io.File file)
          Set the file.
 void setLastModified(long time)
          Set the last modified date of this entry.
 void setURL(java.lang.String url)
          Set the url on which this is based.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JetspeedDiskCacheEntry

protected JetspeedDiskCacheEntry(java.io.File file)

Build a DiskCacheEntry that is based on a cached filesystem entry

This is used to reconstruct the entries from the cache at boot time


JetspeedDiskCacheEntry

public JetspeedDiskCacheEntry(java.lang.String url)
Build a DiskCacheEntry that is based on a remote URL and may be (or not) backed on disk.

Method Detail

init

public void init()
Initialize the file variable, if it is null & the url is not local


getURL

public java.lang.String getURL()
Description copied from interface: DiskCacheEntry
Get the URL that was cached.

Specified by:
getURL in interface DiskCacheEntry

getSourceURL

public java.lang.String getSourceURL()
Reconstruct the original URL based on this URL.

Specified by:
getSourceURL in interface DiskCacheEntry

getFile

public java.io.File getFile()
Get the File that this URL obtains within the cache.

Specified by:
getFile in interface DiskCacheEntry

setFile

public void setFile(java.io.File file)
Set the file.


getData

public java.lang.String getData()
                         throws java.io.IOException
Open this URL and read its data, then return it as a string

Specified by:
getData in interface DiskCacheEntry
Throws:
java.io.IOException

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Get an input stream from this entry

Specified by:
getInputStream in interface DiskCacheEntry
Throws:
java.io.IOException

getReader

public java.io.Reader getReader()
                         throws java.io.IOException
Get a Reader from this entry. ( Patch for handling character encoding sent by Yoshihiro KANNA ) For local entries, we assume that the URL coming from the WEB server is allright WRT encoding For remote entries, we assume that the cache saved them in the local store using UTF8 encoding

Specified by:
getReader in interface DiskCacheEntry
Throws:
java.io.IOException

getWriter

public java.io.Writer getWriter()
                         throws java.io.IOException
Get a Writer to update this entry. For local entries, we assume that the URL coming from the WEB server allows PUT For remote entries, we throws a IOException

Specified by:
getWriter in interface DiskCacheEntry
Throws:
java.io.IOException

getLastModified

public long getLastModified()
Return the last modified date of this entry.

Specified by:
getLastModified in interface DiskCacheEntry

setLastModified

public void setLastModified(long time)
Set the last modified date of this entry.

Specified by:
setLastModified in interface DiskCacheEntry

setURL

public void setURL(java.lang.String url)
Set the url on which this is based.


getExpirationTime

public long getExpirationTime()
Set the expiration date of this entry.

Specified by:
getExpirationTime in interface DiskCacheEntry

setExpirationTime

public void setExpirationTime(long time)
Set the expiration date of this entry.

Specified by:
setExpirationTime in interface DiskCacheEntry

hasExpired

public boolean hasExpired()
Description copied from interface: DiskCacheEntry
Test if the entry is expired

Specified by:
hasExpired in interface DiskCacheEntry

isLocal

public boolean isLocal()
Description copied from interface: DiskCacheEntry
Test if the entry is a Local (fake) disk cache entry

Specified by:
isLocal in interface DiskCacheEntry


Copyright © 2000-2005 Apache Software Foundation. All Rights Reserved.