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.io.FilecreateTempFile()Create a new temporary file in the given directory.java.io.FilecreateTempFile(java.lang.String name)voiddeleteTempFile(java.lang.String uuid)Delete a temporary file by UUID and if created the corresponding reader/writer.booleandoesTempFileExist(java.lang.String name)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 name)Get the temporary file with some name.java.lang.StringgetTempFileDirPath()Returns the absolute path of the temporary file directory.
-
-
-
Method Detail
-
createTempFile
public java.io.File createTempFile()
Create a new temporary file in the given directory.- Returns:
- UUID associated with the new temporary file.
-
createTempFile
public java.io.File createTempFile(java.lang.String name)
-
doesTempFileExist
public boolean doesTempFileExist(java.lang.String name)
-
getTempFile
public java.io.File getTempFile(java.lang.String name)
Get the temporary file with some name.- Parameters:
name- name of the temporary file.- Returns:
- File object associated with the name.
-
getFileReaderForTempFile
public java.io.BufferedReader getFileReaderForTempFile(java.lang.String uuid) throws java.io.FileNotFoundExceptionCreate 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.
- Throws:
java.io.FileNotFoundException
-
getFileWriterForTempFile
public java.io.FileWriter getFileWriterForTempFile(java.lang.String uuid) throws java.io.IOExceptionCreate 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.
- Throws:
java.io.IOException
-
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.
-
-