org.ckkloverdos.resource
Class ClassLoaderResource

java.lang.Object
  extended by org.ckkloverdos.resource.ClassLoaderResource
All Implemented Interfaces:
IResource, IToStringAware

public class ClassLoaderResource
extends java.lang.Object
implements IResource, IToStringAware

A resource obtained from a class loader. The underlying implementation is URL-based.

Author:
Christos KK Loverdos

Constructor Summary
ClassLoaderResource(java.net.URL url)
          Contructs a new resource whose URL is the provided one.
 
Method Summary
 boolean exists()
          Returns true iff the underlying URL is not null.
 java.io.File getFile()
          Returns a file object generated from the path of the underlying URL.
 java.io.InputStream getInputStream()
          Returns the input stream as obtained from the underlying URL.
 java.lang.String getName()
          Returns the string representation of the underlying resource URL.
 java.net.URL getURL()
          Returns the underlying URL.
 boolean isFile()
          Returns true iff the protocol of the underlying URL is "file".
 java.lang.String toString()
           
 void toStringAware(ToString ts)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassLoaderResource

public ClassLoaderResource(java.net.URL url)
Contructs a new resource whose URL is the provided one. Normally, this URL has been obtained by a class loader call, like: ClassLoader.getResource(String).

Parameters:
url -
Method Detail

getName

public java.lang.String getName()
Returns the string representation of the underlying resource URL.

Specified by:
getName in interface IResource

getURL

public java.net.URL getURL()
Returns the underlying URL.

Specified by:
getURL in interface IResource

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns the input stream as obtained from the underlying URL. If the resource doesnot exist, then null is returned.

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

exists

public boolean exists()
Returns true iff the underlying URL is not null.

Specified by:
exists in interface IResource

isFile

public boolean isFile()
Returns true iff the protocol of the underlying URL is "file".

Specified by:
isFile in interface IResource

getFile

public java.io.File getFile()
Returns a file object generated from the path of the underlying URL. If this resource doesnot represent a file, then null is returned.

Specified by:
getFile in interface IResource

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toStringAware

public void toStringAware(ToString ts)
Specified by:
toStringAware in interface IToStringAware


Copyright © 1999-2007 Christos KK Loverdos. All Rights Reserved.