Class DirectoryWithPrefix
Object
DirectoryWithPrefix
- All Implemented Interfaces:
PathCreator
A directory into which files can be written, and a prefix for the name of each written file.
A delimeter may additionally be specified that is inserted between the prefix and a filename when a filename is specified (which may not always be the case).
- Author:
- Owen Feehan
-
Constructor Summary
ConstructorsConstructorDescriptionDirectoryWithPrefix
(Path directory) Creates for a directory, with no prefix.DirectoryWithPrefix
(Path directory, String prefix, String delimiter) Creates a newDirectoryWithPrefix
instance. -
Method Summary
Modifier and TypeMethodDescriptionasPath
(boolean includeDelimeter) A path that combines thedirectory
andfileNamePrefix
anddelimiter
.The directory in which files can be written to.Generates a full path, given the final part (suffix) of a path.makePathRelative
(Path fullPath) Extracts a relative-file path, given the final part (suffix) of a path.The prefix concatenated with the delimeter.void
setDelimiter
(String delimiter) Added betweenprefix
and the filename, if the filename is defined.void
setDirectory
(Path directory) Assigns a new directory, replacing the existing directory.void
Always prepended to outputted filenames.
-
Constructor Details
-
DirectoryWithPrefix
Creates for a directory, with no prefix.- Parameters:
directory
- the directory.
-
DirectoryWithPrefix
Creates a newDirectoryWithPrefix
instance.- Parameters:
directory
- The directory in which files can be written to.prefix
- Always prepended to outputted filenames.delimiter
- Added betweenprefix
and the filename, if the filename is defined.
-
-
Method Details
-
setDirectory
Assigns a new directory, replacing the existing directory.- Parameters:
directory
- the directory.
-
asPath
A path that combines thedirectory
andfileNamePrefix
anddelimiter
.- Parameters:
includeDelimeter
- if true, the delimeter is included in the combined prefix.- Returns:
- the combined path
-
prefixWithDelimeter
The prefix concatenated with the delimeter.- Returns:
- the result of the concatenation above.
-
makePathAbsolute
public Path makePathAbsolute(Optional<String> suffix, Optional<String> extension, String fallbackSuffix) Description copied from interface:PathCreator
Generates a full path, given the final part (suffix) of a path.All sub-directories are created if needed to ensure it's possible to write to the fullPath.
- Specified by:
makePathAbsolute
in interfacePathCreator
- Parameters:
suffix
- the final part of the path, to be added to the prefixextension
- a file extension (without a leading period).fallbackSuffix
- if neither aprefix
is defined nor asuffix
, then this provides a suffix to use so a file isn't only an extension.- Returns:
- a complete absolute path with all components (prefix, suffix) etc., including the leading directory.
-
makePathRelative
Description copied from interface:PathCreator
Extracts a relative-file path, given the final part (suffix) of a path.The path will be relative to the underlying root
directory
.This relative-path includes any filename-prefix added by the
DirectoryWithPrefix
.- Specified by:
makePathRelative
in interfacePathCreator
- Parameters:
fullPath
- the final part of the path, to be added to the prefix- Returns:
- a complete relative path with all components (prefix, suffix) etc., but no leading directory.
-
getDirectory
The directory in which files can be written to. -
setPrefix
Always prepended to outputted filenames. -
setDelimiter
Added betweenprefix
and the filename, if the filename is defined.
-