Package ai.libs.jaicore.basic
Class TempFileHandler
- java.lang.Object
-
- ai.libs.jaicore.basic.TempFileHandler
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class TempFileHandler extends java.lang.Object implements java.io.CloseableUtility 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.
-
-
Constructor Summary
Constructors Constructor Description TempFileHandler()TempFileHandler(java.io.File tempFileDirectory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanUp()Removes all temporary files and close all readers/writers.voidclose()java.lang.StringcreateTempFile()Create a new temporary file in the given directory.voiddeleteTempFile(java.lang.String uuid)Delete a temporary file by UUID and if created the corresponding reader/writer.java.io.BufferedReadergetFileReaderForTempFile(java.lang.String uuid)Create or retrieve an existing file reader for a temporary file by UUID.java.io.FileWritergetFileWriterForTempFile(java.lang.String uuid)Create or retrieve an existing file writer for a temporary file by UUID.java.io.FilegetTempFile(java.lang.String uuid)Get the temporary file with the UUID.java.lang.StringgetTempFileDirPath()Returns the absolute path of the temporary file directory.
-
-
-
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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.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.
-
-