net.sf.jzeno.classloader
Class ClassBytesLoader

java.lang.Object
  extended by net.sf.jzeno.classloader.ClassBytesLoader

public class ClassBytesLoader
extends java.lang.Object

Utility class to load the bytes of class files.

After instantiating it, the setupSunByteLoading()Â method can optionally be called to let the class detect if it's possible to interface with a private API that's specific to the Sun JVM. This interface can improve class byte loading performance by 40%.


Constructor Summary
ClassBytesLoader(java.lang.ClassLoader classLoader)
          Instantiates a new bytes loader for class files.
 
Method Summary
 byte[] getClassBytes(java.lang.String classFileName)
          Retrieves a byte array that contains the bytecode for a specific Java class.
 byte[] getClassBytes(java.lang.String classFileName, java.net.URL classResource)
          Retrieves a byte array that contains the bytecode for a specific Java class.
 boolean isUsingSunByteLoading()
          Indicates whether this class is using the private Sun JVM interface to speed up class bytes loading.
 boolean setupSunByteLoading()
          Tries to setup an interaction with a private Sun JVM interface that can speed up class bytes loading by 40%, when available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassBytesLoader

public ClassBytesLoader(java.lang.ClassLoader classLoader)
Instantiates a new bytes loader for class files.

Parameters:
classLoader - the classloader that should be used to search for the classes
Since:
1.6
Method Detail

setupSunByteLoading

public boolean setupSunByteLoading()
Tries to setup an interaction with a private Sun JVM interface that can speed up class bytes loading by 40%, when available.

Returns:
true when the interaction with the private Sun JVM interface could be setup; or

false otherwise


getClassBytes

public byte[] getClassBytes(java.lang.String classFileName)
                     throws java.lang.ClassNotFoundException
Retrieves a byte array that contains the bytecode for a specific Java class.

Parameters:
classFileName - the file name of the class whose bytes should be loaded, note that this is not the Java FQN (com.uwyn.rife.Version), but the real name of the file resource (com/uwyn/rife/Version.java)
Returns:
an array with the bytes of the class; or

null if no bytes could be loaded

Throws:
FileUtilsErrorException - if an error occurred during the loading of the class bytes
java.lang.ClassNotFoundException
See Also:
getClassBytes(String, URL)

getClassBytes

public byte[] getClassBytes(java.lang.String classFileName,
                            java.net.URL classResource)
                     throws java.lang.ClassNotFoundException
Retrieves a byte array that contains the bytecode for a specific Java class.

Parameters:
classFileName - the file name of the class whose bytes should be loaded
classResource - the resource that can be used to load the class bytes from if it couldn't be obtained by using the file name, if no resource is provided and the bytes couldn't be loaded by simply using the class' file name, a resource will be looked up for the file name through the class loader that was provided to the constructor
Returns:
an array with the bytes of the class; or

null if no bytes could be loaded

Throws:
java.lang.ClassNotFoundException - if an error occurred during the loading of the class bytes
See Also:
getClassBytes(String)

isUsingSunByteLoading

public boolean isUsingSunByteLoading()
Indicates whether this class is using the private Sun JVM interface to speed up class bytes loading.

Returns:
true when this class is using the private Sun JVM interface; or

false if this is not the case