Package org.sosy_lab.common.io
Class TempFile.TempFileBuilder
- java.lang.Object
-
- org.sosy_lab.common.io.TempFile.TempFileBuilder
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Pathcreate()Create a fresh temporary file according to the specifications set on this builder.TempFile.DeleteOnCloseFilecreateDeleteOnClose()Create a fresh temporary file according to the specifications set on this builder.TempFile.TempFileBuilderdir(Path pDir)The directory where the file will be created, default is JVM's temp directory.TempFile.TempFileBuilderfileAttributes(FileAttribute<?>... pFileAttributes)Use the specifiedFileAttributes for creating the file.TempFile.TempFileBuilderinitialContent(Object pContent, Charset pCharset)Content to write to temp file immediately after creation.TempFile.TempFileBuildernoDeleteOnJvmExit()Do not automatically delete the file on JVM exit withFile.deleteOnExit().TempFile.TempFileBuilderprefix(String pPrefix)Prefix of randomly-generated file name.TempFile.TempFileBuildersuffix(String pSuffix)Suffix of randomly generated file name, default is.tmp.
-
-
-
Method Detail
-
dir
@CanIgnoreReturnValue public TempFile.TempFileBuilder dir(Path pDir)
The directory where the file will be created, default is JVM's temp directory.
-
prefix
@CanIgnoreReturnValue public TempFile.TempFileBuilder prefix(String pPrefix)
Prefix of randomly-generated file name.
-
suffix
@CanIgnoreReturnValue public TempFile.TempFileBuilder suffix(String pSuffix)
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
@CanIgnoreReturnValue public TempFile.TempFileBuilder 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
public Path create() throws IOException
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
public TempFile.DeleteOnCloseFile createDeleteOnClose() throws IOException
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
-
-