Class TemporaryFiles
java.lang.Object
dev.getelements.elements.sdk.util.TemporaryFiles
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 Summary
ConstructorsConstructorDescriptionTemporaryFiles(Class<?> enclosingClass) Creates an instance ofTemporaryFileswith the enclosing class.TemporaryFiles(String prefix) Creates an instance ofTemporaryFileswith the supplied prefix. -
Method Summary
Modifier and TypeMethodDescriptionCreates a temporary directory using this instance's prefix.createTempDirectory(String prefix) Creates a temporary directory, using a specific prefix.Creates a temporary file.createTempFile(String suffix) Creates a temporary file with the supplied suffix and the default prefix.createTempFile(String prefix, String suffix) Creates a temporary file with the supplied prefix and suffix.createTempFile(String prefix, String suffix, Path parent) Creates a temporary file with the supplied prefix and suffix.voidDeletes all temporary files and directories created by thisTemporaryFilesinstance.
-
Constructor Details
-
TemporaryFiles
Creates an instance ofTemporaryFileswith 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
Creates an instance ofTemporaryFileswith 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 thisTemporaryFilesinstance. -
createTempDirectory
Creates a temporary directory using this instance's prefix.- Returns:
- the
Pathto the directory - Throws:
UncheckedIOException- if there is a problem creating the directory.
-
createTempDirectory
Creates a temporary directory, using a specific prefix. The prefix supplied will be appended to this instance's prefix.- Returns:
- the
Pathto the directory - Throws:
UncheckedIOException- if there is a problem creating the directory.
-
createTempFile
Creates a temporary file.- Returns:
- the temporary file
Path - Throws:
UncheckedIOException- if an error occurred creating the temporary file.
-
createTempFile
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
Creates a temporary file with the supplied prefix and suffix.- Parameters:
prefix- the prefixsuffix- the suffix- Returns:
- the temporary file
Path - Throws:
UncheckedIOException- if an error occurred creating the temporary file.
-
createTempFile
Creates a temporary file with the supplied prefix and suffix.- Parameters:
prefix- the prefixsuffix- the suffix- Returns:
- the temporary file
Path - Throws:
UncheckedIOException- if an error occurred creating the temporary file.
-