List of utility methods to do ClassLoader Load
Collection | getProhibitedProxyInterfaces() 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) ... |
Properties | getProperties(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 { ... |
String | getProperty(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; |
Reader | getReader(final String name, final String encoding) get Reader return new InputStreamReader(getStream(name), encoding); |
String | getRootPath() 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("/"); ... |
String | getSimpleName(String fqcn) Should return a decent short version of the FQCN given: class java.lang.String -> c String class java.lang.Class
|
String | getSourcesPath() get Sources Path return URLDecoder.decode(ClassLoader.getSystemResource("").getFile(), "utf-8"); |
File | getSSTable(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"); ... |
InputStream | getStream(final File file) get Stream return new FileInputStream(file); |
InputStream | getStreamForString(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; ... |