Class RJavaClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- RJavaClassLoader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class RJavaClassLoader extends java.net.URLClassLoader
Class loader used internally by rJava The class manages the class paths and the native libraries (jri, ...)
-
-
Field Summary
Fields Modifier and Type Field Description static RJavaClassLoader
primaryLoader
singletonboolean
useSystem
Should the system class loader be used to resolve classes as well as this class loaderstatic boolean
verbose
Print debug messages if is set totrue
-
Constructor Summary
Constructors Constructor Description RJavaClassLoader(java.lang.String path, java.lang.String libpath)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addClassPath(java.lang.String cp)
adds an entry to the class pathvoid
addClassPath(java.lang.String[] cp)
adds several entries to the class pathvoid
addRLibrary(java.lang.String name, java.lang.String path)
add a library to path mapping for a native libraryvoid
bootClass(java.lang.String cName, java.lang.String mName, java.lang.String[] args)
Boots the specified method of the specified classprotected java.lang.Class
findClass(java.lang.String name)
protected java.lang.String
findLibrary(java.lang.String name)
java.net.URL
findResource(java.lang.String name)
java.lang.String[]
getClassPath()
static RJavaClassLoader
getPrimaryLoader()
Returns the singleton instance of RJavaClassLoaderstatic void
main(java.lang.String[] args)
main methodstatic void
setDebug(int level)
Set the debug level.static byte[]
toByte(java.lang.Object object)
Serialize an object to a byte array.java.lang.Object
toObject(byte[] byteArray)
Deserialize an object from a byte array.static java.lang.Object
toObjectPL(byte[] byteArray)
converts the byte array into an Object using the primary RJavaClassLoaderstatic java.lang.String
u2w(java.lang.String fn)
Utility to convert paths for windows.-
Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Field Detail
-
primaryLoader
public static RJavaClassLoader primaryLoader
singleton
-
verbose
public static boolean verbose
Print debug messages if is set totrue
-
useSystem
public boolean useSystem
Should the system class loader be used to resolve classes as well as this class loader
-
-
Method Detail
-
getPrimaryLoader
public static RJavaClassLoader getPrimaryLoader()
Returns the singleton instance of RJavaClassLoader
-
findClass
protected java.lang.Class findClass(java.lang.String name) throws java.lang.ClassNotFoundException
- Overrides:
findClass
in classjava.net.URLClassLoader
- Throws:
java.lang.ClassNotFoundException
-
findResource
public java.net.URL findResource(java.lang.String name)
- Overrides:
findResource
in classjava.net.URLClassLoader
-
addRLibrary
public void addRLibrary(java.lang.String name, java.lang.String path)
add a library to path mapping for a native library
-
addClassPath
public void addClassPath(java.lang.String cp)
adds an entry to the class path
-
addClassPath
public void addClassPath(java.lang.String[] cp)
adds several entries to the class path
-
getClassPath
public java.lang.String[] getClassPath()
- Returns:
- the array of class paths used by this class loader
-
findLibrary
protected java.lang.String findLibrary(java.lang.String name)
- Overrides:
findLibrary
in classjava.lang.ClassLoader
-
bootClass
public void bootClass(java.lang.String cName, java.lang.String mName, java.lang.String[] args) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.NoSuchMethodException, java.lang.ClassNotFoundException
Boots the specified method of the specified class- Parameters:
cName
- class to bootmName
- method to boot (typically main). The method must take a String[] as parameterargs
- arguments to pass to the method- Throws:
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodException
java.lang.ClassNotFoundException
-
setDebug
public static void setDebug(int level)
Set the debug level. At the moment, there is only verbose (level > 0) or quiet- Parameters:
level
- debug level. verbose (>0), quiet otherwise
-
u2w
public static java.lang.String u2w(java.lang.String fn)
Utility to convert paths for windows. Converts / to the path separator in use- Parameters:
fn
- file name
-
main
public static void main(java.lang.String[] args)
main methodThis uses the system properties:
rjava.path
: path of the rJava packagerjava.lib
: lib sub directory of the rJava packagemain.class
: main class to "boot", assumes Main if not specifiedrjava.class.path
: set of paths to populate the initiate the class path
and boots the "main" method of the specified
main.class
, passing the args down to the booted classThis makes sure R and rJava are known by the class loader
-
toByte
public static byte[] toByte(java.lang.Object object) throws java.lang.Exception
Serialize an object to a byte array. (code by CB)- Parameters:
object
- object to serialize- Returns:
- byte array that represents the object
- Throws:
java.lang.Exception
-
toObject
public java.lang.Object toObject(byte[] byteArray) throws java.lang.Exception
Deserialize an object from a byte array. (code by CB)- Parameters:
byteArray
-- Returns:
- the object that is represented by the byte array
- Throws:
java.lang.Exception
-
toObjectPL
public static java.lang.Object toObjectPL(byte[] byteArray) throws java.lang.Exception
converts the byte array into an Object using the primary RJavaClassLoader- Throws:
java.lang.Exception
-
-