Class PathGenerator
java.lang.Object
org.instancio.internal.generator.AbstractGenerator<Path>
org.instancio.internal.generator.nio.file.PathGenerator
- All Implemented Interfaces:
AsStringGeneratorSpec<Path>
,Generator<Path>
,GeneratorSpec<Path>
,PathGeneratorSpec<Path>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the public API method name of the generator spec.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.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.Returns a generated value.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.Methods inherited from class org.instancio.internal.generator.AbstractGenerator
getContext, hints
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.instancio.generator.AsStringGeneratorSpec
asString, asString
-
Constructor Details
-
PathGenerator
-
-
Method Details
-
apiMethod
Description copied from class:AbstractGenerator
Returns the public API method name of the generator spec. The returned name is used for reporting validation errors.- Specified by:
apiMethod
in classAbstractGenerator<Path>
- Returns:
- spec name if defined, or
null
otherwise
-
tmp
Description copied from interface:PathGeneratorSpec
Generate path withjava.io.tmpdir
as the parent directory.- Specified by:
tmp
in interfacePathGeneratorSpec<Path>
- Returns:
- spec builder
-
prefix
Description copied from interface:PathGeneratorSpec
File or directory name prefix. No prefix is added by default.- Specified by:
prefix
in interfacePathGeneratorSpec<Path>
- Parameters:
prefix
- to add to the file or directory name- Returns:
- spec builder
-
suffix
Description copied from interface:PathGeneratorSpec
File or directory name suffix. No suffix is added by default.- Specified by:
suffix
in interfacePathGeneratorSpec<Path>
- Parameters:
suffix
- to add to the file or directory name- Returns:
- spec builder
-
name
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 interfacePathGeneratorSpec<Path>
- Parameters:
nameGenerator
- for generating the name- Returns:
- spec builder
- Prefix and suffix are optional and are
-
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 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 interfacePathGeneratorSpec<Path>
- Parameters:
content
- to write to the file- Returns:
- completed spec with no further methods
- See Also:
-
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 interfacePathGeneratorSpec<Path>
- Returns:
- completed spec with no further methods
- See Also:
-
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 interfacePathGeneratorSpec<Path>
- Returns:
- completed spec with no further methods
- See Also:
-
generate
Description copied from interface:Generator
Returns a generated value.If this method produces random data, the data needs to be generated using the provided
Random
instance. This ensures generated values are reproducible for a given seed value.
-