diff options
| author | Robert Gemmell <robbie@apache.org> | 2011-07-21 13:18:51 +0000 |
|---|---|---|
| committer | Robert Gemmell <robbie@apache.org> | 2011-07-21 13:18:51 +0000 |
| commit | 1f55f866f3d1f377031656440dd4fd3326b4638b (patch) | |
| tree | 355f24b32b95d2205943c0a153ea6aaf7304c301 /qpid/java/common/src/main | |
| parent | a8e7aeb469037dfaf8b2bb0bb6ca75d4181a4b1c (diff) | |
| download | qpid-python-1f55f866f3d1f377031656440dd4fd3326b4638b.tar.gz | |
QPID-3367: FileUtils improvements. #openFileOrDefaultResource now tries the override filename in the classpath too, before falling back to the default.
Applied patch from Keith Wall <keith.wall@gmail.com>
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1149165 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/common/src/main')
| -rw-r--r-- | qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java b/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java index 1a57af9bf7..ac8e3da3c2 100644 --- a/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java +++ b/qpid/java/common/src/main/java/org/apache/qpid/util/FileUtils.java @@ -143,8 +143,9 @@ public class FileUtils } /** - * Either opens the specified filename as an input stream, or uses the default resource loaded using the - * specified class loader, if opening the file fails or no file name is specified. + * Either opens the specified filename as an input stream or either the filesystem or classpath, + * or uses the default resource loaded using the specified class loader, if opening the file fails + * or no file name is specified. * * @param filename The name of the file to open. * @param defaultResource The name of the default resource on the classpath if the file cannot be opened. @@ -156,28 +157,28 @@ public class FileUtils { InputStream is = null; - // Flag to indicate whether the default resource should be used. By default this is true, so that the default - // is used when opening the file fails. - boolean useDefault = true; - // Try to open the file if one was specified. if (filename != null) { + // try on filesystem try { is = new BufferedInputStream(new FileInputStream(new File(filename))); - - // Clear the default flag because the file was succesfully opened. - useDefault = false; } catch (FileNotFoundException e) { - // Ignore this exception, the default will be used instead. + is = null; + } + + if (is == null) + { + // failed on filesystem, so try on classpath + is = cl.getResourceAsStream(filename); } } // Load the default resource if a file was not specified, or if opening the file failed. - if (useDefault) + if (is == null) { is = cl.getResourceAsStream(defaultResource); } |
