FileDocCategorySizeDatePackage
SimpleTempStorage.javaAPI DocAndroid 1.5 API7823Wed May 06 22:42:46 BST 2009org.apache.james.mime4j.util

SimpleTempStorage

public class SimpleTempStorage extends TempStorage
version
$Id: SimpleTempStorage.java,v 1.2 2004/10/02 12:41:11 ntherning Exp $

Fields Summary
private static Log
log
private TempPath
rootPath
private Random
random
Constructors Summary
public SimpleTempStorage()
Creates a new SimpleTempStorageManager instance.

    
              
      
        rootPath = new SimpleTempPath(System.getProperty("java.io.tmpdir"));
    
Methods Summary
private TempFilecreateTempFile(TempPath parent, java.lang.String prefix, java.lang.String suffix)

        
        if (prefix == null) {
            prefix = "";
        }
        if (suffix == null) {
            suffix = ".tmp";
        }
        
        File f = null;
        
        int count = 1000;
        synchronized (this) {
            do {
                long n = Math.abs(random.nextLong());
                f = new File(parent.getAbsolutePath(), prefix + n + suffix);
                count--;
            } while (f.exists() && count > 0);
            
            if (f.exists()) {
                throw new IOException("Creating temp file failed: "
                                         + "Unable to find unique file name");
            }
            
            try {
                f.createNewFile();
            } catch (IOException e) {
                throw new IOException("Creating dir '" 
                                        + f.getAbsolutePath() + "' failed."); 
            }
        }
        
        return new SimpleTempFile(f);
    
private TempPathcreateTempPath(TempPath parent, java.lang.String prefix)

        
        if (prefix == null) {
            prefix = "";
        }
        
        File p = null;
        int count = 1000;
        do {
            long n = Math.abs(random.nextLong());
            p = new File(parent.getAbsolutePath(), prefix + n);
            count--;
        } while (p.exists() && count > 0);
        
        if (p.exists() || !p.mkdirs()) {
            log.error("Unable to mkdirs on " + p.getAbsolutePath());
            throw new IOException("Creating dir '" 
                                    + p.getAbsolutePath() + "' failed."); 
        }
        
        return new SimpleTempPath(p);
    
public TempPathgetRootTempPath()

see
org.apache.james.mime4j.util.TempStorage#getRootTempPath()

        return rootPath;