Search in sources :

Example 6 with ITempFileDeleter

use of org.pentaho.platform.api.util.ITempFileDeleter in project pentaho-platform by pentaho.

the class ApplicationContextDouble method createTempFile.

public File createTempFile(final IPentahoSession session, final String prefix, final String extn, final File parentDir, boolean trackFile) throws IOException {
    ITempFileDeleter fileDeleter = null;
    if ((session != null) && trackFile) {
        fileDeleter = (ITempFileDeleter) session.getAttribute(ITempFileDeleter.DELETER_SESSION_VARIABLE);
    }
    final String newPrefix = new StringBuilder().append(prefix).append(session.getId().substring(0, 10)).append('-').toString();
    final File file = File.createTempFile(newPrefix, extn, parentDir);
    if (fileDeleter != null) {
        fileDeleter.trackTempFile(file);
    } else {
        // There is no deleter, so cleanup on VM exit. (old behavior)
        file.deleteOnExit();
    }
    return file;
}
Also used : ITempFileDeleter(org.pentaho.platform.api.util.ITempFileDeleter) File(java.io.File)

Aggregations

ITempFileDeleter (org.pentaho.platform.api.util.ITempFileDeleter)6 File (java.io.File)3 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 RandomAccessFile (java.io.RandomAccessFile)1 ZipFile (java.util.zip.ZipFile)1 HttpSession (javax.servlet.http.HttpSession)1 PentahoHttpSession (org.pentaho.platform.web.http.session.PentahoHttpSession)1