Class TempDir

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

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

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

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

    Methods inherited from class java.lang.Object

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

    • TempDir

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

      public TempDir(Path dir, String prefix) throws IOException
      Creates a temporary directory with specified prefix in the given parent directory.
      Parameters:
      dir - the parent directory
      prefix - the directory name prefix
      Throws:
      IOException - if directory creation fails
  • Method Details

    • get

      public Path get()
      Returns the path to the temporary directory.
      Returns:
      path to the temporary directory
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException