com.uwyn.rife.tools
Class ClassBytesLoader

java.lang.Object
  extended by com.uwyn.rife.tools.ClassBytesLoader

public class ClassBytesLoader
extends 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%.

Since:
1.6
Version:
$Revision: 3811 $
Author:
Geert Bevin (gbevin[remove] at uwyn dot com)

Constructor Summary
ClassBytesLoader(ClassLoader classLoader)
          Instantiates a new bytes loader for class files.
 
Method Summary
 byte[] getClassBytes(String classFileName)
          Retrieves a byte array that contains the bytecode for a specific Java class.
 byte[] getClassBytes(String classFileName, 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(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(String classFileName)
                     throws 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
ClassNotFoundException
Since:
1.6
See Also:
getClassBytes(String, URL)

getClassBytes

public byte[] getClassBytes(String classFileName,
                            URL classResource)
                     throws 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)
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:
FileUtilsErrorException - if an error occurred during the loading of the class bytes
ClassNotFoundException
Since:
1.6
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

Since:
1.6


Copyright © 2001-2007 Uwyn sprl/bvba. All Rights Reserved.