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

public class NBIO extends Object implements NBPathsAPI.Facets
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 Details

    • addGlobalIncludes

      public static void addGlobalIncludes(String[] globalIncludes)
    • readLines

      public static List<String> readLines(String filename)
    • readFileCSV

      public static org.apache.commons.csv.CSVParser readFileCSV(String filename, String... searchPaths)
    • readFileDelimCSV

      public static org.apache.commons.csv.CSVParser readFileDelimCSV(String filename, char delim, String... searchPaths)
    • readCharBuffer

      public static CharBuffer readCharBuffer(String filename, String... searchPaths)
    • getFirstLocalPath

      public static Path getFirstLocalPath(String... potentials)
    • findFirstLocalPath

      public static Optional<Path> findFirstLocalPath(String... potentials)
    • readInputStream

      public static InputStream readInputStream(String fromPath, String yaml, String[] searchPaths)
    • localContent

      public NBPathsAPI.GetPrefixes localContent()
      Only provide content from the class path and the local filesystem.
      Specified by:
      localContent in interface NBPathsAPI.GetSource
      Returns:
      this builder
    • remoteContent

      public NBPathsAPI.GetPrefixes 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:
      remoteContent in interface NBPathsAPI.GetSource
      Returns:
      this builder
    • internalContent

      public NBPathsAPI.GetPrefixes internalContent()
      Only return content from the runtime classpath, internal resources that are bundled, and do not return content on the file system.
      Specified by:
      internalContent in interface NBPathsAPI.GetSource
      Returns:
      this builder
    • fileContent

      public NBPathsAPI.GetPrefixes fileContent()
      Only return content from the filesystem, but not remote URLs nor internal bundled resources.
      Specified by:
      fileContent in interface NBPathsAPI.GetSource
      Returns:
      this builder
    • cachedContent

      public NBPathsAPI.GetPrefixes 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:
      cachedContent in interface NBPathsAPI.GetSource
      Returns:
      this builder
    • allContent

      public NBPathsAPI.GetPrefixes 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:
      allContent in interface NBPathsAPI.GetSource
      Returns:
      this builder
    • chainContent

      public NBPathsAPI.GetPrefixes chainContent(List<ResolverChain.Link> chains)
      Return content from protocols that you choose in the order you specify
      Specified by:
      chainContent in interface NBPathsAPI.GetSource
      Returns:
      this builder
    • searchPrefixes

      public NBPathsAPI.GetPrefixes searchPrefixes(String... searchPaths)
      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:
      searchPrefixes in interface NBPathsAPI.GetPrefixes
      Parameters:
      searchPaths - A list of paths to include in the search
      Returns:
      this builder
    • search

      public NBPathsAPI.DoSearch search(String... searches)
      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:
      1. Any suffix like
        .name
        is stripped off as the extension.
      2. Any literal (non-pattern) path parts are taken as the prefix.
      3. The remainder is taken as the name.
      Examples:
      • my/prefix/path/..?/name.txt yields:
        • prefix: my/prefix/path/
        • name: ..?/name
        • extension: .txt
      • .*.yaml yeilds:
        • prefix: ./
        • name: .*
        • extension: .yaml
      Specified by:
      search in interface NBPathsAPI.GetPathname
      Parameters:
      searches -
      Returns:
    • pathname

      public NBPathsAPI.GetExtensions pathname(String... searchNames)
      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:
      pathname in interface NBPathsAPI.GetPathname
      Parameters:
      searchNames - The name of the resource to load
      Returns:
      this builder
    • extensionSet

      public NBPathsAPI.GetExtensions extensionSet(String... extensions)
      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:
      extensionSet in interface NBPathsAPI.GetExtensions
      Parameters:
      extensions - The extension names to try
      Returns:
      this builder
    • extensionSets

      public NBPathsAPI.GetExtensions extensionSets(Set<String>... cosets)
      Specified by:
      extensionSets in interface NBPathsAPI.GetExtensions
    • all

      public static NBPathsAPI.GetPrefixes all()
      Search for named resources everywhere: URLs, filesystem, classpath
      Returns:
      a builder
    • classpath

      public static NBPathsAPI.GetPrefixes classpath()
      Search for named resources in the classpath
      Returns:
      a builder
    • fs

      public static NBPathsAPI.GetPrefixes fs()
      Search for named resources on the filesystem
      Returns:
      a builder
    • local

      public static NBPathsAPI.GetPrefixes local()
      Search for named resources locally: filesystem, classpath
      Returns:
      a builder
    • chain

      public static NBPathsAPI.GetPrefixes chain(List<ResolverChain.Link> chains)
      Search for ordered chains
      Returns:
      a builder
    • remote

      public static NBPathsAPI.GetPrefixes remote()
      Search for named resources only in URLs
      Returns:
      a builder
    • cached

      public static NBPathsAPI.GetPrefixes 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

      public Optional<Content<?>> first()
      Return the result of resolving the resource.
      Specified by:
      first in interface NBPathsAPI.DoSearch
      Returns:
      an optional Content<?> element.
    • maybeOne

      public Optional<Content<?>> maybeOne()
    • one

      public Content<?> 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:
      one in interface NBPathsAPI.DoSearch
      Returns:
      An optional content element.
    • resolveEach

      public List<List<Content<?>>> resolveEach()
      Return the result of resolving each of the resource names given. This has the same semantics of NBPathsAPI.DoSearch.first(), except that it returns a result pair-wise for each name given.
      Specified by:
      resolveEach in interface NBPathsAPI.DoSearch
      Returns:
      A list of optional Content<?> elements.
    • expandNamesAndSuffixes

      public LinkedHashSet<String> 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

      public static Set<String> expandSynonymPaths(List<String> names, List<Set<String>> suffixSets)
    • list

      public List<Content<?>> list()
      Provide a list of all matching content that was matched by the search qualifiers
      Specified by:
      list in interface NBPathsAPI.DoSearch
      Returns:
      a list of content
    • relativeTo

      public List<Path> 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. This is done per content item within the direct filesystem the path belongs to.
      Specified by:
      relativeTo in interface NBPathsAPI.DoSearch
      Parameters:
      base - The root path elements to remove
      Returns:
      Relative paths
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • useNBIOCache

      public boolean useNBIOCache()
    • setUseNBIOCache

      public static void setUseNBIOCache(boolean wantsToUseNBIOCache)