otmpfile
O_TMPFILE backed temporary files for Java.
What is O_TMPFILE?
O_TMPFILE is a Linux-specific flag for open(), that allows creation of already-unlinked temporary files, that don't need to be explicitly removed via unlink. This means that you could create a temp file without name. This is wrapper library to use O_TMPFILE from Java.
How to Use?
SecureTempFile tmp = new SecureTempFile();
// Create and write temp file without giving a name
try (FileOutputStream fs = new FileOutputStream(stf.getFileDescriptor())) {
fs.write("foo".getBytes());
}
// Optionally set the file name
String tempFilePath = SecureTempFile.TEMP_DIR + File.separator + "my-temp-file.tmp";
tmp.setName(tempFilePath);
Articles
Automatic Deletion of Incomplete Output Files
open() flags: O_TMPFILE and O_BENEATH
Supported Java Versions
Oracle & OpenJDK Java 8, 11.
Both the JRE and the JDK are suitable for use with this library.
Supported Platforms
otmpfile has been tested under Ubuntu, but should work on any platform where a GNU/Linux 3.11 Kernel available.
Integration with Maven
To use the official release of otmpfile, please use the following snippet in your pom.xml
file.
Add the following to your POM's <dependencies>
tag:
<dependency>
<groupId>io.webfolder</groupId>
<artifactId>otmpfile</artifactId>
<version>1.1.0</version>
</dependency>
License
This project licensed under the MIT License.