Konloch Software

API Talk - Temporary Files

Published 10/02/2024

Java provides a very nice way to create temporary files and folders, normally I would use this. But for BCV I wanted something that would handle cleanup along with a few other specific features I figured would be easy enough to write.

The Temp File API has replaced the old way of creating temporary files. The current target for replacement is for all Abstract Decompilers, but the API will be eventually applied to all temporary file creation within BCV.

//init the temp files / directories
TempFile tempFile = TempFile.createTemporaryFile(true, ".class");
File tempInputClassFile = tempFile.getFile();
File tempOutputJavaFile = tempFile.createFileFromExtension(false, true, ".java");

//cleanup any created files and folders
tempFile.cleanup();

The idea behind the API is you can easily define temporary files, directories, etc. Then you call on the tempFile.cleanup() function and it removes the files right after your code execution.

As an added bonus, this update resolved a bug in BCV caused by laziness on my part - creating excess temporary files. We originally solved this by hiding the interface when exiting the gui - then we run a cleanup script on exit. This means after you have opened many files in BCV, decompiling them as you go - it can take several seconds to actually close the process. As far as I know, it wasn’t a problem to users, but I knew about it - so I’m glad it’s fixed.

If you want to look at the API in more detail, you can view the classfile from the BCV repo