net.larsan.urd.util.fileset
Class ResourceBase

java.lang.Object
  |
  +--net.larsan.urd.util.fileset.ResourceBase
All Implemented Interfaces:
Resource
Direct Known Subclasses:
FileResource, JarFileSet.JarResource

public abstract class ResourceBase
extends java.lang.Object
implements Resource

Abstract base class for resources. This class keeps track size, visited time path and an error handler.

Version:
Alpha-0.1 / 2002-10-06 21:37
Author:
Lars J. Nilsson

Field Summary
protected  ErrorHandler errorHandler
          Error handler
protected  java.lang.String filePath
          File path, relative to the file set root folder.
protected  long size
          Optional file size in bytes, defaults to -1 if not set.
protected  long visited
          Exact time the file was visited in milliconds since epoch.
 
Constructor Summary
ResourceBase(java.lang.String filePath)
          Construct file resource with a path with a visited time set to the current system time.
ResourceBase(java.lang.String filePath, long visited, ErrorHandler errorHandler)
          Construct file resource with a path and a visited time.
 
Method Summary
 boolean equals(java.lang.Object o)
          Equality check on the relative path.
abstract  boolean exists()
          Check if the resource is valid.
abstract  byte[] getBytes()
          Get a byte array from the file.
abstract  java.security.cert.Certificate[] getCertificates()
          Get resource Certificates if the resource have been signed.
 ErrorHandler getErrorHandler()
          Get the error handler for this resource.
 long getFileSize()
          Get file size in bytes.
 java.lang.String getPath()
          Get file path, this path will not start with a separator and should be relative to the file set root and case sensitive.
abstract  java.io.InputStream getStream()
          Get a byte stream from the file.
abstract  java.net.URL getURL()
          Get a URL to the resource.
 long getVisitedTime()
          Get visited time in milliseconds.
 int hashCode()
          Hash code based on the relative file path.
protected  java.lang.Object report(java.io.IOException e)
          Report an IO exception to the error handle of the enclosing file set.
 void setErrorHandler(ErrorHandler errorHandler)
          Set the error handler for this resource.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.larsan.urd.util.Resource
getCodeSource
 

Field Detail

errorHandler

protected ErrorHandler errorHandler
Error handler


visited

protected long visited
Exact time the file was visited in milliconds since epoch. This value should be update on rescans.


filePath

protected java.lang.String filePath
File path, relative to the file set root folder. The path should not start with a separator, 'path/name' as opposed to '/path/name'


size

protected long size
Optional file size in bytes, defaults to -1 if not set.

Constructor Detail

ResourceBase

public ResourceBase(java.lang.String filePath,
                    long visited,
                    ErrorHandler errorHandler)
Construct file resource with a path and a visited time. The file path must not be null.

Parameters:
filePath - Resource path, must not be null
visited - Time of resource visitation
errorHandler - Error handler to use, may be null

ResourceBase

public ResourceBase(java.lang.String filePath)
Construct file resource with a path with a visited time set to the current system time. The file path must not be null.

Parameters:
filePath - Resource path, must not be null
Method Detail

getStream

public abstract java.io.InputStream getStream()
Get a byte stream from the file. Should the resource have been disabled or removed before this method is called it will return null.

Specified by:
getStream in interface Resource
Returns:
An input stream from the file, or null if disabled

getBytes

public abstract byte[] getBytes()
Get a byte array from the file. Should the resource have been disabled or removed before this method is called it will return null.

Specified by:
getBytes in interface Resource
Returns:
The resource as a byte array, or null if disabled

getURL

public abstract java.net.URL getURL()
Get a URL to the resource. Should the resource have been disabled or removed before this method is called it will return null.

Specified by:
getURL in interface Resource
Returns:
The resource URL, or null if disabled

getCertificates

public abstract java.security.cert.Certificate[] getCertificates()
Get resource Certificates if the resource have been signed. This method should return null if the class/resource is not signed.

Specified by:
getCertificates in interface Resource
Returns:
The certificates for a signed resources, or null if not signed

exists

public abstract boolean exists()
Check if the resource is valid. This should return false if the underlying file have is removed or unusable.

Returns:
True if the resource is still valid

getPath

public java.lang.String getPath()
Get file path, this path will not start with a separator and should be relative to the file set root and case sensitive.

Specified by:
getPath in interface Resource
Returns:
The file path relative to the set root

getVisitedTime

public long getVisitedTime()
Get visited time in milliseconds.

Returns:
The time in milliseconds since epoch when the file was last visited

getFileSize

public long getFileSize()
Get file size in bytes. This method return -1 if not set.

Returns:
The file size in bytes or -1 if not known

equals

public boolean equals(java.lang.Object o)
Equality check on the relative path. Two files with the same path are considered equal.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Hash code based on the relative file path.

Overrides:
hashCode in class java.lang.Object

getErrorHandler

public ErrorHandler getErrorHandler()
Get the error handler for this resource. If no error handle is specified this method return null.

Returns:
An error handler for the resource

setErrorHandler

public void setErrorHandler(ErrorHandler errorHandler)
Set the error handler for this resource. The error handler will be used on IO errors when reading resources.

Parameters:
errorHandler - Error handler for this resource

report

protected java.lang.Object report(java.io.IOException e)
Report an IO exception to the error handle of the enclosing file set. If no error handler is set this emthod uses the standard error out stream.

This method only returns null.

Parameters:
e - IOException to report
Returns:
Always null