return createTempFile( session, prefix, extn, new File( getSolutionPath( "system/tmp" ) ), trackFile ); //$NON-NLS-1$
}
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 ) {
return null;
}
if ( trackFile ) {
fileDeleter = (ITempFileDeleter) session.getAttribute( ITempFileDeleter.DELETER_SESSION_VARIABLE );
}
String name = session.getName();
final String newPrefix =
new StringBuilder().append( prefix ).append( name.substring( 0, name.length() > 10 ? 10 : name.length() ) )
.append( '-' ).toString();
if ( parentDir != null ) {
parentDir.mkdirs();
}
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;