Package org.instancio.generator.specs
Interface PathGeneratorSpec<T>
- All Superinterfaces:
GeneratorSpec<T>
- All Known Subinterfaces:
FilePathSpec<T>
,FileSpec
,PathAsGeneratorSpec<T>
,PathSpec
- All Known Implementing Classes:
FileGenerator
,PathGenerator
- Since:
- 2.1.0
-
Method Summary
Modifier and TypeMethodDescriptionTerminal 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.createFile
(InputStream content) 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.Generator for the file or directory name.File or directory name prefix.File or directory name suffix.tmp()
Generate path withjava.io.tmpdir
as the parent directory.
-
Method Details
-
name
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
- Parameters:
nameGenerator
- for generating the name- Returns:
- spec builder
- Since:
- 2.1.0
- Prefix and suffix are optional and are
-
prefix
File or directory name prefix. No prefix is added by default.- Parameters:
prefix
- to add to the file or directory name- Returns:
- spec builder
- Since:
- 2.1.0
-
suffix
File or directory name suffix. No suffix is added by default.- Parameters:
suffix
- to add to the file or directory name- Returns:
- spec builder
- Since:
- 2.1.0
-
tmp
PathGeneratorSpec<T> tmp()Generate path withjava.io.tmpdir
as the parent directory.- Returns:
- spec builder
- Since:
- 2.1.0
-
createDirectory
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.
- Returns:
- completed spec with no further methods
- Throws:
InstancioApiException
- if an error occurs creating the path- Since:
- 2.1.0
- See Also:
-
createFile
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.
- Returns:
- completed spec with no further methods
- Throws:
InstancioApiException
- if an error occurs creating the path- Since:
- 2.1.0
- See Also:
-
createFile
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.
- Parameters:
content
- to write to the file- Returns:
- completed spec with no further methods
- Throws:
InstancioApiException
- if an error occurs creating the path or writing content to the file- Since:
- 2.1.0
- See Also:
-