FileDocCategorySizeDatePackage
AETemporaryFileHandler.javaAPI DocAzureus 3.0.3.42784Tue May 29 18:13:08 BST 2007org.gudy.azureus2.core3.util

AETemporaryFileHandler

public class AETemporaryFileHandler extends Object
author
parg

Fields Summary
private static final String
PREFIX
private static final String
SUFFIX
private static boolean
started_up
private static File
tmp_dir
Constructors Summary
Methods Summary
public static java.io.FilecreateTempDir()

		startup();
		
		for (int i=0;i<16;i++){
			
			File f = File.createTempFile( PREFIX, SUFFIX, tmp_dir );
			
			f.delete();
			
			if ( f.mkdirs()){
				
				return( f );
			}
		}
		
		throw( new IOException( "Failed to create temporary directory in " + tmp_dir ));
	
public static java.io.FilecreateTempFile()

		startup();
		
		return( File.createTempFile( PREFIX, SUFFIX, tmp_dir ));
	
public static synchronized voidstartup()


	   
	
	
		if ( started_up ){
			
			return;
		}
		
		started_up	= true;
		
		try{
			tmp_dir		= FileUtil.getUserFile( "tmp" );
						
			if ( tmp_dir.exists()){
				
				File[]	files = tmp_dir.listFiles();
				
				if ( files != null ){
					
					for (int i=0;i<files.length;i++){
						
						File	file = files[i];
						
						if ( file.getName().startsWith(PREFIX) && file.getName().endsWith(SUFFIX)){
						
							if ( file.isDirectory()){
							
								FileUtil.recursiveDelete( file );
								
							}else{
							
								file.delete();
							}
						}
					}
				}
			}else{
				
				tmp_dir.mkdir();
			}
			
		}catch( Throwable e ){
			
			try{
				tmp_dir = File.createTempFile(PREFIX,SUFFIX).getParentFile();
			
			}catch( Throwable f ){
				
				tmp_dir = new File("");
			}
			
				// with webui we don't have the file stuff so this fails with class not found
			
			if ( !(e instanceof NoClassDefFoundError )){
				
				Debug.printStackTrace( e );
			}
		}