Class TempFile

java.lang.Object
org.pgcodekeeper.core.utils.TempFile
All Implemented Interfaces:
AutoCloseable

public final class TempFile extends Object implements AutoCloseable
Wrapper for creation and automatic deletion of a temporary file. Intended for try-with-resources usage to ensure proper cleanup. Automatically deletes the file when closed.
Author:
Alexander Levsha
  • Constructor Summary

    Constructors
    Constructor
    Description
    TempFile(String prefix, String suffix)
    Creates a temporary file with specified prefix and suffix in the system temp directory.
    TempFile(Path dir, String prefix, String suffix)
    Creates a temporary file with specified prefix and suffix in the given directory.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    get()
    Returns the path to the temporary file.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TempFile

      public TempFile(String prefix, String suffix) throws IOException
      Creates a temporary file with specified prefix and suffix in the system temp directory.
      Parameters:
      prefix - the file name prefix
      suffix - the file name suffix
      Throws:
      IOException - if file creation fails
    • TempFile

      public TempFile(Path dir, String prefix, String suffix) throws IOException
      Creates a temporary file with specified prefix and suffix in the given directory.
      Parameters:
      dir - the directory to create file in
      prefix - the file name prefix
      suffix - the file name suffix
      Throws:
      IOException - if file creation fails
  • Method Details