com.github.zhengframework.configuration.io.AbsoluteNameLocationStrategy Maven / Gradle / Ivy
package com.github.zhengframework.configuration.io;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@Slf4j
public class AbsoluteNameLocationStrategy implements FileLocationStrategy {
@Override
public Optional locate(final FileSystem fileSystem, final FileLocator locator) {
if (StringUtils.isNotEmpty(locator.getFileName())) {
final File file = new File(locator.getFileName());
if (file.isAbsolute() && file.exists()) {
try {
log.debug("Loading configuration from the file ({})", file.getCanonicalPath());
return Optional.of(file.toURI().toURL());
} catch (IOException e) {
return Optional.empty();
}
}
}
return Optional.empty();
}
}