Class NBIO

java.lang.Object
io.nosqlbench.api.content.NBIO
All Implemented Interfaces:
NBPathsAPI.DoSearch, NBPathsAPI.Facets, NBPathsAPI.GetExtension, NBPathsAPI.GetName, NBPathsAPI.GetPrefix, 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.GetPrefix localContent()
      Description copied from interface: NBPathsAPI.GetSource
      Only provide content from the class path and the local filesystem.
      Specified by:
      localContent in interface NBPathsAPI.GetSource
      Returns:
      this builder
    • remoteContent

      public NBPathsAPI.GetPrefix remoteContent()
      Description copied from interface: NBPathsAPI.GetSource
      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.GetPrefix internalContent()
      Description copied from interface: NBPathsAPI.GetSource
      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.GetPrefix fileContent()
      Description copied from interface: NBPathsAPI.GetSource
      Only return content from the filesystem, but not remote URLs nor internal bundled resources.
      Specified by:
      fileContent in interface NBPathsAPI.GetSource
      Returns:
      this builder
    • allContent

      public NBPathsAPI.GetPrefix allContent()
      Description copied from interface: NBPathsAPI.GetSource
      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
    • prefix

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

      public NBPathsAPI.DoSearch search(String... searches)
      Description copied from interface: NBPathsAPI.GetName
      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.GetName
      Returns:
    • name

      public NBPathsAPI.GetExtension name(String... searchNames)
      Description copied from interface: NBPathsAPI.GetName
      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:
      name in interface NBPathsAPI.GetName
      Parameters:
      searchNames - The name of the resource to load
      Returns:
      this builder
    • extension

      public NBPathsAPI.DoSearch extension(String... extensions)
      Description copied from interface: NBPathsAPI.GetExtension
      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:
      extension in interface NBPathsAPI.GetExtension
      Parameters:
      extensions - The extension names to try
      Returns:
      this builder
    • all

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

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

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

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

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

      public Optional<Content<?>> first()
      Description copied from interface: NBPathsAPI.DoSearch
      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()
      Description copied from interface: NBPathsAPI.DoSearch
      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()
      Description copied from interface: NBPathsAPI.DoSearch
      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 LinkedHashSet<String> expandNamesAndSuffixes(List<String> _names, Set<String> _suffixes)
      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 names are expanded to match the additional suffixes.
      Parameters:
      _names - base filenames or path fragment, possibly fully-qualified
      _suffixes - 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
    • list

      public List<Content<?>> list()
      Description copied from interface: NBPathsAPI.DoSearch
      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)
      Description copied from interface: NBPathsAPI.DoSearch
      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