Package org.sosy_lab.common.io
Class TempFile.TempFileBuilder
java.lang.Object
org.sosy_lab.common.io.TempFile.TempFileBuilder
- Enclosing class:
- TempFile
-
Method Summary
Modifier and TypeMethodDescriptioncreate()Create a fresh temporary file according to the specifications set on this builder.Create a fresh temporary file according to the specifications set on this builder.The directory where the file will be created, default is JVM's temp directory.fileAttributes(FileAttribute<?>... pFileAttributes) Use the specifiedFileAttributes for creating the file.initialContent(Object pContent, Charset pCharset) Content to write to temp file immediately after creation.Do not automatically delete the file on JVM exit withFile.deleteOnExit().Prefix of randomly-generated file name.Suffix of randomly generated file name, default is.tmp.
-
Method Details
-
dir
The directory where the file will be created, default is JVM's temp directory. -
prefix
Prefix of randomly-generated file name. -
suffix
Suffix of randomly generated file name, default is.tmp. -
initialContent
@CanIgnoreReturnValue public TempFile.TempFileBuilder initialContent(Object pContent, Charset pCharset) Content to write to temp file immediately after creation. -
noDeleteOnJvmExit
Do not automatically delete the file on JVM exit withFile.deleteOnExit(). -
fileAttributes
@CanIgnoreReturnValue public TempFile.TempFileBuilder fileAttributes(FileAttribute<?>... pFileAttributes) Use the specifiedFileAttributes for creating the file. -
create
Create a fresh temporary file according to the specifications set on this builder.If the temporary file should be removed after some specific code is executed, use
createDeleteOnClose().This instance can be safely used again afterwards.
- Throws:
IOException
-
createDeleteOnClose
Create a fresh temporary file according to the specifications set on this builder.The resulting
Pathobject is wrapped in aTempFile.DeleteOnCloseFile, which deletes the file as soon asTempFile.DeleteOnCloseFile.close()is called.It is recommended to use the following pattern:
try (DeleteOnCloseFile tempFile = TempFile.builder()[.. adjust builder ..].createDeleteOnClose()) { // use tempFile.toPath() for writing and reading of the temporary file }The file can be opened and closed multiple times, potentially from different processes.This instance can be safely used again afterwards.
- Throws:
IOException
-