edu.emory.mathcs.util.classloader
Class ResourceHandle

java.lang.Object
  extended byedu.emory.mathcs.util.classloader.ResourceHandle

public abstract class ResourceHandle
extends java.lang.Object

This class represents a handle (a connection) to some resource, which may be a class, native library, text file, image, etc. Handles are returned by ResourceLoader's get methods. Having the resource handle, in addition to accessing the resource data (using methods getInputStream() or getBytes()) as well as access resource metadata, such as attributes, certificates, etc.

As soon as the handle is no longer in use, it should be explicitly close()d, similarly to I/O streams.

Version:
1.0
Author:
Dawid Kurzyniec

Constructor Summary
ResourceHandle()
           
 
Method Summary
 void close()
          Closes a connection to the resource indentified by this handle.
 java.util.jar.Attributes getAttributes()
          Return the Attributes of the resource, or null if none.
 byte[] getBytes()
          Returns this resource data as an array of bytes.
 java.security.cert.Certificate[] getCertificates()
          Return the Certificates of the resource, or null if none.
abstract  java.net.URL getCodeSourceURL()
          Returns the CodeSource URL for the class or resource.
abstract  int getContentLength()
          Returns the length of this resource data, or -1 if unknown.
abstract  java.io.InputStream getInputStream()
          Returns and InputStream for reading this resource data.
 java.util.jar.Manifest getManifest()
          Returns the Manifest of the JAR file from which this resource was loaded, or null if none.
abstract  java.lang.String getName()
          Return the name of the resource.
abstract  java.net.URL getURL()
          Returns the URL of the resource.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResourceHandle

public ResourceHandle()
Method Detail

getName

public abstract java.lang.String getName()
Return the name of the resource. The name is a "/"-separated path name that identifies the resource.


getURL

public abstract java.net.URL getURL()
Returns the URL of the resource.


getCodeSourceURL

public abstract java.net.URL getCodeSourceURL()
Returns the CodeSource URL for the class or resource.


getInputStream

public abstract java.io.InputStream getInputStream()
                                            throws java.io.IOException
Returns and InputStream for reading this resource data.

Throws:
java.io.IOException

getContentLength

public abstract int getContentLength()
Returns the length of this resource data, or -1 if unknown.


getBytes

public byte[] getBytes()
                throws java.io.IOException
Returns this resource data as an array of bytes.

Throws:
java.io.IOException

getManifest

public java.util.jar.Manifest getManifest()
                                   throws java.io.IOException
Returns the Manifest of the JAR file from which this resource was loaded, or null if none.

Throws:
java.io.IOException

getCertificates

public java.security.cert.Certificate[] getCertificates()
Return the Certificates of the resource, or null if none.


getAttributes

public java.util.jar.Attributes getAttributes()
                                       throws java.io.IOException
Return the Attributes of the resource, or null if none.

Throws:
java.io.IOException

close

public void close()
Closes a connection to the resource indentified by this handle. Releases any I/O objects associated with the handle.


toString

public java.lang.String toString()