Package de.xima.fc.io
Class TempFile
- java.lang.Object
-
- de.xima.fc.io.TempFile
-
- All Implemented Interfaces:
Serializable
,AutoCloseable
public final class TempFile extends Object implements AutoCloseable, Serializable
AnAutoCloseable
wrapper for aFile
that deletes that file when closed.- Author:
- XIMA MEDIA GmbH
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static TempFile
create(String prefix, String suffix, FileAttribute<?>... attrs)
Creates a temporary file, wraps it in aTempFile
and returns it.static TempFile
create(Path directory, String prefix, String suffix, FileAttribute<?>... attrs)
Creates a temporary file, wraps it in aTempFile
and returns it.File
getFile()
Path
getPath()
-
-
-
Method Detail
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
getFile
public File getFile()
- Returns:
- The wrapped file.
-
getPath
public Path getPath()
- Returns:
- The wrapped file.
-
create
public static TempFile create(Path directory, String prefix, String suffix, FileAttribute<?>... attrs) throws IOException
Creates a temporary file, wraps it in aTempFile
and returns it. This method is a convenience method for wrapping a temporary file created withFiles.createTempFile(Path, String, String, FileAttribute[])
.- Parameters:
directory
- the path to directory in which to create the fileprefix
- The prefix string to be used in generating the file's name; may be null.suffix
- The suffix string to be used in generating the file's name; may be null, in which case ".tmp
" is usedattrs
- An optional list of file attributes to set atomically when creating the file- Returns:
- The newly created temp file.
- Throws:
IllegalArgumentException
- If the prefix or suffix parameters cannot be used to generate a candidate file name.UnsupportedOperationException
- If the array contains an attribute that cannot be set atomically when creating the directoryIOException
- If an I/O error occurs ordir
does not exist.SecurityException
- In the case of the default provider, and a security manager is installed, thecheckWrite
method is invoked to check write access to the file.
-
create
public static TempFile create(String prefix, String suffix, FileAttribute<?>... attrs) throws IOException
Creates a temporary file, wraps it in aTempFile
and returns it. This method is a convenience method for wrapping a temporary file created withFiles.createTempFile(String, String, FileAttribute[])
.- Parameters:
prefix
- The prefix string to be used in generating the file's name; may be null.suffix
- The suffix string to be used in generating the file's name; may be null, in which case ".tmp
" is usedattrs
- An optional list of file attributes to set atomically when creating the file- Returns:
- The newly created temp file.
- Throws:
IllegalArgumentException
- If the prefix or suffix parameters cannot be used to generate a candidate file name.UnsupportedOperationException
- If the array contains an attribute that cannot be set atomically when creating the directoryIOException
- If an I/O error occurs ordir
does not exist.SecurityException
- In the case of the default provider, and a security manager is installed, thecheckWrite
method is invoked to check write access to the file.
-
-