com.croftsoft.core.lang
Class ClassLib

java.lang.Object
  extended by com.croftsoft.core.lang.ClassLib

public final class ClassLib
extends Object

Static methods to complement the java.lang.Class methods.

Since:
2001-07-24
Version:
2002-10-29
See Also:
Class
Author:
David Wallace Croft

Method Summary
static Image getResourceAsImage(Class relativeClass, String filename)
          Loads an Image as a class resource.
static String getResourceAsText(Class relativeClass, String filename)
          Loads a resource into memory as a String.
static String getShortName(Class c)
          Returns the name of the Class without the package prefix.
static void main(String[] args)
           
static boolean test(String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

main

public static void main(String[] args)

test

public static boolean test(String[] args)

getResourceAsText

public static String getResourceAsText(Class relativeClass,
                                       String filename)
                                throws IOException
Loads a resource into memory as a String.

Useful for loading a text file from a JAR on the classpath.

Implemented using Class.getResourceAsStream(). Review of the documentation of this method is advised in order to understand the relative search path.

Parameters:
relativeClass - The Class used for the text file search.
filename - The path to the file, usually started by "/".
Throws:
IOException
See Also:
Class.getResourceAsStream(java.lang.String)

getResourceAsImage

public static Image getResourceAsImage(Class relativeClass,
                                       String filename)
                                throws IOException
Loads an Image as a class resource.

Useful for when you need to load an image file from a JAR.

Throws:
IOException
See Also:
"Zukowski, Definitive Guide to Swing for Java 2, Second Edition, 2000, p107."

getShortName

public static String getShortName(Class c)
Returns the name of the Class without the package prefix.

For example, this method would return "ClassLib" for class com.croftsoft.core.lang.ClassLib.

See Also:
java.lang.Class#getName(java.lang.String)

CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)