set tmpfile.deleteOnExit by default,

to make sure files are removed on shutdown.
This commit is contained in:
reger 2015-11-16 21:37:45 +01:00
parent 2985baaa01
commit 02e4489a23
2 changed files with 11 additions and 1 deletions

View File

@ -271,7 +271,6 @@ public class psParser extends AbstractParser implements Parser {
try {
// creating a tempfile
tempFile = FileUtils.createTempFile(this.getClass(), "temp.ps");
tempFile.deleteOnExit();
// copying inputstream into file
FileUtils.copy(source,tempFile);

View File

@ -790,6 +790,16 @@ public final class FileUtils {
}
}
/**
* Creates a temp file in the default system tmp directory (System property ""java.io.tmpdir"")
* with a name constructed by combination of class name and name.
* Marks the file with deleteOnExit() to be at least deleted on shutdown of jvm
*
* @param classObj name is used as prefix
* @param name
* @return temp file
* @throws IOException
*/
public static final File createTempFile(final Class<?> classObj, final String name) throws IOException {
String parserClassName = classObj.getName();
int idx = parserClassName.lastIndexOf('.');
@ -809,6 +819,7 @@ public final class FileUtils {
File.createTempFile(
parserClassName + "_" + ((idx > -1) ? fileName.substring(0, idx) : fileName),
(!fileExt.isEmpty()) ? "." + fileExt : fileExt);
tempFile.deleteOnExit();
return tempFile;
}