Java Utililty Methods ClassLoader Load

List of utility methods to do ClassLoader Load

Description

The list of methods to do ClassLoader Load are organized into topic(s).

Method

CollectiongetProhibitedProxyInterfaces()
Returns collection of prohibited proxy interfaces read from resources.
Collection names = new HashSet();
names.add("javax.management.MBeanServerConnection");
Enumeration resources;
try {
    resources = ClassLoader.getSystemResources(prohibitedProxyInterfacesResource);
} catch (IOException e) {
    throw new ExceptionInInitializerError(
            new IOException("problem getting resources: " + prohibitedProxyInterfacesResource)
...
PropertiesgetProperties(String bundleName, String fileName)
get Properties
Properties props = new Properties();
try {
    if (Platform.isRunning()) {
        Bundle bundle = Platform.getBundle(bundleName);
        URL url = bundle.getResource(fileName);
        String filepath = FileLocator.toFileURL(url).getFile();
        props.load(new FileInputStream(new File(filepath)));
    } else {
...
StringgetProperty(String propertyName)
Get the specified property from the environment.
String property = null;
try {
    property = System.getProperty(propertyName);
} catch (SecurityException security) {
    if (!propertyName.equals("ptolemy.ptII.dir")) {
        throw new RuntimeException("Could not find '" + propertyName + "' System property", security);
if (propertyName.equals("user.dir")) {
    try {
        File userDirFile = new File(property);
        return userDirFile.getCanonicalPath();
    } catch (IOException ex) {
        return property;
if (property != null) {
    return property;
if (propertyName.equals("ptolemy.ptII.dirAsURL")) {
    File ptIIAsFile = new File(getProperty("ptolemy.ptII.dir"));
    try {
        URL ptIIAsURL = ptIIAsFile.toURI().toURL();
        return ptIIAsURL.toString();
    } catch (java.net.MalformedURLException malformed) {
        throw new RuntimeException("While trying to find '" + propertyName + "', could not convert '"
                + ptIIAsFile + "' to a URL", malformed);
if (propertyName.equals("ptolemy.ptII.dir")) {
    String namedObjPath = "ptolemy/kernel/util/NamedObj.class";
    String home = null;
    URL namedObjURL = Thread.currentThread().getContextClassLoader().getResource(namedObjPath);
    if (namedObjURL != null) {
        String namedObjFileName = namedObjURL.getFile().toString();
        if (namedObjFileName.startsWith("file:")) {
            namedObjFileName = namedObjFileName.substring(6);
        String abnormalHome = namedObjFileName.substring(0,
                namedObjFileName.length() - namedObjPath.length());
        home = (new File(abnormalHome)).toString();
        if (home.endsWith("!")) {
            home = home.substring(0, home.length() - 1);
        String ptsupportJarName = File.separator + "DMptolemy" + File.separator + "RMptsupport.jar";
        if (home.endsWith(ptsupportJarName)) {
            home = home.substring(0, home.length() - ptsupportJarName.length());
        ptsupportJarName = File.separator + "ptolemy" + File.separator + "ptsupport.jar";
        if (home.endsWith(ptsupportJarName)) {
            home = home.substring(0, home.length() - ptsupportJarName.length());
    if (home == null) {
        throw new RuntimeException(
                "Could not find " + "'ptolemy.ptII.dir'" + " property.  Also tried loading '" + namedObjPath
                        + "' as a resource and working from that. " + "Vergil should be "
                        + "invoked with -Dptolemy.ptII.dir" + "=\"$PTII\"");
    try {
        System.setProperty("ptolemy.ptII.dir", home);
    } catch (SecurityException security) {
    return home;
if (property == null) {
    return "";
return property;
ReadergetReader(final String name, final String encoding)
get Reader
return new InputStreamReader(getStream(name), encoding);
StringgetRootPath()
get Root Path
if (null != ROOT_PATH) {
    return ROOT_PATH;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (null == classLoader) {
    classLoader = ClassLoader.getSystemClassLoader();
URL url = classLoader.getResource("/");
...
StringgetSimpleName(String fqcn)
Should return a decent short version of the FQCN given: class java.lang.String -> c String class java.lang.Classreturn fqcn.replaceAll(REGEX_FOR_PACKAGE, "$3 ");
StringgetSourcesPath()
get Sources Path
return URLDecoder.decode(ClassLoader.getSystemResource("").getFile(), "utf-8");
FilegetSSTable(String version, int generation)
get SS Table
copyResource(version + "-" + generation + "-big-Digest.crc32");
copyResource(version + "-" + generation + "-big-TOC.txt");
copyResource(version + "-" + generation + "-big-CompressionInfo.db");
copyResource(version + "-" + generation + "-big-Filter.db");
copyResource(version + "-" + generation + "-big-Index.db");
copyResource(version + "-" + generation + "-big-Statistics.db");
copyResource(version + "-" + generation + "-big-Summary.db");
copyResource(version + "-" + generation + "-big-TOC.txt");
...
InputStreamgetStream(final File file)
get Stream
return new FileInputStream(file);
InputStreamgetStreamForString(String source)
Allows client to get an InputStream for a given URL (any string with a ':') or Path specified as a String.
InputStream ret = null;
try {
    if (source.indexOf(":") > 1) {
        URL url = new URL(source);
        ret = url.openStream();
    } else {
        FileInputStream f = new FileInputStream(source);
        ret = f;
...