Class TempFileHandler

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class TempFileHandler
    extends java.lang.Object
    implements java.io.Closeable
    Utility Class for managing temporary files and corresponding readers/writers. A directory for the temporary files can be given, otherwise a new one in the Home Directory is created.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cleanUp()
      Removes all temporary files and close all readers/writers.
      void close()  
      java.lang.String createTempFile()
      Create a new temporary file in the given directory.
      void deleteTempFile​(java.lang.String uuid)
      Delete a temporary file by UUID and if created the corresponding reader/writer.
      java.io.BufferedReader getFileReaderForTempFile​(java.lang.String uuid)
      Create or retrieve an existing file reader for a temporary file by UUID.
      java.io.FileWriter getFileWriterForTempFile​(java.lang.String uuid)
      Create or retrieve an existing file writer for a temporary file by UUID.
      java.io.File getTempFile​(java.lang.String uuid)
      Get the temporary file with the UUID.
      java.lang.String getTempFileDirPath()
      Returns the absolute path of the temporary file directory.
      • Methods inherited from class java.lang.Object

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

      • TempFileHandler

        public TempFileHandler​(java.io.File tempFileDirectory)
      • TempFileHandler

        public TempFileHandler()
    • Method Detail

      • createTempFile

        public java.lang.String createTempFile()
        Create a new temporary file in the given directory.
        Returns:
        UUID associated with the new temporary file.
      • getTempFile

        public java.io.File getTempFile​(java.lang.String uuid)
        Get the temporary file with the UUID.
        Parameters:
        uuid - UUID of the file.
        Returns:
        File object associated with the UUID.
      • getFileReaderForTempFile

        public java.io.BufferedReader getFileReaderForTempFile​(java.lang.String uuid)
        Create or retrieve an existing file reader for a temporary file by UUID.
        Parameters:
        uuid - UUID of the temporary file.
        Returns:
        An existing or new file reader for the given temporary file.
      • getFileWriterForTempFile

        public java.io.FileWriter getFileWriterForTempFile​(java.lang.String uuid)
        Create or retrieve an existing file writer for a temporary file by UUID.
        Parameters:
        uuid - UUID of the temporary file.
        Returns:
        An existing or new file writer for the given temporary file.
      • deleteTempFile

        public void deleteTempFile​(java.lang.String uuid)
        Delete a temporary file by UUID and if created the corresponding reader/writer.
        Parameters:
        uuid - UUID of the file.
      • cleanUp

        public void cleanUp()
        Removes all temporary files and close all readers/writers.
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • getTempFileDirPath

        public java.lang.String getTempFileDirPath()
        Returns the absolute path of the temporary file directory.
        Returns:
        The absolute path of the temporary file directory.