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.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.
-
-
Constructor Summary
Constructors Constructor Description TempFileHandler()
TempFileHandler(java.io.File tempFileDirectory)
-
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.io.File
createTempFile()
Create a new temporary file in the given directory.java.io.File
createTempFile(java.lang.String name)
void
deleteTempFile(java.lang.String uuid)
Delete a temporary file by UUID and if created the corresponding reader/writer.boolean
doesTempFileExist(java.lang.String name)
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 name)
Get the temporary file with some name.java.lang.String
getTempFileDirPath()
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.FileNotFoundException
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.
- Throws:
java.io.FileNotFoundException
-
getFileWriterForTempFile
public java.io.FileWriter getFileWriterForTempFile(java.lang.String uuid) throws java.io.IOException
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.
- 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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in 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.
-
-