Skip to content

Commit

Permalink
[Java] Reduce the number of exceptions when loading properties files.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjpt777 committed Aug 24, 2017
1 parent ddb2f39 commit 0522197
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions aeron-driver/src/main/java/io/aeron/driver/MediaDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,28 @@ public static void loadPropertiesFile(final String filenameOrUrl)
{
final Properties properties = new Properties(System.getProperties());

try (InputStream in = MediaDriver.class.getClassLoader().getResourceAsStream(filenameOrUrl))
{
properties.load(in);
}
catch (final Exception ignore)
final URL resource = MediaDriver.class.getClassLoader().getResource(filenameOrUrl);
if (null != resource)
{
try (InputStream in = resource.openStream())
{
properties.load(in);
}
catch (final Exception ignore)
{
}
}

try (FileInputStream in = new FileInputStream(filenameOrUrl))
{
properties.load(in);
}
catch (final Exception ignore)
final File file = new File(filenameOrUrl);
if (file.exists())
{
try (FileInputStream in = new FileInputStream(file))
{
properties.load(in);
}
catch (final Exception ignore)
{
}
}

try (InputStream in = new URL(filenameOrUrl).openStream())
Expand Down Expand Up @@ -130,7 +138,7 @@ public static void main(final String[] args) throws Exception
{
loadPropertiesFiles(args);

try (MediaDriver ignored = MediaDriver.launch())
try (MediaDriver ignore = MediaDriver.launch())
{
new ShutdownSignalBarrier().await();

Expand Down

0 comments on commit 0522197

Please sign in to comment.