/** * Add a configuration resource. The properties form this configuration will * overwrite corresponding already loaded property and system property * * @param configFile * Configuration file. */ public void addConfiguration(File configFile) throws ConfigException { LOG.info("Reading configuration from: {}", configFile.getAbsolutePath()); try { configFile = (new VerifyingFileFactory.Builder(LOG).warnForRelativePath().failForNonExistingPath().build()) .validate(configFile); Properties cfg = new Properties(); FileInputStream in = new FileInputStream(configFile); try { cfg.load(in); } finally { in.close(); } parseProperties(cfg); } catch (IOException | IllegalArgumentException e) { LOG.error("Error while configuration from: {}", configFile.getAbsolutePath(), e); throw new ConfigException("Error while processing " + configFile.getAbsolutePath(), e); } }
String clientPortAddress = null; String secureClientPortAddress = null; VerifyingFileFactory vff = new VerifyingFileFactory.Builder(LOG).warnForRelativePath().build(); for (Entry<Object, Object> entry : zkProp.entrySet()) { String key = entry.getKey().toString().trim();
.warnForRelativePath() .failForNonExistingPath() .build()).create(path);
.warnForRelativePath() .failForNonExistingPath() .build()).create(configFileStr); .warnForRelativePath() .failForNonExistingPath() .build()).create(dynamicFileStr);
@Test public void testForNoWarningOnIntendedRelativePath() { VerifyingFileFactory vff = new VerifyingFileFactory.Builder(log) .warnForRelativePath().build(); vff.create("./an/intended/relative/path"); // assertFalse(log.hasWarned); }
@Test public void testForWarningOnRelativePath() { VerifyingFileFactory vff = new VerifyingFileFactory.Builder(log) .warnForRelativePath().build(); vff.create("a/relative/path"); // assertTrue(log.hasWarned); }