Methods Summary |
---|
private static java.io.InputStream | getResourceAsStream(java.lang.String fileName, java.lang.Class cls)
fileName = resolveName(fileName, cls);
ClassLoader loader = cls.getClassLoader ();
if (loader == null) {
return ClassLoader.getSystemResourceAsStream(fileName);
}
InputStream in = loader.getResourceAsStream(fileName);
if (in == null) {
in = ClassLoader.getSystemResourceAsStream(fileName);
}
return in;
|
public static java.util.ResourceBundle | getResourceBundle(java.lang.String className, java.lang.String propertyName)Returns resource bundle associated with class or with property file
ResourceBundle myBundle = null;
// Try to open property file first
InputStream in = getResourceAsStream(propertyName + ".properties", ResourceBundleAccessor.class);
if (in != null) {
try {
myBundle = new PropertyResourceBundle (in);
}
catch(IOException ioException) {
myBundle = null;
}
finally{
try {
in.close ();
in = null;
System.gc ();
}
catch(IOException closeException) {
System.out.println ("Could not close resource input stream: " + closeException);
}
}
}
// If property file did not open, use standard way
if (myBundle == null) {
System.err.println ("Property file ["+ propertyName + ".properties] not found , opening class");
// Try to open resources as class/property
myBundle = ResourceBundle.getBundle (className);
}
return myBundle;
|
private static java.lang.String | resolveName(java.lang.String name, java.lang.Class clazz)
System.err.println("resolveName " + name);
if (name == null) {
return name;
}
if (!name.startsWith("/")) {
Class c = clazz;
while (c.isArray()) {
c = c.getComponentType();
}
String baseName = c.getName();
int index = baseName.lastIndexOf('.");
if (index != -1) {
name = baseName.substring(0, index).replace('.", '/")+"/"+name;
}
}
else {
name = name.substring(1);
}
System.err.println("resolvedName = " + name);
return name;
|