Class TemporaryFiles

java.lang.Object
dev.getelements.elements.sdk.util.TemporaryFiles

public class TemporaryFiles extends Object
Manages temporary files. Each instance of TemporaryFiles makes a temporary directory which houses all temporary files. The directory will be automatically deleted when requested or when the VM shuts down (assuming a clean shutdown). This TemporaryFiles type controls disk location using a set of environment variables. If, for some reason, this instance cannot use the configured path this will log a warning and defer to the value of the "java.io.tmpdir" system property. This class is thread safe and is suitable for use in static memory space. It is recommended to scope a single instance of TemporaryFiles to a type for convenient organization and access.
  • Constructor Details

    • TemporaryFiles

      public TemporaryFiles(Class<?> enclosingClass)
      Creates an instance of TemporaryFiles with the enclosing class. This simply uses the supplied class' fully qualifie dname as the prefix such that the temporary files may be identified later.
      Parameters:
      enclosingClass - the enclosing class
    • TemporaryFiles

      public TemporaryFiles(String prefix)
      Creates an instance of TemporaryFiles with the supplied prefix. The prefix is used in all subsequent operations to create and manage temporary files.
      Parameters:
      prefix - the prefix to use
  • Method Details

    • deleteTempFilesAndDirectories

      public void deleteTempFilesAndDirectories()
      Deletes all temporary files and directories created by this TemporaryFiles instance.
    • createTempDirectory

      public Path createTempDirectory() throws UncheckedIOException
      Creates a temporary directory using this instance's prefix.
      Returns:
      the Path to the directory
      Throws:
      UncheckedIOException - if there is a problem creating the directory.
    • createTempDirectory

      public Path createTempDirectory(String prefix) throws UncheckedIOException
      Creates a temporary directory, using a specific prefix. The prefix supplied will be appended to this instance's prefix.
      Returns:
      the Path to the directory
      Throws:
      UncheckedIOException - if there is a problem creating the directory.
    • createTempFile

      public Path createTempFile() throws UncheckedIOException
      Creates a temporary file.
      Returns:
      the temporary file Path
      Throws:
      UncheckedIOException - if an error occurred creating the temporary file.
    • createTempFile

      public Path createTempFile(String suffix) throws UncheckedIOException
      Creates a temporary file with the supplied suffix and the default prefix.
      Parameters:
      suffix - the suffix the suffix of the file.
      Returns:
      the temporary file Path
      Throws:
      UncheckedIOException - if an error occurred creating the temporary file.
    • createTempFile

      public Path createTempFile(String prefix, String suffix) throws UncheckedIOException
      Creates a temporary file with the supplied prefix and suffix.
      Parameters:
      prefix - the prefix
      suffix - the suffix
      Returns:
      the temporary file Path
      Throws:
      UncheckedIOException - if an error occurred creating the temporary file.
    • createTempFile

      public Path createTempFile(String prefix, String suffix, Path parent) throws UncheckedIOException
      Creates a temporary file with the supplied prefix and suffix.
      Parameters:
      prefix - the prefix
      suffix - the suffix
      Returns:
      the temporary file Path
      Throws:
      UncheckedIOException - if an error occurred creating the temporary file.