diff options
author | Mark Spruiell <mes@zeroc.com> | 2009-04-07 14:47:49 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2009-04-07 14:47:49 -0700 |
commit | b6434cdb0b59adf520c4d782d991cbd5fac818cd (patch) | |
tree | a54daae0d762bb8eab8aaa596d43e926bfddcb10 /java/src/IceInternal/Util.java | |
parent | Changes update (diff) | |
download | ice-b6434cdb0b59adf520c4d782d991cbd5fac818cd.tar.bz2 ice-b6434cdb0b59adf520c4d782d991cbd5fac818cd.tar.xz ice-b6434cdb0b59adf520c4d782d991cbd5fac818cd.zip |
bug 849 - load properties from JAR file
Ice now attempts to load a configuration file as a class path
resource, and if that fails it opens the file in the local file
system.
bug 3613 - System properties
Ice for Java no longer uses Java system properties as default
values for Ice properties.
Diffstat (limited to 'java/src/IceInternal/Util.java')
-rw-r--r-- | java/src/IceInternal/Util.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/java/src/IceInternal/Util.java b/java/src/IceInternal/Util.java index fbfc49e1c0f..2a1f70ce69c 100644 --- a/java/src/IceInternal/Util.java +++ b/java/src/IceInternal/Util.java @@ -23,4 +23,40 @@ public final class Util { return new ProtocolPluginFacadeI(communicator); } + + // + // Given a path name, first try to open it as a class path resource (the path is + // treated as absolute). If that fails, fall back to the file system. Returns null + // if the file does not exist and raises IOException if an error occurs. + // + public static java.io.InputStream + openResource(ClassLoader cl, String path) + throws java.io.IOException + { + // + // Calling getResourceAsStream on the class loader means all paths are absolute, + // whereas calling it on the class means all paths are relative to the class + // unless the path has a leading forward slash. We call it on the class loader. + // + // getResourceAsStream returns null if the resource can't be found. + // + java.io.InputStream stream = cl.getResourceAsStream(path); + if(stream == null) + { + try + { + java.io.File f = new java.io.File(path); + if(f.exists()) + { + stream = new java.io.FileInputStream(f); + } + } + catch(java.lang.SecurityException ex) + { + // Ignore - a security manager may forbid access to the local file system. + } + } + + return stream; + } } |