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
AnAutoCloseablewrapper for aFilethat 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 voidclose()static TempFilecreate(String prefix, String suffix, FileAttribute<?>... attrs)Creates a temporary file, wraps it in aTempFileand returns it.static TempFilecreate(Path directory, String prefix, String suffix, FileAttribute<?>... attrs)Creates a temporary file, wraps it in aTempFileand returns it.FilegetFile()PathgetPath()
-
-
-
Method Detail
-
close
public void close()
- Specified by:
closein 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 aTempFileand 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 ordirdoes not exist.SecurityException- In the case of the default provider, and a security manager is installed, thecheckWritemethod 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 aTempFileand 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 ordirdoes not exist.SecurityException- In the case of the default provider, and a security manager is installed, thecheckWritemethod is invoked to check write access to the file.
-
-