Class DirectoryWithPrefix

Object
DirectoryWithPrefix
All Implemented Interfaces:
PathCreator

public class DirectoryWithPrefix extends Object implements 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 Details

    • DirectoryWithPrefix

      public DirectoryWithPrefix(Path directory)
      Creates for a directory, with no prefix.
      Parameters:
      directory - the directory.
    • DirectoryWithPrefix

      public DirectoryWithPrefix(Path directory, String prefix, String delimiter)
      Creates a new DirectoryWithPrefix instance.
      Parameters:
      directory - The directory in which files can be written to.
      prefix - Always prepended to outputted filenames.
      delimiter - Added between prefix and the filename, if the filename is defined.
  • Method Details

    • setDirectory

      public void setDirectory(Path directory)
      Assigns a new directory, replacing the existing directory.
      Parameters:
      directory - the directory.
    • asPath

      public Path asPath(boolean includeDelimeter)
      A path that combines the directory and fileNamePrefix and delimiter.
      Parameters:
      includeDelimeter - if true, the delimeter is included in the combined prefix.
      Returns:
      the combined path
    • prefixWithDelimeter

      public String 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 interface PathCreator
      Parameters:
      suffix - the final part of the path, to be added to the prefix
      extension - a file extension (without a leading period).
      fallbackSuffix - if neither a prefix is defined nor a suffix, 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

      public Path makePathRelative(Path fullPath)
      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 interface PathCreator
      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

      public Path getDirectory()
      The directory in which files can be written to.
    • setPrefix

      public void setPrefix(String prefix)
      Always prepended to outputted filenames.
    • setDelimiter

      public void setDelimiter(String delimiter)
      Added between prefix and the filename, if the filename is defined.