/** * 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()); }
/** * Locates the provided {@code FileLocator}, returning a URL for accessing * the referenced file. This method uses a {@link FileLocationStrategy} to * locate the file the passed in {@code FileLocator} points to. If the * {@code FileLocator} contains itself a {@code FileLocationStrategy}, it is * used. Otherwise, the default {@code FileLocationStrategy} is applied. The * strategy is passed the locator and a {@code FileSystem}. The resulting * URL is returned. If the {@code FileLocator} is <b>null</b>, result is * <b>null</b>. * * @param locator the {@code FileLocator} to be resolved * @return the URL pointing to the referenced file or <b>null</b> if the * {@code FileLocator} could not be resolved * @see #DEFAULT_LOCATION_STRATEGY */ public static URL locate(final FileLocator locator) { if (locator == null) { return null; } return obtainLocationStrategy(locator).locate( obtainFileSystem(locator), locator); }
/** * Internal helper method for saving data to the given {@code File}. * * @param file the target file * @param locator the current {@code FileLocator} * @throws ConfigurationException if an error occurs during the save * operation */ private void save(final File file, final FileLocator locator) throws ConfigurationException { OutputStream out = null; try { out = FileLocatorUtils.obtainFileSystem(locator).getOutputStream(file); saveToStream(out, locator.getEncoding(), file.toURI().toURL()); } catch (final MalformedURLException muex) { throw new ConfigurationException(muex); } finally { closeSilent(out); } }
/** * Returns the full path to the associated file. The return value is a valid * {@code File} path only if this location is based on a file on the local * disk. If the file was loaded from a packed archive, the returned value is * the string form of the URL from which the file was loaded. * * @return the full path to the associated file */ public String getPath() { final FileLocator locator = getFileLocator(); final File file = createFile(locator); return FileLocatorUtils.obtainFileSystem(locator).getPath(file, locator.getSourceURL(), locator.getBasePath(), locator.getFileName()); }
/** * Internal helper method for saving data to the given file name. * * @param fileName the path to the target file * @param locator the current {@code FileLocator} * @throws ConfigurationException if an error occurs during the save * operation */ private void save(final String fileName, final FileLocator locator) throws ConfigurationException { URL url; try { url = FileLocatorUtils.obtainFileSystem(locator).getURL( locator.getBasePath(), fileName); } catch (final MalformedURLException e) { throw new ConfigurationException(e); } if (url == null) { throw new ConfigurationException( "Cannot locate configuration source " + fileName); } save(url, locator); }
/** * Internal helper method for loading a file from the given URL. * * @param url the URL * @param locator the current {@code FileLocator} * @throws ConfigurationException if an error occurs */ private void load(final URL url, final FileLocator locator) throws ConfigurationException { InputStream in = null; try { in = FileLocatorUtils.obtainFileSystem(locator).getInputStream(url); loadFromStream(in, locator.getEncoding(), url); } catch (final ConfigurationException e) { throw e; } catch (final Exception e) { throw new ConfigurationException( "Unable to load the configuration from the URL " + url, e); } finally { closeSilent(in); } }
try out = FileLocatorUtils.obtainFileSystem(locator).getOutputStream(url); saveToStream(out, locator.getEncoding(), url); if (out instanceof VerifiableOutputStream)