Class TempFile
java.lang.Object
de.xima.fc.io.TempFile
- All Implemented Interfaces:
Serializable, AutoCloseable
An
AutoCloseable wrapper for a File that deletes that file when closed.- Author:
- XIMA MEDIA GmbH
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()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.getFile()getPath()
-
Constructor Details
-
TempFile
-
TempFile
-
-
Method Details
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
getFile
- Returns:
- The wrapped file.
-
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.
-