/** * Prepares a builder for a {@code FileLocator} which does not have a * defined file location. Other properties (e.g. encoding or file system) * are initialized from the {@code FileLocator} associated with this object. * * @return the initialized builder for a {@code FileLocator} */ private FileLocatorBuilder prepareNullLocatorBuilder() { return FileLocatorUtils.fileLocator(getFileLocator()).sourceURL(null) .basePath(null).fileName(null); }
/** * Returns the {@code FileLocationStrategy} to be applied when accessing the * associated file. This method never returns <b>null</b>. If a * {@code FileLocationStrategy} has been set, it is returned. Otherwise, * result is the default {@code FileLocationStrategy}. * * @return the {@code FileLocationStrategy} to be used */ public FileLocationStrategy getLocationStrategy() { return FileLocatorUtils.obtainLocationStrategy(getFileLocator()); }
/** * 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()); }
try { PropertiesConfiguration pcf = new PropertiesConfiguration(); FileHandler fh = new FileHandler(pcf); fh.setFileName(fname); fh.load(); Configuration cf = pcf.interpolatedConfiguration(); LOG.info("Loaded properties from {}", fname);
/** * Creates an uninitialized file locator. * * @return the locator */ private static FileLocator emptyFileLocator() { return FileLocatorUtils.fileLocator().create(); }
/** * Creates a new {@code FileHandler} instance from properties stored in a * map. This method tries to extract a {@link FileLocator} from the map. A * new {@code FileHandler} is created based on this {@code FileLocator}. * * @param map the map (may be <b>null</b>) * @return the newly created {@code FileHandler} * @see FileLocatorUtils#fromMap(Map) */ public static FileHandler fromMap(final Map<String, ?> map) { return new FileHandler(null, FileLocatorUtils.fromMap(map)); }
/** * 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); }
/** * 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); }
/** * Internal helper method for saving a file to the given output stream. * * @param out the output stream * @param locator the current {@code FileLocator} * @throws ConfigurationException if an error occurs during the save * operation */ private void save(final OutputStream out, final FileLocator locator) throws ConfigurationException { save(out, locator.getEncoding()); }
/** * {@inheritDoc} This implementation delegates to the {@code FileSystem}. */ @Override public URL locate(final FileSystem fileSystem, final FileLocator locator) { return fileSystem.locateFromURL(locator.getBasePath(), locator.getFileName()); } }
/** * Returns the location of the associated file as a URL. If a URL is set, * it is directly returned. Otherwise, an attempt to locate the referenced * file is made. * * @return a URL to the associated file; can be <b>null</b> if the location * is unspecified */ public URL getURL() { final FileLocator locator = getFileLocator(); return (locator.getSourceURL() != null) ? locator.getSourceURL() : FileLocatorUtils.locate(locator); }
/** * Tests whether a location is defined for this {@code FileHandler}. * * @return <b>true</b> if a location is defined, <b>false</b> otherwise */ public boolean isLocationDefined() { return FileLocatorUtils.isLocationDefined(getFileLocator()); }
/** * Returns the encoding of the associated file. Result can be <b>null</b> if * no encoding has been set. * * @return the encoding of the associated file */ public String getEncoding() { return getFileLocator().getEncoding(); }
/** * Returns the {@code FileSystem} to be used by this object when locating * files. Result is never <b>null</b>; if no file system has been set, the * default file system is returned. * * @return the used {@code FileSystem} */ public FileSystem getFileSystem() { return FileLocatorUtils.obtainFileSystem(getFileLocator()); }
@Override public String getFileName(final String path) { URL url; try { url = getURL(null, path); return FileLocatorUtils.getFileName(url); } catch (final Exception e) { return null; } }
@Override protected void updateBuilder(final FileLocatorBuilder builder) { builder.encoding(encoding); } }
/** * Resets the {@code FileSystem} used by this object. It is set to the * default file system. */ public void resetFileSystem() { setFileSystem(null); }
/** * Tries to convert the specified URL to a file object. If this fails, * <b>null</b> is returned. * * @param url the URL * @return the resulting file object */ public static File fileFromURL(final URL url) { return FileUtils.toFile(url); }
/** * Initializes the logger. Supports <b>null</b> input. This method can be * called by derived classes in order to enable logging. * * @param log the logger * @since 2.0 */ protected final void initLogger(final ConfigurationLogger log) { this.log = (log != null) ? log : ConfigurationLogger.newDummyLogger(); }