public final class TempPath extends Object implements AutoCloseable
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this path, deleting the file or directory if it exists.
|
static TempPath |
createDirectory()
Creates a new temporary directory in the default temporary file location.
|
static TempPath |
createDirectory(Path dir)
Creates a new temporary directory in the specified directory.
|
static TempPath |
createFile()
Creates a new temporary file in the default temporary file location.
|
static TempPath |
createFile(Path dir)
Creates a new temporary file in the specified directory.
|
Path |
path()
Returns the
Path to the temporary file or directory. |
String |
toString() |
static TempPath |
wrap(Path path)
Wraps an existing
Path as a TempPath . |
public static TempPath createDirectory() throws IOException
IOException
- if an I/O error occurs while creating the directorypublic static TempPath createDirectory(Path dir) throws IOException
IOException
- if an I/O error occurs while creating the directorypublic static TempPath createFile() throws IOException
IOException
- if an I/O error occurs while creating the filepublic static TempPath createFile(Path dir) throws IOException
IOException
- if an I/O error occurs while creating the filepublic static TempPath wrap(Path path)
Path
as a TempPath
. To allow reasoning
about deletion, all access to the delegate path should
use the returned wrapper.path
- the path to wrappublic Path path()
Path
to the temporary file or directory.
Clients must take care to avoid leaking the returned reference outside the scope of a surrounding try-with-resources block, as the path is deleted when this object is closed.
IllegalStateException
- if this path is closedpublic void close() throws IOException
close
in interface AutoCloseable
IOException
- if an I/O error occurs while deleting this path