Class NBIO
java.lang.Object
io.nosqlbench.nb.api.nbio.NBIO
- All Implemented Interfaces:
NBPathsAPI.DoSearch,NBPathsAPI.Facets,NBPathsAPI.GetExtensions,NBPathsAPI.GetPathname,NBPathsAPI.GetPrefixes,NBPathsAPI.GetSource
NBIO is a helper utility packaged as a search builder and fluent API. It uses value semantics internally, so it is
safe to re-use as a stateful configuration builder for finding files in various ways.
Since this is meant to ease development around a usually over-complicated surface area in the JVM (Files, Paths, URIs, accessing data, knowing where it comes from, searching for it, etc), more emphasis was put on ease of use and clarity than efficiency. This set of classes is not expected to be used much in NoSqlBench after workload initialization, so is not performance oriented.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddGlobalIncludes(String[] globalIncludes) static NBPathsAPI.GetPrefixesall()Search for named resources everywhere: URLs, filesystem, classpathReturn content from everywhere, from remote URls, or from the file system and then the internal bundled content if not found in the file system first.static NBPathsAPI.GetPrefixescached()Return content from the NBIO cache.Return content from the NBIO cache.static NBPathsAPI.GetPrefixeschain(List<ResolverChain.Link> chains) Search for ordered chainschainContent(List<ResolverChain.Link> chains) Return content from protocols that you choose in the order you specifystatic NBPathsAPI.GetPrefixesSearch for named resources in the classpathstatic LinkedHashSet<String> expandNamesAndSuffixes(Set<String> _prefixes, List<String> _names, List<Set<String>> _suffixCosetLists) Given names and suffixes, expand a list of names which may be valid.extensionSet(String... extensions) provide a list of optional file extensions which should be considered.extensionSets(Set<String>... cosets) Only return content from the filesystem, but not remote URLs nor internal bundled resources.findFirstLocalPath(String... potentials) first()Return the result of resolving the resource.static NBPathsAPI.GetPrefixesfs()Search for named resources on the filesystemstatic PathgetFirstLocalPath(String... potentials) Only return content from the runtime classpath, internal resources that are bundled, and do not return content on the file system.list()Provide a list of all matching content that was matched by the search qualifiersstatic NBPathsAPI.GetPrefixeslocal()Search for named resources locally: filesystem, classpathOnly provide content from the class path and the local filesystem.maybeOne()Content<?> one()Find exactly one source of content under the search parameters given.Provide the names of the resources to be resolved.static CharBufferreadCharBuffer(String filename, String... searchPaths) static org.apache.commons.csv.CSVParserreadFileCSV(String filename, String... searchPaths) static org.apache.commons.csv.CSVParserreadFileDelimCSV(String filename, char delim, String... searchPaths) static InputStreamreadInputStream(String fromPath, String yaml, String[] searchPaths) relativeTo(String... base) Return a list of paths which are comprised of the relative part once the provided base has been removed from the front.static NBPathsAPI.GetPrefixesremote()Search for named resources only in URLsOnly return content from remote URLs.Return the result of resolving each of the resource names given.Provide a combined prefix, name and suffix in a combined form.searchPrefixes(String... searchPaths) Each of the prefix paths will be searched if the resource is not found with the exact path given.static voidsetUseNBIOCache(boolean wantsToUseNBIOCache) toString()boolean
-
Method Details
-
addGlobalIncludes
-
readLines
-
readFileCSV
-
readFileDelimCSV
-
readCharBuffer
-
getFirstLocalPath
-
findFirstLocalPath
-
readInputStream
-
localContent
Only provide content from the class path and the local filesystem.- Specified by:
localContentin interfaceNBPathsAPI.GetSource- Returns:
- this builder
-
remoteContent
Only return content from remote URLs. If the user is providing non-URL content in this context, it is an error. Throw an error in that case.- Specified by:
remoteContentin interfaceNBPathsAPI.GetSource- Returns:
- this builder
-
internalContent
Only return content from the runtime classpath, internal resources that are bundled, and do not return content on the file system.- Specified by:
internalContentin interfaceNBPathsAPI.GetSource- Returns:
- this builder
-
fileContent
Only return content from the filesystem, but not remote URLs nor internal bundled resources.- Specified by:
fileContentin interfaceNBPathsAPI.GetSource- Returns:
- this builder
-
cachedContent
Return content from the NBIO cache. If the content is not in the cache look for it in the given URL and put it in the cache.- Specified by:
cachedContentin interfaceNBPathsAPI.GetSource- Returns:
- this builder
-
allContent
Return content from everywhere, from remote URls, or from the file system and then the internal bundled content if not found in the file system first.- Specified by:
allContentin interfaceNBPathsAPI.GetSource- Returns:
- this builder
-
chainContent
Return content from protocols that you choose in the order you specify- Specified by:
chainContentin interfaceNBPathsAPI.GetSource- Returns:
- this builder
-
searchPrefixes
Each of the prefix paths will be searched if the resource is not found with the exact path given. To be specific, if you want to search within a location based on wildcards, you must provide a prefix that provides a boundary for the search.- Specified by:
searchPrefixesin interfaceNBPathsAPI.GetPrefixes- Parameters:
searchPaths- A list of paths to include in the search- Returns:
- this builder
-
search
Provide a combined prefix, name and suffix in a combined form. For each search template provided, the value is sliced up into the three components (prefix, name, extension) and added as if they were specified separately using the following rules:- Any suffix like
is stripped off as the extension..name - Any literal (non-pattern) path parts are taken as the prefix.
- The remainder is taken as the name.
my/prefix/path/..?/name.txtyields:- prefix:
my/prefix/path/ - name:
..?/name - extension:
.txt
- prefix:
.*.yamlyeilds:- prefix:
./ - name:
.* - extension:
.yaml
- prefix:
- Specified by:
searchin interfaceNBPathsAPI.GetPathname- Parameters:
searches-- Returns:
- Any suffix like
-
pathname
Provide the names of the resources to be resolved. More than one resource may be provided. If no name is provided, then a wildcard search is assumed.- Specified by:
pathnamein interfaceNBPathsAPI.GetPathname- Parameters:
searchNames- The name of the resource to load- Returns:
- this builder
-
extensionSet
provide a list of optional file extensions which should be considered. If the content is not found under the provided name, then each of the extension is tried in order. Any provided names are combined with the extensions to create an expanded list of paths to search for. if extensions are provided without a name, then wildcards are created with the extensions as suffix patterns.- Specified by:
extensionSetin interfaceNBPathsAPI.GetExtensions- Parameters:
extensions- The extension names to try- Returns:
- this builder
-
extensionSets
- Specified by:
extensionSetsin interfaceNBPathsAPI.GetExtensions
-
all
Search for named resources everywhere: URLs, filesystem, classpath- Returns:
- a builder
-
classpath
Search for named resources in the classpath- Returns:
- a builder
-
fs
Search for named resources on the filesystem- Returns:
- a builder
-
local
Search for named resources locally: filesystem, classpath- Returns:
- a builder
-
chain
Search for ordered chains- Returns:
- a builder
-
remote
Search for named resources only in URLs- Returns:
- a builder
-
cached
Return content from the NBIO cache. If the content is not in the cache look for it in the given URL and put it in the cache.- Returns:
- this builder
-
first
Return the result of resolving the resource.- Specified by:
firstin interfaceNBPathsAPI.DoSearch- Returns:
- an optional
Content<?>element.
-
maybeOne
-
one
Find exactly one source of content under the search parameters given. It is an error if you find none, or more than one.- Specified by:
onein interfaceNBPathsAPI.DoSearch- Returns:
- An optional content element.
-
resolveEach
Return the result of resolving each of the resource names given. This has the same semantics ofNBPathsAPI.DoSearch.first(), except that it returns a result pair-wise for each name given.- Specified by:
resolveEachin interfaceNBPathsAPI.DoSearch- Returns:
- A list of optional
Content<?>elements.
-
expandNamesAndSuffixes
-
expandNamesAndSuffixes
public static LinkedHashSet<String> expandNamesAndSuffixes(Set<String> _prefixes, List<String> _names, List<Set<String>> _suffixCosetLists) Given names and suffixes, expand a list of names which may be valid. If no name is given, then
is used. If suffixes are given, then all returned results must include at least one of the suffixes. If the name includes one of the suffixes given, then additional suffixes are added to the list of searchable path names..*- Parameters:
_names- base filenames or path fragment, possibly fully-qualified_suffixCosetLists- zero or more suffixes, which, if given, imply that one of them must match- Returns:
- Expanded names of valid filename fragments according to the above rules
-
expandSynonymPaths
-
list
Provide a list of all matching content that was matched by the search qualifiers- Specified by:
listin interfaceNBPathsAPI.DoSearch- Returns:
- a list of content
-
relativeTo
Return a list of paths which are comprised of the relative part once the provided base has been removed from the front. This is done per content item within the direct filesystem the path belongs to.- Specified by:
relativeToin interfaceNBPathsAPI.DoSearch- Parameters:
base- The root path elements to remove- Returns:
- Relative paths
-
toString
-
useNBIOCache
public boolean useNBIOCache() -
setUseNBIOCache
public static void setUseNBIOCache(boolean wantsToUseNBIOCache)
-