Class TempResourceContainer

java.lang.Object
io.github.dornol.excelkit.core.TempResourceContainer
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
AbstractReadHandler, CsvHandler

public class TempResourceContainer extends Object implements AutoCloseable
Abstract container class for managing temporary files and directories.

This class is typically used by file-based exporters such as CSV and Excel handlers, providing automatic cleanup of temporary resources via AutoCloseable.

Since:
2025-07-19
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new empty temp resource container.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Attempts to delete the temporary file and directory (if they exist).
    protected @Nullable Path
    Returns the path to the temporary directory (if set).
    protected @Nullable Path
    Returns the path to the temporary file (if set).
    protected void
    setTempDir(@Nullable Path tempDir)
    Sets the path to the temporary directory.
    protected void
    setTempFile(@Nullable Path tempFile)
    Sets the path to the temporary file.

    Methods inherited from class java.lang.Object

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

    • TempResourceContainer

      public TempResourceContainer()
      Creates a new empty temp resource container.
  • Method Details

    • getTempDir

      protected @Nullable Path getTempDir()
      Returns the path to the temporary directory (if set).
      Returns:
      the temporary directory path, or null
    • setTempDir

      protected void setTempDir(@Nullable Path tempDir)
      Sets the path to the temporary directory.
      Parameters:
      tempDir - The directory to store the temporary file
    • getTempFile

      protected @Nullable Path getTempFile()
      Returns the path to the temporary file (if set).
      Returns:
      the temporary file path, or null
    • setTempFile

      protected void setTempFile(@Nullable Path tempFile)
      Sets the path to the temporary file.
      Parameters:
      tempFile - The file that will be eventually streamed
    • close

      public void close()
      Attempts to delete the temporary file and directory (if they exist).

      Called automatically at the end of file export operations.

      Specified by:
      close in interface AutoCloseable