PropertyHelperpublic class PropertyHelper extends Object
Fields Summary |
---|
private static final com.sun.jdo.spi.persistence.utility.logging.Logger | loggerThe logger. | private static final ResourceBundle | messagesI18N message handler. |
Methods Summary |
---|
private static void | load(java.util.Properties properties, java.lang.String resourceName, boolean loadFromFile, java.lang.ClassLoader classLoader)Loads properties list from the specified resource
into specified Properties object.
InputStream bin = null;
InputStream in = null;
boolean debug = logger.isLoggable();
if (debug) {
Object[] items = new Object[] {resourceName,Boolean.valueOf(loadFromFile)};
logger.fine("utility.PropertyHelper.load",items); // NOI18N
}
in = loadFromFile ? openFileInputStream(resourceName) :
openResourceInputStream(resourceName,classLoader);
if (in == null) {
throw new IOException(I18NHelper.getMessage(messages,
"utility.PropertyHelper.failedToLoadResource", resourceName));// NOI18N
}
bin = new BufferedInputStream(in);
try {
properties.load(bin);
} finally {
try {
bin.close();
} catch (Exception e) {
// no action
}
}
| public static void | loadFromFile(java.util.Properties properties, java.lang.String fileName)Loads properties list from the specified file into specified Properties object.
load(properties, fileName, true, null);
| public static void | loadFromResource(java.util.Properties properties, java.lang.String resourceName, java.lang.ClassLoader classLoader)Loads properties list from the specified resource into specified Properties object.
load(properties, resourceName, false, classLoader);
| private static java.io.InputStream | openFileInputStream(java.lang.String fileName)Open fileName as input stream inside doPriviledged block
try {
return (InputStream) AccessController.doPrivileged(
new PrivilegedExceptionAction() {
public Object run() throws FileNotFoundException {
return new FileInputStream(fileName);
}
}
);
} catch (PrivilegedActionException e) {
// e.getException() should be an instance of FileNotFoundException,
// as only "checked" exceptions will be "wrapped" in a
// PrivilegedActionException.
throw (FileNotFoundException) e.getException();
}
| private static java.io.InputStream | openResourceInputStream(java.lang.String resourceName, java.lang.ClassLoader classLoader)Open resourcenName as input stream inside doPriviledged block
return (InputStream) AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
if (classLoader != null) {
return classLoader.getResourceAsStream(resourceName);
} else {
return ClassLoader.getSystemResourceAsStream(resourceName);
}
}
}
);
|
|