Class TempFile.TempFileBuilder

java.lang.Object
org.sosy_lab.common.io.TempFile.TempFileBuilder
Enclosing class:
TempFile

public static final class TempFile.TempFileBuilder extends Object
  • Method Details

    • 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 with File.deleteOnExit().
    • fileAttributes

      @CanIgnoreReturnValue public TempFile.TempFileBuilder fileAttributes(FileAttribute<?>... pFileAttributes)
      Use the specified FileAttributes 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 Path object is wrapped in a TempFile.DeleteOnCloseFile, which deletes the file as soon as TempFile.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