Interface FilePathSpec<T>

All Superinterfaces:
GeneratorSpec<T>, PathGeneratorSpec<T>, ValueSpec<T>
All Known Subinterfaces:
FileSpec, PathSpec

public interface FilePathSpec<T> extends ValueSpec<T>, PathGeneratorSpec<T>
Spec for generating File and Path values.
Since:
2.6.0
  • Method Summary

    Modifier and Type
    Method
    Description
    Terminal method to indicate that the generated path, including parent directories (if any), should be created as a directory in the file system.
    Terminal method to indicate that the generated path, including parent directories (if any), should be created as a file in the file system.
    Terminal method to indicate that the generated path, including parent directories (if any), should be created as a file in the file system and content provided by the input stream written to the file.
    name(Generator<String> nameGenerator)
    Generator for the file or directory name.
    prefix(String prefix)
    File or directory name prefix.
    suffix(String suffix)
    File or directory name suffix.
    tmp()
    Generate path with java.io.tmpdir as the parent directory.

    Methods inherited from interface org.instancio.generator.ValueSpec

    get, list, map, nullable, stream, toModel
  • Method Details

    • name

      FilePathSpec<T> name(Generator<String> nameGenerator)
      Description copied from interface: PathGeneratorSpec
      Generator for the file or directory name.

      Generated path names are formed using the following elements:

           [prefix][name][suffix]
       
      • Prefix and suffix are optional and are null by default.
      • If no generator is supplied using this method, a random 16-character lowercase name will be generated.
      • The concatenation of prefix, name, and suffix must not be blank.

      Example:

      
       List<Path> paths = Instancio.ofList(Path.class)
               .generate(all(Path.class), gen -> gen.nio().path()
                       .prefix("queued_")
                       .name(random -> random.alphanumeric(8))
                       .suffix(".csv"))
               .create();
      
       // Sample paths: queued_t5LG4AUw.csv, queued_o0nBWkej.csv, etc
       
      Specified by:
      name in interface PathGeneratorSpec<T>
      Parameters:
      nameGenerator - for generating the name
      Returns:
      spec builder
    • prefix

      FilePathSpec<T> prefix(String prefix)
      Description copied from interface: PathGeneratorSpec
      File or directory name prefix. No prefix is added by default.
      Specified by:
      prefix in interface PathGeneratorSpec<T>
      Parameters:
      prefix - to add to the file or directory name
      Returns:
      spec builder
    • suffix

      FilePathSpec<T> suffix(String suffix)
      Description copied from interface: PathGeneratorSpec
      File or directory name suffix. No suffix is added by default.
      Specified by:
      suffix in interface PathGeneratorSpec<T>
      Parameters:
      suffix - to add to the file or directory name
      Returns:
      spec builder
    • tmp

      FilePathSpec<T> tmp()
      Description copied from interface: PathGeneratorSpec
      Generate path with java.io.tmpdir as the parent directory.
      Specified by:
      tmp in interface PathGeneratorSpec<T>
      Returns:
      spec builder
    • createDirectory

      ValueSpec<T> createDirectory()
      Description copied from interface: PathGeneratorSpec
      Terminal method to indicate that the generated path, including parent directories (if any), should be created as a directory in the file system.

      If the directory already exists, then no action will be taken.

      Specified by:
      createDirectory in interface PathGeneratorSpec<T>
      Returns:
      completed spec with no further methods
      See Also:
    • createFile

      ValueSpec<T> createFile()
      Description copied from interface: PathGeneratorSpec
      Terminal method to indicate that the generated path, including parent directories (if any), should be created as a file in the file system.

      If the file already exists, then no action will be taken.

      Specified by:
      createFile in interface PathGeneratorSpec<T>
      Returns:
      completed spec with no further methods
      See Also:
    • createFile

      ValueSpec<T> createFile(InputStream content)
      Description copied from interface: PathGeneratorSpec
      Terminal method to indicate that the generated path, including parent directories (if any), should be created as a file in the file system and content provided by the input stream written to the file.

      If the file already exists, then no action will be taken.

      Specified by:
      createFile in interface PathGeneratorSpec<T>
      Parameters:
      content - to write to the file
      Returns:
      completed spec with no further methods
      See Also: