io.nosqlbench.nb.api.content.ResolverForFilesystem Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nb-api Show documentation
Show all versions of nb-api Show documentation
The top level API module for NoSQLBench. This module should have no internal
module dependencies other than the mvn-default module.
All modules within NoSQLBench can safely depend on this module with circular
dependencies. This module provides cross-cutting code infrastracture, such as
path utilities and ways of describing services used between modules.
It is also the transitive aggregation point for system-wide library dependencies
for logging and testing or similar needs.
package io.nosqlbench.nb.api.content;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
public class ResolverForFilesystem implements ContentResolver {
public static ResolverForFilesystem INSTANCE = new ResolverForFilesystem();
private final static Logger logger = LogManager.getLogger(ResolverForFilesystem.class);
@Override
public List> resolve(URI uri) {
List> contents = new ArrayList<>();
Path path = resolvePath(uri);
if (path != null) {
contents.add(new PathContent(path));
}
return contents;
}
@Override
public List resolveDirectory(URI uri) {
List dirs = new ArrayList<>();
Path path = resolvePath(uri);
if (path!=null && Files.isDirectory(path)) {
dirs.add(path);
}
return dirs;
}
private Path resolvePath(URI uri) {
if (uri.getScheme() != null && !uri.getScheme().isEmpty() && !uri.getScheme().equals("file")) {
return null;
}
Path pathFromUri = Path.of(uri.getPath());
if (Files.isReadable(pathFromUri)) {
return pathFromUri;
}
return null;
}
public String toString() {
return this.getClass().getSimpleName();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy