@Test public void shouldDoNothingToSystemPropsWhenLoadingFileWhichDoesNotExist() { final int originalSystemPropSize = System.getProperties().size(); loadPropertiesFile("$unknown-file$"); assertThat(originalSystemPropSize, is(System.getProperties().size())); }
public static void loadPropertiesFile(final String filenameOrUrl) { final Properties properties = new Properties(System.getProperties()); System.getProperties().forEach(properties::put); final URL resource = ClassLoader.getSystemClassLoader().getResource(filenameOrUrl); if (null != resource) { try (InputStream in = resource.openStream()) { 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()) { properties.load(in); } catch (final Exception ignore) { } System.setProperties(properties); }
SystemUtil { public static void loadPropertiesFile(final String filenameOrUrl) { final Properties properties = new Properties(System.getProperties()); System.getProperties().forEach(properties::put); final URL resource = ClassLoader.getSystemClassLoader().getResource(filenameOrUrl); if (null != resource) { try (InputStream in = resource.openStream()) { 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()) { properties.load(in); } catch (final Exception ignore) { } System.setProperties(properties); } }
SystemUtil { public static void loadPropertiesFile(final String filenameOrUrl) { final Properties properties = new Properties(System.getProperties()); System.getProperties().forEach(properties::put); final URL resource = ClassLoader.getSystemClassLoader().getResource(filenameOrUrl); if (null != resource) { try (InputStream in = resource.openStream()) { 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()) { properties.load(in); } catch (final Exception ignore) { } System.setProperties(properties); } private  SystemUtil(); }
SystemUtil { public static void loadPropertiesFile(final String filenameOrUrl) { final Properties properties = new Properties(System.getProperties()); System.getProperties().forEach(properties::put); final URL resource = ClassLoader.getSystemClassLoader().getResource(filenameOrUrl); if (null != resource) { try (InputStream in = resource.openStream()) { 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()) { properties.load(in); } catch (final Exception ignore) { } System.setProperties(properties); } private  SystemUtil(); static String osName(); static long getPid(); static boolean isWindows(); static boolean isLinux(); static boolean isDebuggerAttached(); static String tmpDirName(); static String threadDump(); static void loadPropertiesFile(final String filenameOrUrl); static void loadPropertiesFiles(final String[] filenamesOrUrls); static int getSizeAsInt(final String propertyName, final int defaultValue); static long getSizeAsLong(final String propertyName, final long defaultValue); static long parseSize(final String propertyName, final String propertyValue); static long getDurationInNanos(final String propertyName, final long defaultValue); static long parseDuration(final String propertyName, final String propertyValue); }
SystemUtil { public static void loadPropertiesFile(final String filenameOrUrl) { final Properties properties = new Properties(System.getProperties()); System.getProperties().forEach(properties::put); final URL resource = ClassLoader.getSystemClassLoader().getResource(filenameOrUrl); if (null != resource) { try (InputStream in = resource.openStream()) { 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()) { properties.load(in); } catch (final Exception ignore) { } System.setProperties(properties); } private  SystemUtil(); static String osName(); static long getPid(); static boolean isWindows(); static boolean isLinux(); static boolean isDebuggerAttached(); static String tmpDirName(); static String threadDump(); static void loadPropertiesFile(final String filenameOrUrl); static void loadPropertiesFiles(final String[] filenamesOrUrls); static int getSizeAsInt(final String propertyName, final int defaultValue); static long getSizeAsLong(final String propertyName, final long defaultValue); static long parseSize(final String propertyName, final String propertyValue); static long getDurationInNanos(final String propertyName, final long defaultValue); static long parseDuration(final String propertyName, final String propertyValue); static final long PID_NOT_FOUND; }