/** * 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()); }
/** * 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()); }
/** * Returns the location of the associated file as a {@code File} object. If * the base path is a URL with a protocol different than "file", * or the file is within a compressed archive, the return value will not * point to a valid file object. * * @return the location as {@code File} object; this can be <b>null</b> */ public File getFile() { return createFile(getFileLocator()); }
/** * 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(); }
/** * Checks whether a content object is available and returns the current * {@code FileLocator}. If there is no content object, an exception is * thrown. This is a typical operation to be performed before a load() or * save() operation. * * @return the current {@code FileLocator} to be used for the calling * operation */ private FileLocator checkContentAndGetLocator() throws ConfigurationException { checkContent(); return getFileLocator(); }
/** * Creates a new instance of {@code FileHandler} which is associated with * the given {@code FileBased} object and the location defined for the given * {@code FileHandler} object. A copy of the location of the given * {@code FileHandler} is created. This constructor is a possibility to * associate a file location with a {@code FileBased} object. * * @param obj the {@code FileBased} object to manage * @param c the {@code FileHandler} from which to copy the location (must * not be <b>null</b>) * @throws IllegalArgumentException if the {@code FileHandler} is * <b>null</b> */ public FileHandler(final FileBased obj, final FileHandler c) { this(obj, checkSourceHandler(c).getFileLocator()); }
/** * 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); }
final FileLocator locator = getFileLocator(); FileLocator fullLocator = FileLocatorUtils.fullyInitializedLocator(locator);
/** * 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); }
/** * Return the base path. If no base path is defined, but a URL, the base * path is derived from there. * * @return the base path */ public String getBasePath() { final FileLocator locator = getFileLocator(); if (locator.getBasePath() != null) { return locator.getBasePath(); } if (locator.getSourceURL() != null) { return FileLocatorUtils.getBasePath(locator.getSourceURL()); } return null; }
/** * Return the name of the file. If only a URL is defined, the file name * is derived from there. * * @return the file name */ public String getFileName() { final FileLocator locator = getFileLocator(); if (locator.getFileName() != null) { return locator.getFileName(); } if (locator.getSourceURL() != null) { return FileLocatorUtils.getFileName(locator.getSourceURL()); } return null; }
/** * 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()); }