Started New TempFiles API

This commit is contained in:
Konloch 2024-10-02 10:55:27 -06:00
parent d4a528ee23
commit 32b6f4ee8a

AI 샘플 코드 생성 중입니다

Loading...

View File

@ -0,0 +1,43 @@
package the.bytecode.club.bytecodeviewer.util;
import java.io.File;
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
/**
* @author Konloch
* @since 10/2/2024
*/
public class TempFiles
{
public static File createTemporaryFile(boolean newDirecory, String extension)
{
//genereate a new temporary parent directory
File parent = newDirecory ? createTemporaryDirectory() : new File(TEMP_DIRECTORY);
//make the parent directories
parent.mkdirs();
//return the temporary file
File file;
//generate a new name until the directory no longer exists
while((file = new File(parent, MiscUtils.getUniqueName("", extension))).exists())
{
}
return file;
}
public static File createTemporaryDirectory()
{
File directory;
//generate a new name until the directory no longer exists
while((directory = new File(TEMP_DIRECTORY, MiscUtils.randomString(32))).exists())
{
}
return directory;
}
}