EAF 7.4 API

com.lutris.classloader
Class Resource

java.lang.Object
  extended by com.lutris.classloader.Resource

public abstract class Resource
extends java.lang.Object

A resource that is a file existing on the local machine or a remote machine. The properties of a resource include file name, location, size, and last-modified time. The location of the resource is represented by a ClassPathEntry and is either a directory or a zip file. The file name, described by a String, is relative to the specified location. The resource size is the file size in bytes and the resource time is the last-modified time of the file in milliseconds.

This is an abstract class. All subclasses must determine the size and last-modified time for the resource, and must implement the getInputStream method.

Resources can be ASCII or binary files, such as text files, HTML files, Java source-code files, Java byte-code files, Java archive (JAR) files, and gif files. Some examples resource file names are:

      /users/kristen/text/schedule.txt
      /webserver/htdocs/index.html
      /jdk1.1.5/src/java/util/Enumeration.java
      /jdk1.1.5/classes/java/util/Enumeration.class
      /users/kristen/lutris/lutris.jar
      /webserver/htdocs/banner.gif
 
Since the file names are relative to the location, the beginning slash ("/") does NOT mean that the file name is given as the absolute path on its host machine.

Version:
$Revision : 1.1 $
Author:
Kristen Pol, Lutris Technologies
See Also:
ClassPathEntry

Field Summary
protected  long lastModifiedTime
          The last-modified time of the resource when this object was created.
protected  com.lutris.classloader.ClassPathEntry location
          The location of the resource, which can be local or remote.
protected  LogChannel logChannel
          Log channel to write messages to
protected  boolean loggingEnabled
          Is logging enabled?
protected  int logLevel
          Numeric log level number for LOGLEVEL string
protected  java.lang.String name
          The file name of the resource relative to the location.
protected  long size
          The size of the resource in bytes.
 
Constructor Summary
protected Resource(java.lang.String name, com.lutris.classloader.ClassPathEntry location, LogChannel loadLogChannel)
          Constructs resource with specified name, location and log channel.
 
Method Summary
 boolean equals(Resource resource)
          Determines if the specified resource is equal to this resource.
 byte[] getBytes()
          Gets byte array representing resource.
abstract  long getCurrentLastModifiedTime()
          Get current last-modification time of resource.
abstract  java.io.InputStream getInputStream()
          Gets input stream representing resource.
 long getLastModifiedTime()
          Gets last-modification time of resource at the time this Resource object was created.
 com.lutris.classloader.ClassPathEntry getLocation()
          Gets location of resource set previously by constructor.
 java.lang.String getName()
          Gets file name of resource set previously by constructor.
 long getSize()
          Gets size of resource in bytes.
 long getTime()
          Gets last-modified time of resource in milliseconds.
 boolean hasBeenModified()
          Determine if the resource has been modified since it was loaded.
 java.lang.String toString()
          Stringifies resource described previously by constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
The file name of the resource relative to the location.


location

protected com.lutris.classloader.ClassPathEntry location
The location of the resource, which can be local or remote.


size

protected long size
The size of the resource in bytes.


lastModifiedTime

protected long lastModifiedTime
The last-modified time of the resource when this object was created.


loggingEnabled

protected boolean loggingEnabled
Is logging enabled?


logChannel

protected LogChannel logChannel
Log channel to write messages to


logLevel

protected int logLevel
Numeric log level number for LOGLEVEL string

Constructor Detail

Resource

protected Resource(java.lang.String name,
                   com.lutris.classloader.ClassPathEntry location,
                   LogChannel loadLogChannel)
            throws java.lang.NullPointerException
Constructs resource with specified name, location and log channel. The file name must be described relative to the location. The location, described by the ClassPathEntry, can be a directory or a zip file on the local or a remote machine.

Assumes that all slashes in the name parameter are forward slashes ("/");

Parameters:
name - The file name of the resource.
location - The location of the resource.
loadLogChannel - The log channel for logging.
Throws:
java.lang.NullPointerException - if either the name or location parameters are null.
See Also:
ClassPathEntry
Method Detail

getName

public java.lang.String getName()
Gets file name of resource set previously by constructor.

Returns:
the file name of the resource represented by a String.

getLocation

public com.lutris.classloader.ClassPathEntry getLocation()
Gets location of resource set previously by constructor.

Returns:
the location of the resource represented by a ClassPathEntry.

toString

public java.lang.String toString()
Stringifies resource described previously by constructor. The the file name and location are concatenated together to represent the resource.

Overrides:
toString in class java.lang.Object
Returns:
the resource represented by a String composed of the file name and location.

getSize

public long getSize()
Gets size of resource in bytes.

All subclasses are expected to determine this size prior to this method being called.

Returns:
the size of the resource in bytes.

getLastModifiedTime

public long getLastModifiedTime()
Gets last-modification time of resource at the time this Resource object was created.

All subclasses are expected to determine this time prior to this method being called.

Returns:
the last-modified time of the resource in milliseconds.

getTime

public long getTime()
Gets last-modified time of resource in milliseconds.

See Also:
getlastModifiedTime

getCurrentLastModifiedTime

public abstract long getCurrentLastModifiedTime()
                                         throws java.io.FileNotFoundException
Get current last-modification time of resource. This is the time on the disk file the resource is associated with.

Returns:
the last-modified time of the permanent copy of the resource in milliseconds.
Throws:
java.io.FileNotFoundException

hasBeenModified

public boolean hasBeenModified()
                        throws java.io.FileNotFoundException
Determine if the resource has been modified since it was loaded.

Returns:
true if the resource has been modified, false if not.
Throws:
java.io.FileNotFoundException

getBytes

public byte[] getBytes()
                throws java.io.IOException
Gets byte array representing resource.

This method relies on the implementation of getInputStream.

Returns:
an array of bytes representing the resource.
Throws:
java.io.IOException - if the byte array can not be constructed.

getInputStream

public abstract java.io.InputStream getInputStream()
                                            throws java.io.IOException
Gets input stream representing resource.

This method is abstract and must be implemented by all subclasses. The getBytes method also depends upon this implementation.

Returns:
the input stream that represents the resource.
Throws:
java.io.IOException - if the input stream can not be constructed.

equals

public boolean equals(Resource resource)
Determines if the specified resource is equal to this resource. Resources are considered equal if the file names, locations, sizes, and last-modified times are all the same.

Returns:
true if the resources are equal, false if not.

EAF 7.4 API