FileHandler fh = new FileHandler(pcf); fh.setFileName(fname); fh.load(); Configuration cf = pcf.interpolatedConfiguration(); LOG.info("Loaded properties from {}", fname);
/** * Loads the associated file from the specified stream, using the encoding * returned by {@link #getEncoding()}. * * @param in the input stream * @throws ConfigurationException if an error occurs during the load * operation */ public void load(final InputStream in) throws ConfigurationException { load(in, checkContentAndGetLocator()); }
/** * Loads the associated file from the specified URL. The location stored in * this object is not changed. * * @param url the URL of the file to be loaded * @throws ConfigurationException if an error occurs */ public void load(final URL url) throws ConfigurationException { load(url, checkContentAndGetLocator()); }
/** * Internal helper method for loading a file from the given input stream. * * @param in the input stream * @param locator the current {@code FileLocator} * @throws ConfigurationException if an error occurs */ private void load(final InputStream in, final FileLocator locator) throws ConfigurationException { load(in, locator.getEncoding()); }
/** * Loads the associated file from the underlying location. If no location * has been set, an exception is thrown. * * @throws ConfigurationException if loading of the configuration fails */ public void load() throws ConfigurationException { load(checkContentAndGetLocator()); }
/** * Internal helper method for loading the associated file from the location * specified in the given {@code FileLocator}. * * @param locator the current {@code FileLocator} * @throws ConfigurationException if an error occurs */ private void load(final FileLocator locator) throws ConfigurationException { final URL url = FileLocatorUtils.locateOrThrow(locator); load(url, locator); }
/** * Loads the associated file from the given file name. The file name is * interpreted in the context of the already set location (e.g. if it is a * relative file name, a base path is applied if available). The underlying * location is not changed. * * @param fileName the name of the file to be loaded * @throws ConfigurationException if an error occurs */ public void load(final String fileName) throws ConfigurationException { load(fileName, checkContentAndGetLocator()); }
/** * Internal helper method for loading a file from a file name. * * @param fileName the file name * @param locator the current {@code FileLocator} * @throws ConfigurationException if an error occurs */ private void load(final String fileName, final FileLocator locator) throws ConfigurationException { final FileLocator locFileName = createLocatorWithFileName(fileName, locator); final URL url = FileLocatorUtils.locateOrThrow(locFileName); load(url, locator); }
/** * Loads the associated file from the specified {@code File}. * * @param file the file to load * @throws ConfigurationException if an error occurs */ public void load(final File file) throws ConfigurationException { URL url; try { url = FileLocatorUtils.toURL(file); } catch (final MalformedURLException e1) { throw new ConfigurationException("Cannot create URL from file " + file); } load(url); }
/** * Initializes the new current {@code FileHandler}. When a new result object * is created, a new {@code FileHandler} is created, too, and associated * with the result object. This new handler is passed to this method. If a * location is defined, the result object is loaded from this location. * Note: This method is called from a synchronized block. * * @param handler the new current {@code FileHandler} * @throws ConfigurationException if an error occurs */ protected void initFileHandler(final FileHandler handler) throws ConfigurationException { initEncoding(handler); if (handler.isLocationDefined()) { handler.locate(); handler.load(); } }
/** * Sets system properties from a file specified using its base path and * file name. The file can either be a properties file or an XML properties * file. It is loaded, and all properties it contains are added to system * properties. * * @param basePath The base path to look for the property file. * @param fileName The name of the property file. * @throws ConfigurationException if an error occurs. * @since 1.6 */ public static void setSystemProperties(final String basePath, final String fileName) throws ConfigurationException { final FileBasedConfiguration config = fileName.endsWith(".xml") ? new XMLPropertiesConfiguration() : new PropertiesConfiguration(); final FileHandler handler = new FileHandler(config); handler.setBasePath(basePath); handler.setFileName(fileName); handler.load(); setSystemProperties(config); }
private static FileBasedConfiguration createConfiguration(Reader reader) throws ConfigurationException { if (reader == null) { throw new NullPointerException("reader: null"); } FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(XMLConfiguration.class) .configure(new Parameters().xml()); FileBasedConfiguration fileBasedConfiguration = builder.getConfiguration(); FileHandler handler = new FileHandler(fileBasedConfiguration); handler.load(reader); return fileBasedConfiguration; }