/** * Creates a new {@code FileLocator} object with the properties defined in * the given map. The map must be conform to the structure generated by the * {@link #put(FileLocator, Map)} method; unexpected data can cause * {@code ClassCastException} exceptions. The map can be <b>null</b>, then * an uninitialized {@code FileLocator} is returned. * * @param map the map * @return the new {@code FileLocator} * @throws ClassCastException if the map contains invalid data */ public static FileLocator fromMap(final Map<String, ?> map) { final FileLocator.FileLocatorBuilder builder = fileLocator(); if (map != null) { builder.basePath((String) map.get(PROP_BASE_PATH)) .encoding((String) map.get(PROP_ENCODING)) .fileName((String) map.get(PROP_FILE_NAME)) .fileSystem((FileSystem) map.get(PROP_FILE_SYSTEM)) .locationStrategy( (FileLocationStrategy) map.get(PROP_STRATEGY)) .sourceURL((URL) map.get(PROP_SOURCE_URL)); } return builder.create(); }
/** * Helper method for locating a given file. This implementation delegates to * the corresponding method in {@link FileLocatorUtils}. * * @param fs the {@code FileSystem} * @param basePath the base path * @param name the file name * @return the URL pointing to the file */ private static URL locate(final FileSystem fs, final String basePath, final String name) { final FileLocator locator = FileLocatorUtils.fileLocator().fileSystem(fs) .basePath(basePath).fileName(name).create(); return FileLocatorUtils.locate(locator); }
@Override protected void updateBuilder(final FileLocatorBuilder builder) { builder.fileSystem(fileSystem); } }